robtyketto
Member
- Joined
- Jul 23, 2009
- Messages
- 23
- Programming Experience
- Beginner
Greetings,
My scenerio is a form with a button, when clicked opens a form dialog.
The dialog allows the user to enter a text box.
I want to read the value of the text box from the main form into a variable to be used with an SQL statement.
The following code is used to create a new instance of the form dialog if one does not exist:-
Code below is the dialog box class and public values which I believe should be accessable to any other class (other forms).
Setting the value of the private variable, will this inturn update the publc variable TransferLocation?
I then believed I could access the variable as follows:-
So if transferdialog Is NOT Nothing then I could use the following code:
However this errors as it appears to recognise as a window form class as it has been dimensioned and not transferdialog class with an available public variable.
I know there is several ways to pass values between forms, can anyone point me in the right direction of how to access values via properties i.e what im trying to do?
I've also started to read about shared variables too, so if there is a strong reason not to use the method I've tried to implement Im all ears.
Thanks and hope the problem is clear.
Rob
My scenerio is a form with a button, when clicked opens a form dialog.
The dialog allows the user to enter a text box.
I want to read the value of the text box from the main form into a variable to be used with an SQL statement.
The following code is used to create a new instance of the form dialog if one does not exist:-
VB.NET:
If transferdialog Is Nothing Then
transferdialog = New dlgTransfers(txtMemNum.Text.ToString)
Else
transferdialog.Show()
End If
Code below is the dialog box class and public values which I believe should be accessable to any other class (other forms).
VB.NET:
Public Class dlgTransfers
Private cTransferLocation As String
Public Sub New(ByVal memNum As String)
' This call is required by the Windows Form Designer.
InitializeComponent()
lblTransferMemNum.Text += " " + frmAddMembers.txtMemNum.Text
End Sub
Public Property TransferLocation() As String
Get
Return cTransferLocation
End Get
Set(ByVal value As String)
cTransferLocation = value
End Set
End Property
End Class
Setting the value of the private variable, will this inturn update the publc variable TransferLocation?
VB.NET:
Private Sub dlgTransfers_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Me.cTransferLocation = txtBranch.Text.ToString
End Sub
I then believed I could access the variable as follows:-
<classname>.<public variable>
So if transferdialog Is NOT Nothing then I could use the following code:
VB.NET:
Dim passedTransferLocation as string = Me.transferdialog.TransferLocation
However this errors as it appears to recognise as a window form class as it has been dimensioned and not transferdialog class with an available public variable.
I know there is several ways to pass values between forms, can anyone point me in the right direction of how to access values via properties i.e what im trying to do?
I've also started to read about shared variables too, so if there is a strong reason not to use the method I've tried to implement Im all ears.
Thanks and hope the problem is clear.
Rob