Passing of Variables

gladiator83x

Member
Joined
Jan 15, 2008
Messages
11
Programming Experience
Beginner
Hi All,

I have a general question on passing variables from function (private sub) to function (private sub) in the same form. Is there a special one word declaration prefix? (i.e. Dim or Public or global...I know those 3 don't work b/c I checked,lol.)

Also, how would I pass variables from form to form? Can anyone give me any direction on that as well? Thanks for any help.
 
Firstly, every version since 2002 has been VB.NET. Microsoft have just dropped the .NET suffix because it's now assumed. VB6 was not .NET. VB.NET 2002, VB.NET 2003, VB 2005 and VB 2008 are all VB.NET, as will every future version of VB until Microsoft announce a new platform to replace .NET.

Secondly, a private sub is not a function. A Sub is a method that does not return a value, while a Function is a method that does return a value.

As for your question, I'm sure you've already done what you're asking for more than once. Try creating a new WinForms project and adding the following code to the form:
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    MessageBox.Show(Me.Function1(""))
End Sub

Private Function Function1(ByVal input As String) As String
    input &= "Entering Function1" & Environment.NewLine
    input = Me.Function2(input)
    input &= "Leaving Function1" & Environment.NewLine

    Return input
End Function

Private Function Function2(ByVal input As String) As String
    input &= "Entering Function2" & Environment.NewLine
    input = Me.Function3(input)
    input &= "Leaving Function2" & Environment.NewLine

    Return input
End Function

Private Function Function3(ByVal input As String) As String
    input &= "Entering Function3" & Environment.NewLine
    input &= "Leaving Function3" & Environment.NewLine

    Return input
End Function
As for passing data from form to form, this question has been asked and answered many times, although it needn't have been. Forms are just objects like any other, so you pass data between them the very same way you do any other objects. If you want to pass data into an object you either set one of its properties or call one of its methods and pass a parameter. If you want to get data out of an object you either get one of its properties or call one of its methods and get the return value. This goes for forms exactly the same as for any other object. If your object doesn't have the appropriate properties or methods for you to pass in or get out the data you want then it's up to you to write those properties and/or methods.
 
Back
Top