|
-
Jun 12th, 2000, 06:07 AM
#1
Thread Starter
Member
Hi,
This should be a simple question, hopefully I get a reply 
I have 2 forms, and I need to pass a variable from one form to the other form.
How do I do this?
For example, in form2, this is the screen where I ask a user to enter file location..... ie: C:\Mydocuments\text.txt
I want this information to be available in my form1.
How do I write the code? I'm not using modules, just forms...
Thanks for reading my post!
-
Jun 12th, 2000, 06:13 AM
#2
Store it in the form's Tag property. For example, make a Form with a CommandButton on it.
Code:
Private Sub Command1_Click()
Form2.Tag = "C:\MyFile"
Form2.Show
End Sub
On Form2, make another CommandButton and put this code in it.
Code:
Private Sub Command1_Click()
Print Me.Tag
End Sub
-
Jun 12th, 2000, 06:15 AM
#3
_______
variable
just declare a public variable to store your info
'main form
Option Explicit
Public strHolder as string
you can give it value from either form
and it will retain it's value over both
strHolder = text1.text '("C:\Mydocuments\text.txt")
It's now available to all...
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 12th, 2000, 08:00 AM
#4
PowerPoster
Using Tag is better, because you no need to declare any public variable.
-
Jun 12th, 2000, 08:18 AM
#5
Fanatic Member
Both ways work!
You can declare it through "Tag" property, but it will be hard to keep track in the future if your program is large.
You can declare it as "Public" but it will take up resource for the variable.
You have a choice between
-being Resource Saving
or
-being Organize.
I would go for "Public" if you are not advance with VB yet.
Make sure if you use "Public", make good practice to declare in a separate module strictly for global and constant variables. This will keep it organize.
Chemically Formulated As:
Dr. Nitro
-
Jun 13th, 2000, 02:47 AM
#6
If you are only going to store one Public variable, than making a seperate module just to store one variable is not necessary. It'll be better to use the Tag in this case.
-
Jun 13th, 2000, 03:00 AM
#7
If Form2 has not been unloaded (it can be hidden), the simplest thing to do is to directly refer to contents of the field on Form2. So assuming that your user enters data into Text1 just do something like MsgBox "Path = " & Form2.Text1.Text
-
Jun 13th, 2000, 04:44 AM
#8
Hyperactive Member
A variation on Martin's answer is to do the following ...
.
.
.
form2.txtName = strName
form2.show 1
.
.
.
VB will automatically load form2 when the control is referenced on it and you can avoid the use of either tag or a global variable. However, if the value is not going into a field on form2 then use the tag property, it's 'cleaner'.
That's Mr Mullet to you, you mulletless wonder.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|