|
-
Aug 9th, 2007, 05:23 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED][02/03] how to pass variable from one form to another form
Hi all,
Now i'm facing a problem when i passing a variable from one form to another form, i can't get the value.
I used the method of property.
vb code
Form A
Code:
Private UserID as string
Private Sub New()
Me.User_ID = textbox1.text
End Sub
Public property User_ID() as string
Get
Return UserID
End Get
Set (ByVal Value As String)
UserID = Value
End Set
end property
Form B --> Try to get value from Variable form A
Code:
dim frm as new FormA
textbox1.text = frm.User_ID
Last edited by nUflAvOrS; Aug 10th, 2007 at 07:08 PM.
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Aug 9th, 2007, 05:31 AM
#2
Re: [02/03] how to pass variable from one form to another form
-
Aug 9th, 2007, 05:51 AM
#3
Thread Starter
Hyperactive Member
Re: [02/03] how to pass variable from one form to another form
Thx Andy showed me the link.
I faced the problem while passing value from parent to child .
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Aug 9th, 2007, 07:12 AM
#4
Registered User
Re: [02/03] how to pass variable from one form to another form
Assign a variable as public in Form A and then assign some values to that variable and call that variable from Form B.
Example
Public test as string="Testing"
'Write this code in Form A and write the following line in Form B
messagebox.show(FormA.test)
-
Aug 9th, 2007, 07:30 AM
#5
Re: [02/03] how to pass variable from one form to another form
You had it backwards in the constructor. It should be
Code:
Private Sub New()
Me.textbox1.text = UserID
End Sub
And in formA, when you instantiate formB, you should set the User_ID property of formB
Code:
'This is done in formA
Dim frmB As New FormB
frmB.User_ID = "whatever id you want to put in here"
frmB.Show()
-
Aug 9th, 2007, 07:36 PM
#6
Thread Starter
Hyperactive Member
Re: [02/03] how to pass variable from one form to another form
Thx stanax,
I ever tried your method, but when everytime i need passing variables i have to create a lot of property.Furthermore, if i create a property inside a class why i cannot used the class public property to store the value when program is running ?
Stanax i rated you ... thanks a lot
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Aug 9th, 2007, 10:50 PM
#7
Thread Starter
Hyperactive Member
Re: [02/03]Please Help how to pass variable from one form to another form
My project contains a class store the public variable
In VB 6 i always used
Code:
Public Variable as string
to assign a variable to store value along project is running.
In .net i'm still new
I tried create a class but still cannot obtains the value
Class
Code:
Public Class VariableStorage
Private UserID As String
Public Sub New()
MyBase.new()
End Sub
Public Property User_ID() As String
Get
Return UserID
End Get
Set(ByVal Value As String)
UserID = Value
End Set
End Property
End Class
Code:
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
Dim USerID As New VariableStorage
USerID.User_ID = Me.txtUserID.Text.ToString
end sub
Code:
Private Sub mdiForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim UserID As New VariableStorage
Me.sbpMdiForm.Panels.Item(0).Text = "User ID: " & UserID.User_ID
END SUB
thanks !!!!!
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Aug 10th, 2007, 07:47 AM
#8
Re: [02/03] how to pass variable from one form to another form
 Originally Posted by nUflAvOrS
Thx stanax,
I ever tried your method, but when everytime i need passing variables i have to create a lot of property.Furthermore, if i create a property inside a class why i cannot used the class public property to store the value when program is running ?
Stanax i rated you ... thanks a lot
Unless it is absolutely needed, I tend not to use public variables because they're considered as bad programming practice... Why is it bad? If you just google for "why are public variables bad?" and you'll get the image
-
Aug 10th, 2007, 07:09 PM
#9
Thread Starter
Hyperactive Member
Re: [RESOLVED][02/03] how to pass variable from one form to another form
THANKS stanav ,, ;-) i will take ur advise
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|