Hi,
I've used the instruction on this great page Passing variables and controls using WinForms and VB.NET [Archive] - Xtreme Visual Basic Talk to pass variables between forms on VB.Net Winforms (instead of using global variables, properties, or public variables).
Basically, I call a form using this code
and fetches the variable using this code
.
However, I now face a problem. I have a form that calls another form when the user clicks a button. This new form gets its variables using the above method. This form then calls a third form, passing some variables. Now, depending on what the user selects in this third form, the first form needs to get the variables back (so basically, it's more like a function that returns values).
I can't seem to accomplish this using the method I described, as that would mean creating a new Form1 class, and I just want to return the variables. What should I do? (I guess the same problem arises when it's just a matter of two forms, as in any master-detail scenario).
When I'm at it, a small question: I need to close the second form after the third form delivered its variables back to Form1. I guess the only way to access it, such as Form2.Close(), is to send the entire form as a variable (as I did in the code above). I guess this is heavy on the server and it doesn't look nice, when all I need is a reference to it (something as "Me.Caller.Close()" would do nicely too). Any suggestions (sending the Name property doesn't work for me, as the name itself can't be closed)?
Thanks for all help!
Pettrer
I've used the instruction on this great page Passing variables and controls using WinForms and VB.NET [Archive] - Xtreme Visual Basic Talk to pass variables between forms on VB.Net Winforms (instead of using global variables, properties, or public variables).
Basically, I call a form using this code
VB.NET:
If StudId > 0 And AntId > 0 Then
Dim nyform As New frmStud(StudId, AntId, Me)
nyform.Show()
Else
MsgBox("Errortext. " & StudId & " " & AntId)
End If
and fetches the variable using this code
VB.NET:
Private sStudId As Integer
Private sAnt As Integer
Private anropande As Form
Public Sub New(ByVal id As Integer, ByVal ant As Integer, ByVal namn As Form)
MyBase.New()
InitializeComponent()
sStudId = id
sAnt = ant
anropande = namn
End Sub
However, I now face a problem. I have a form that calls another form when the user clicks a button. This new form gets its variables using the above method. This form then calls a third form, passing some variables. Now, depending on what the user selects in this third form, the first form needs to get the variables back (so basically, it's more like a function that returns values).
I can't seem to accomplish this using the method I described, as that would mean creating a new Form1 class, and I just want to return the variables. What should I do? (I guess the same problem arises when it's just a matter of two forms, as in any master-detail scenario).
When I'm at it, a small question: I need to close the second form after the third form delivered its variables back to Form1. I guess the only way to access it, such as Form2.Close(), is to send the entire form as a variable (as I did in the code above). I guess this is heavy on the server and it doesn't look nice, when all I need is a reference to it (something as "Me.Caller.Close()" would do nicely too). Any suggestions (sending the Name property doesn't work for me, as the name itself can't be closed)?
Thanks for all help!
Pettrer