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
  #1 (permalink)  
Old August 26th, 2004, 01:10 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Addressing form from module

Please, help me with this problem:
I need to address the text box on the form from the module procedure.
But not on the form known by name, but generally - on the "form from which the module procedure was called".
Thank you in advance.
MK

Reply With Quote
  #2 (permalink)  
Old August 26th, 2004, 07:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Why not pass the textbox in as a parameter to the module?

Brian
Reply With Quote
  #3 (permalink)  
Old August 26th, 2004, 04:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Put this in your form:

Friend Shared tbNewTextbox as Textbox = New Textbox
-------
In your form load event:

tbNewTextbox = [TextBoxName]

-------
In your module:

[FormName].tbNewTextbox.[xxxx]

See if this helps.

J
Reply With Quote
  #4 (permalink)  
Old August 30th, 2004, 08:48 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but form name is the real problem.
How to pass the form name to the module and how to address
back the form from the module?

Reply With Quote
  #5 (permalink)  
Old August 30th, 2004, 02:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I wouldn't pass it the form name, but a reference to the form itself. Just remember, the Form is a control like everything else (inherits from the Control class), and can be referenced as a variable.

Brian
Reply With Quote
  #6 (permalink)  
Old September 5th, 2004, 08:40 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but can you tell me explicitly -
how to "pass ... a reference to the form itself ..." from the form to the module procedure, so that the module procedure adresses back the
form (enters certain number to the form's text box).

Reply With Quote
  #7 (permalink)  
Old September 6th, 2004, 03:37 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Quote:
quote:Originally posted by MKri
 Thanks, but can you tell me explicitly -
how to "pass ... a reference to the form itself ..." from the form to the module procedure, so that the module procedure adresses back the
form (enters certain number to the form's text box).


Right - make the form you're interested in a parameter in the module method, e.g.
Code:
Public Sub FormMethod(ByRef refFrm as Form1)
    ' do stuff with refFrm here...
End Sub
Then back in the form, say when someone presses a button:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles Button1.Click
    ' call the module method, passing in this form as a parameter...
    FormMethod(Me)
End Sub
Reply With Quote
  #8 (permalink)  
Old September 12th, 2004, 06:09 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but it is valid for Form1 only and the whole point is that it should be valid for more forms, which all have text boxes txt1, txt2, txt3 and txt4. Otherwise it would be no need to put that procedure in the separate module.

Reply With Quote
  #9 (permalink)  
Old September 13th, 2004, 07:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

When you open a form, you typically do:

objForm = New Form1
objForm.Show()

Now say you want to pass in a reference to the current form (pass in a reference of the currently opened form to Form1, you could do:

objForm.DoSomethingWithForm(Me)

That function would be defined as:

Public Sub DoSomethingWithForm(ByRef objForm As Form1)
  'code here
End Sub

Also, I like to set the owner property, which is the reference to the owner form. So what I do is:

objForm = New Form1
objForm.Owner = Me
objForm.Show()

And in the Form1 code, you reference the owner.

Brian
Reply With Quote
  #10 (permalink)  
Old September 14th, 2004, 09:17 AM
Authorized User
 
Join Date: Jun 2004
Location: Karlovac, , Croatia.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your answer, but I'm not sure I understand it. Can you please apply it on my specific problem:

I have forms frm1, frm2 ... frm20. They are opened one at a time.
All of them have 4 text boxes: txt1, txt2, txt3 and txt4.
All of the forms have a procedure proc() which does the following:

txt1.Text = "a"
txt2.Text = "b"
txt3.Text = "c"
txt4.Text = "d"

Now I want to avoid having that procedure in each one of the 20 forms. I want to have it only once and it would probably be in a
separate module.
So, I need an opened form to be able to call that procedure in that
module and get it's text boxes filled with "a", "b", "c" and "d".

In VBA you would simply put procedure

Sub proc()
CodeContextObject.txt1 = "a"
CodeContextObject.txt2 = "b"
CodeContextObject.txt3 = "c"
CodeContextObject.txt4 = "d"
End Sub

in a separate module and call it from any of the forms:

Sub btn1_Click()
Call proc
End Sub

and the text boxes would get their values.

So, how to do it in VB.NET?

Thanks in advance.







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 04:17 PM.


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