 |
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 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
|
|
|

September 14th, 2004, 12:21 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
In your module put:
---------------------------------------------------
Public Sub PassFields(ByVal txt1 As TextBox, ByVal txt2 As TextBox, ByVal txt3 As TextBox, ByVal txt4 As TextBox)
txt1.Text = "Text1"
txt2.Text = "Text2"
txt3.Text = "Text3"
txt4.Text = "Text4"
End Sub
----------------------------------------------------
From your form:
----------------------------------------------------
PassFields([TextBox1Name], [TextBox2Name], [TextBox3Name], [TextBox4Name])
----------------------------------------------------
J
|

September 15th, 2004, 08:45 AM
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for your help.
But, let me put one additional question:
What do you exactly mean by TextBox1Name?
Is it "txt1", or txt1.Name ?
|

September 15th, 2004, 09:24 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
This is whatever you name your first textbox on any of the forms, assuming that each form has different names for each of the textboxes.
So if on your 1st form, you have the first textbox named as "txtForm1Textbox1", then you would write:
---------------------------------------
PassFields(txtForm1Textbox1, [TextBox2Name], [TextBox3Name], [TextBox4Name])
---------------------------------------
-replace the last 3 with the names of the other textboxes on your 1st form.
On your second form if you have the first textbox named as "txtForm2Textbox1", then you would write:
---------------------------------------
PassFields(txtForm2Textbox1, [TextBox2Name], [TextBox3Name], [TextBox4Name])
---------------------------------------
-replace the last 3 with the names of the other textboxes on your 2nd form.
Realize that your are passing the textbox itself as the object and not just a string(it's name). If we look again at some of the previous posts, I believe this is what Brian(bmains) said.
J
|

September 16th, 2004, 08:39 AM
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Two things confuse me in your explanation:
1. We discuss a real example where we have 20 forms with text boxes named txt1, txt2, txt3 and txt4, and you introduce some general names such as txtForm1Textbox1.
2. You don't seem to answer, how will the module procedure PassFields know, which form does the call come from (which form's txt1, txt2, txt3 and txt4 should it fill).
|

September 16th, 2004, 01:29 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Quote:
quote:Originally posted by MKri
Two things confuse me in your explanation:
1. We discuss a real example where we have 20 forms with text boxes named txt1, txt2, txt3 and txt4, and you introduce some general names such as txtForm1Textbox1.
|
txt1, txt2, txt3, and txt4 in my example are NOT the names of the textboxes on the forms. They are arguments accepted by the sub.
txtForm1Textbox1 is a name that I have supplied (it is equal to txt1 in your example - I would probably name them a little differently, but you can use what you want). The reason that I used this name as the example is that I wanted to show you how I was using the different textboxes on different forms to access the same sub.
Quote:
quote:Originally posted by MKri
2. You don't seem to answer, how will the module procedure PassFields know, which form does the call come from (which form's txt1, txt2, txt3 and txt4 should it fill).
|
It knows because you are passing the textboxes as arguments to the procedure.
------------------------------------
Public Sub PassFields(ByVal txt1 As TextBox, ByVal txt2 As TextBox, ByVal txt3 As TextBox, ByVal txt4 As TextBox) ' - arguments accepted in blue
txt1.Text = "Text1"
txt2.Text = "Text2"
txt3.Text = "Text3"
txt4.Text = "Text4"
End Sub
------------------------------------
PassFields(txtForm1Textbox1, [TextBox2Name], [TextBox3Name], [TextBox4Name]) ' - arguments being passed in blue
------------------------------------
J
|

September 19th, 2004, 05:10 AM
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Now I understand. And it works perfectly. Thank you very much for your help and for your patience!
Mladen
|

September 19th, 2004, 03:44 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
My pleasure ;)
|

December 23rd, 2005, 03:01 AM
|
Registered User
|
|
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This works when passing these textboxes by value? I have a similar question to that of one posted above; how can the function possibly be changing the correct textbox if passed by value?
|

December 23rd, 2005, 10:22 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Look up reference types. Read this on passing reference types byval:
http://msdn.microsoft.com/library/de...parameters.asp
It is in C#, but it explains what is happening.
J
|
|
 |