Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variables (Again)

Status
Not open for further replies.

DotNetNewbie

Programmer
Mar 3, 2004
344
GB
Hi,

I have just had to upgrade some code form VB.net to Visual Studio 2005. After making a number of code changes my program now works. However there seems to be a change in the way that Global variables work.

After investigating I found that Global variables are not the chosen method, but passing the variable from one form to the form it is used in is.

Can someone give me an example on how this is done, as I am at a loss on how to do this correctly.

Kind Regards,

.net
 
You want to use a property value in the form that will pass the variable data back to the original form that called it.
Here is a simple example:

[form 1]
Code:
Dim frm as New Form2
Dim myVariable as String = Nothing

If frm.ShowDialog = DialogResult.Ok Then
  myVariable = frm.GetText
End If

frm = Nothing

[form 2]
Code:
Private rtnText as String

Public ReadOnly Property GetText() as String
  Get
     Return rtnText
  End Get
End Property

Private Sub Button1_Click(ByVal sender as Object, ByVal e as  System.EventArgs) Handles Button1.Click
  rtnText = TextBox1.Text
  me.DialogResult = DialogResult.Ok
  me.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top