|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to Return Value from Module?Suppose I have this code: ---------- Imports System.IO Module Module1 Sub Main() Dim TextFile As New StreamReader("c:\test.txt") Dim Content As String Do Content = TextFile.ReadLine() If (Content <> Nothing) Then Console.WriteLine(Content) End If Loop While (Content <> Nothing) TextFile.Close() End Sub End Module -------- I have created Module1.vb In the main Form I created Button & TextBox. My problem: How I can return Data from the Module1.vb to the TextBox ? it is the first tim i am trying to use ind understand Modules :( THX A module is just a class. There is no concept of returning values with
classes. Methods and properties can return values. So you can add a property or method to your module, and have your form call it. <hailco***@gmail.com> wrote in message Show quoteHide quote news:1153416908.976182.232410@75g2000cwc.googlegroups.com... > Hi, > Suppose I have this code: > ---------- > Imports System.IO > > Module Module1 > > Sub Main() > Dim TextFile As New StreamReader("c:\test.txt") > > Dim Content As String > > Do > Content = TextFile.ReadLine() > > If (Content <> Nothing) Then > Console.WriteLine(Content) > End If > Loop While (Content <> Nothing) > > TextFile.Close() > End Sub > End Module > -------- > > > I have created Module1.vb > > In the main Form I created Button & TextBox. > > My problem: > How I can return Data from the Module1.vb to the TextBox ? > it is the first tim i am trying to use ind understand Modules :( > > THX > Are you saying you don't know how to write a method or property? In which
case you need to go back and read up before moving forward. In your case, by the way, it doesn't look like you have a form or anything like that. If this Sub Main is the main entry point of the application, then the application ends as soon as this method completes. So the application is done, I don't see what you are trying to do here. Here is an example using your code. I modified it to have a function that can return a string. Presumably, something else at some point is going to call Module1.GetContent(). Module Module1 Public Function GetContext() As String Dim TextFile As New StreamReader("c:\test.txt") Dim Content As String Do Content = TextFile.ReadLine() If (Content <> Nothing) Then Console.WriteLine(Content) End If Loop While (Content <> Nothing) TextFile.Close() Return Content End Sub End Module <hailco***@gmail.com> wrote in message Show quoteHide quote news:1153421090.142344.251020@75g2000cwc.googlegroups.com... > Thanks Marina Levit , but can you give me example :( > > thx > Hail,
A module makes it possible to share code by all other modules and instanced classes (objects). (For the rest it is the same as any other code) Therefore I would never write it like you but do (although I trie forever to avoid modules and use instanced classes (objects) ). Module Module1 Public Function ReadMain(byval theFileName as string) as String Dim TextFile As New StreamReader(theFileName) ... ... Return Content End Function End module Now you can use this everywhere in your program as Dim myreadedcontent as string = Module1.ReadMain("c:\test.txt") I hope this helps, Cor <hailco***@gmail.com> schreef in bericht Show quoteHide quote news:1153416908.976182.232410@75g2000cwc.googlegroups.com... > Hi, > Suppose I have this code: > ---------- > Imports System.IO > > Module Module1 > > Sub Main() > Dim TextFile As New StreamReader("c:\test.txt") > > Dim Content As String > > Do > Content = TextFile.ReadLine() > > If (Content <> Nothing) Then > Console.WriteLine(Content) > End If > Loop While (Content <> Nothing) > > TextFile.Close() > End Sub > End Module > -------- > > > I have created Module1.vb > > In the main Form I created Button & TextBox. > > My problem: > How I can return Data from the Module1.vb to the TextBox ? > it is the first tim i am trying to use ind understand Modules :( > > THX >
exceptions/inner exceptions
Menus from a database table and addhandler Problem with two version of program in one code and class referenc Expose Count from System.Collections.CollectionBase in an inherited class Referencing a MDI Parent form from a Child Force Windows to "See" new files burned to a CD/DVD? Internet connection present? Obtain info from other computer SendMessage() Assembly info from separate project? |
|||||||||||||||||||||||