Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use variable values over different forms..

Status
Not open for further replies.

fr33l3r

MIS
Dec 2, 2003
24
NL
I want to use a variable value from Form1 in Form2. How can i do this? I have made a module to dim a public variable. But now i need to use the value from form1.

In Form1 i have a textfield for input. The value is like
testing.text = "testing"

In Form2 i have a label that shows the value of testing.text in Form1 like testing.caption = Form1.testing.text (should be "testing" right?)

Who can help me?

Okke.
 
There are two main ways that you can do this.

1. Declare a public or global variable in a module (.bas).

Code:
Public MyVariable as String

Then anywhere in you program you can access it as

Code:
MyVariable = ??

2. A second method is to declare a public variable within a specific form (.frm).

Code:
Public MyVariable as string

This ties it to the form so you have to reference the form to get to the variable.

Code:
Form1.MyVariable = ??

The difference is where you declare it, and that will determine how you reference it.

Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
ok it works with a textbox or a textlabel (something stabel) but i can't get it right with a inputbox. for example:
Module1:
Public test As String

Form1:
test = inputbox "type somthing here.."
msgbox test

When i want to take the value of test to Form2 to put it in a label it doesn't work anymore.

Form2:
label.caption = test

What do i do wrong then?
 
Assuming that the msgbox shows you the correct value, is there any place between the msgbox, in form1, and the assignment to the label, in form2, that 'test' is being changed. I would put a watch on test to break if the value changes and see if it is being changed.



Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
check the ever actual faq222-400

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
It works in a new project.. so i think there is something to be reviewed in my current project :)

but thanx for your input.. i do know where to look now.

Okke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top