Wrox Programmer Forums
|
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
 
Old September 14th, 2004, 12:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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
 
Old September 15th, 2004, 08:45 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ?

 
Old September 15th, 2004, 09:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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
 
Old September 16th, 2004, 08:39 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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).

 
Old September 16th, 2004, 01:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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
 
Old September 19th, 2004, 05:10 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I understand. And it works perfectly. Thank you very much for your help and for your patience!

Mladen

 
Old September 19th, 2004, 03:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

My pleasure ;)
 
Old December 23rd, 2005, 03:01 AM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old December 23rd, 2005, 10:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Group Variables (from Form to Module) emanuele.musa VB How-To 1 July 20th, 2007 03:58 PM
Call Standard Module Error Handler from Form mod johndickerson BOOK: Beginning Access 2003 VBA 0 April 19th, 2007 11:12 AM
Passing an array from module to form ftm Excel VBA 2 March 8th, 2007 07:39 AM
Addressing a control on a form from another form Lamprey Access 1 March 3rd, 2005 12:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.