Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old September 14th, 2004, 12:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #12 (permalink)  
Old September 15th, 2004, 08:45 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
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 ?

Reply With Quote
  #13 (permalink)  
Old September 15th, 2004, 09:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #14 (permalink)  
Old September 16th, 2004, 08:39 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
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).

Reply With Quote
  #15 (permalink)  
Old September 16th, 2004, 01:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #16 (permalink)  
Old September 19th, 2004, 05:10 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
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

Reply With Quote
  #17 (permalink)  
Old September 19th, 2004, 03:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

My pleasure ;)
Reply With Quote
  #18 (permalink)  
Old December 23rd, 2005, 03:01 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
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?

Reply With Quote
  #19 (permalink)  
Old December 23rd, 2005, 10:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:29 AM.


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