Passing Variables Between Forms

compguru910

Well-known member
Joined
Nov 25, 2009
Messages
47
Programming Experience
3-5
I seem to be running into an issue. This may seem like a noob question (which it really is, I only have experience in vb6 from years ago) but what Im trying to do is pass a variable from one form to another. Ive tried telling the first form to set the value of the variable on the second form like so frmsecond.variable = "value" but that does not work. Ive tried placing a public variable in a module to do it, but again, no luck. The only way seem to be able to get it to work is the second form setting the variable by reading the value from the first form like so

strVariable = frmfirst.datagridview.Rows(1).Items(1).Value (or something to that effect, im not sitting in front of the code)

The problem I have with that code is what if for some reason the selected line gets changed as the form is loading or something to that nature. It doesnt seem very secure. Any help would be appreciated.
 
VB.NET:
frmsecond.variable = "value"

It should work, but which form were you displaying - frmsecond or a copy of it? Try this :-

VB.NET:
Using fSecond as new frmsecond
  fSecond.variable = value
  fSecond.ShowDialog
End Using
 
Well, i am displaying the frmsecond, and not just making an instance of it. Like ive said before, im fairly new to the vb.net way of doing things, should I just instantiate a new copy of the frmsecond when I do this? And, I did some research, would it be best if I just make a few properties in the form to handle passing of information?
 
Thanks for your suggestions. The program I am building transfers alot of information between forms (generally from database querys) I guess normally all I would need to pass is id's of the item I am querying. Thanks again
 
Why don't you use the Me.Mysettings?

Ig Me.Mysettings.Var1 = Variable1

or will this not work in this particular instance?
 
Back
Top