mechwarrior3
Well-known member
- Joined
- Dec 19, 2005
- Messages
- 67
- Programming Experience
- Beginner
Alright,
Here is the situation: I have a main form (Form1 (Yes, I know the naming convention for the forms are horrible.)). This Form has two fields filled out and once those fields are filled by the user, the main form makes a call to another form (Form3). This form has several text boxes that are filled by the user. Then the user clicks the OK button. That triggers all of the values in the text boxes to be saved into an array of strings. Then, a call is made to a friend sub routine in the main form. That friend sub routine passes the String array parameter to the main form and saves each string in the array to a new variable. The size of the array is hard coded (albeit, rather poorly) so the amount of necessary variables is known. Once the friend sub routine concludes, Form3 closes and we are returned to the Form1. When I click on the Save button on Form1, I look and all of those string variables that I just set with the friend sub routine are empty. All of them. Nothing left. What is going on? It seems like they are being emptied between the conclusion of the friend sub routine and the closing of Form3. Is this correct? If so, how do I fix that?
Here is the code for Form3 (all of it) There are 12 text boxes and an OK button:
[/COLOR][/COLOR][/SIZE]
Here is the friend sub routine, AssignPNumbers (the 12 strPNums do exist as global variables on Form1):
Any help is greatly appreciated.
[/COLOR][/SIZE]
Here is the situation: I have a main form (Form1 (Yes, I know the naming convention for the forms are horrible.)). This Form has two fields filled out and once those fields are filled by the user, the main form makes a call to another form (Form3). This form has several text boxes that are filled by the user. Then the user clicks the OK button. That triggers all of the values in the text boxes to be saved into an array of strings. Then, a call is made to a friend sub routine in the main form. That friend sub routine passes the String array parameter to the main form and saves each string in the array to a new variable. The size of the array is hard coded (albeit, rather poorly) so the amount of necessary variables is known. Once the friend sub routine concludes, Form3 closes and we are returned to the Form1. When I click on the Save button on Form1, I look and all of those string variables that I just set with the friend sub routine are empty. All of them. Nothing left. What is going on? It seems like they are being emptied between the conclusion of the friend sub routine and the closing of Form3. Is this correct? If so, how do I fix that?
Here is the code for Form3 (all of it) There are 12 text boxes and an OK button:
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] cmdPNumOK_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] cmdPNumOK.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] frm1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] PNumArray() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = {"", "", "", "", "", "", "", "", "", "", "", ""}
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum1.Text, "000"), 0)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum2.Text, "000"), 1)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum3.Text, "000"), 2)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum4.Text, "000"), 3)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum5.Text, "000"), 4)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum6.Text, "000"), 5)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum7.Text, "000"), 6)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum8.Text, "000"), 7)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum9.Text, "000"), 8)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum10.Text, "000"), 9)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum11.Text, "000"), 10)
PNumArray.SetValue(DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum12.Text, "000"), 11)
frm1.AssignPNumbers(PNumArray)
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] DefaultPNum([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] txtString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] txtDefault [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (txtString = "") [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] txtDefault
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] txtString
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form3_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
DefaultSettings()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DefaultSettings()
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPNum1.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][COLOR=black]
Here is the friend sub routine, AssignPNumbers (the 12 strPNums do exist as global variables on Form1):
VB.NET:
[/COLOR][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Friend[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] [COLOR=black]AssignPNumbers([/COLOR][/SIZE][COLOR=black][SIZE=2][COLOR=blue]ByVal[/COLOR][/SIZE][SIZE=2] PNumArray() [/SIZE][/COLOR][COLOR=blue][SIZE=2]As[/SIZE][SIZE=2] [/SIZE][SIZE=2]String[/SIZE][/COLOR][SIZE=2][COLOR=black])[/COLOR]
[COLOR=black]strPNum1 = PNumArray(0)[/COLOR]
[COLOR=black]strPNum2 = PNumArray(1)[/COLOR]
[COLOR=black]strPNum3 = PNumArray(2)[/COLOR]
[COLOR=black]strPNum4 = PNumArray(3)[/COLOR]
[COLOR=black]strPNum5 = PNumArray(4)[/COLOR]
[COLOR=black]strPNum6 = PNumArray(5)[/COLOR]
[COLOR=black]strPNum7 = PNumArray(6)[/COLOR]
[COLOR=black]strPNum8 = PNumArray(7)[/COLOR]
[COLOR=black]strPNum9 = PNumArray(8)[/COLOR]
[COLOR=black]strPNum10 = PNumArray(9)[/COLOR]
[COLOR=black]strPNum11 = PNumArray(10)[/COLOR]
[COLOR=black]strPNum12 = PNumArray(11)[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][COLOR=black]
Any help is greatly appreciated.
[/COLOR][/SIZE]