 |
| Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book:
Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 11th, 2008, 11:30 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
|
|
To pass value of string variable to another form
Hi all
Thank you for all your help and I have learnt a lot so far.
Now I am trying to pass the value of the selection - a string variable - to another form. Information from form1 is about what to play ie word, spell or math. The value of the variable will be one of these three words. I need to pass this to the next from so this form can modify depending on which game to play.
My problem is I am unable to pass this string variable value from form1 to form2. Any help is very much appriciated.
Thanks
thillai
|
|

March 11th, 2008, 01:59 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
And what have you tried so far?
Is the form already open? Do you want to open the form with the value?
One way is to create an instance of the form, then call a method on it that receives the value in question. This method initializes the form based on the data passed in and then calls the method to show itself.
-Peter
peterlanoie.blog
|
|

March 12th, 2008, 10:39 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi peter
Thanks for the reply. The form1 allows user to select one of three options ie word, spell and math. Once the selection is made and button clicked, another form loads- form2- and I want the selection from form1 to be passed to form2.
Cannot make it work, Please help.
Thanks
thillai
|
|

March 12th, 2008, 01:04 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Thillai,
I understand what you are trying to do. But you still have not shown us what you have tried so far. You say you cannot make it work. How is it not working? Can you post the relevant code you are trying to use? That will help us help you.
-Peter
peterlanoie.blog
|
|

March 12th, 2008, 03:24 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
(I donât mean to horn in here, Peter. But, that said . . .)
Thillai,
When you load the second form, the 1st form is still loaded. You can read the values of the controls on the first from directly be referencing the name of the form, the name of the control, and the name of the property you are examining. Let's say form 1 is frmOne, and the control is a text box named txtValue. In form two, you can reference frmOne.txtValue.Text to read that control. The same applies to check boxes and radio buttons.
|
|

March 13th, 2008, 03:29 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi all
Yes I have done it using Brian's method; In form2 I wrote strChoice=Form1.txtSelection.Text, where strChoice is a string variable defined in form2, txtSelection is the textbox in form1 where selection is made.
Thanks all.
I am learning every time I have a doubt.
thillai
|
|
 |