473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to Return Value from Module?

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

Jul 20 '06 #1
5 3648
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.

<ha*******@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.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

Jul 20 '06 #2
Thanks Marina Levit , but can you give me example :(

thx

Jul 20 '06 #3
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
<ha*******@gmail.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.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

Jul 20 '06 #4
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

<ha*******@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Thanks Marina Levit , but can you give me example :(

thx

Jul 20 '06 #5
Thank You For EveryOne
THX

Jul 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rigga | last post by:
Hi, I am new to Python and am currentky just playing with some simple functions however I can not work out how to return a variable back from a module, probably easier if you see the code.. what...
8
by: george young | last post by:
I recently found myself writing something like: def get_connection(): if tcp_conn(): if server_allows_conn(): return 'good_conn' else: return 'bad_auth' else: return 'no_server'
8
by: Martin Stettner | last post by:
Hi, I would like to use covariant return types in mutual dependent classes like: class IB; class IA { virtual IB* getIB() = 0; }; class IB{ virtual IA* getIA() = 0;
1
by: Matthias Klöpper | last post by:
Hi there, I'm currently trying to call some API-Functions via Reflection.Emit since I need to bind to different dlls based on user input. The dynamic creation of the required PInvoke-Methods works...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
4
by: Wardeaux | last post by:
Hope this is easy... I have a simple winform app that does some work and then exits... I need to return a value to the calling app/process to indicate completion status... what's the...
8
by: gregory_may | last post by:
Is it possible to return "nothing" from an Integer function? This seems to give me "0" rather than "nothing". Private Function MyFunction() As Integer Return Nothing End Function
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
7
by: asit | last post by:
#include <stdio.h> //#include <stdlib.h> int main() { int c; printf("c before call=%d\n",c); c=message(); printf("c after call=%d\n",c); return 0;
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.