passing values to second form

Pork

New member
Joined
Nov 24, 2005
Messages
2
Programming Experience
Beginner
Hello All:

I have an application with two forms. The first for has a listbox on it that displays a list of students. The second form is the form where you would enter all the student information in...when you click save it rights the info to a comma delimited file. There is a view button on the main form that when you select a student from the list box and then click view, what should happen is that the second form opens and displays only that students information. I created a loop on the click event of the view button that opens the text file, reads it in line by line into a variable, there is some string manipulation that is done that puts the individual pieces of information into other variables ie. pulls the last name out of the string and puts it in a last name variable etc. Now, I have 18 variables with correct information in them just waiting to display themselves on the second form in the appropriate fields, and I can't figure out how to get them there. I figure I probably have to pass the values somehow from the main form to the second form...but not sure how to do this. I tried creating a procedure that is called after my loop populates all the variables and pass the variables as parameters to this procedure, but I got a message that I am passing too many parameters. Hope someone can tell me the correct way of doing this.

Thanks ....you guys are great...got some help the other day and it worked great.

Alex
 

abowg

New member
Joined
Nov 26, 2005
Messages
4
Location
Northern Illinois
Programming Experience
1-3
When I need to pass values to the next form this is how I usually do it....

on form1

'create instance of form2
Dim f2 As New form2

'assign values to form2 textboxes
f2.TextBox1.Text = dataFromFile
f2.TextBox2.Text = dataFromFile
......

f2.show()
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+
Put the data into an array, then create a public property on the second form of an array type and pass it the array. The property can then take the array and set the appropriate controls with the data.

-tg
 

mariano_donati

Active member
Joined
Nov 30, 2005
Messages
41
Programming Experience
Beginner
I always need to pass data from one form to another, when I need to put in the other form not too large data, then I use one of the method mention above. When secondary form needs to get a lot of data from the main form, then I create a class named Params (for example), and pass it to the constructor method of the secondary form. Something like this:

Dim Form2 As New Form2(ParamsClass)

And then you can manipulate the data in the second form.
I think that there is not a huge difference between this methods. It's just a personal way to do it.
Good luck!.
 
Top Bottom