PDA

View Full Version : VB Anyone?


xtremcoder
09-14-2003, 10:21 PM
I was working on my lab assignment and I wanted to take it “one step further” and make it a little more complex. I need to access a variable that I declared on another form. I tried to do:

otherForm.variableName

But I got a compiler error saying that object did not exist. I know you can do:

otherForm.Object.Property

Because I did this (from a second form) as a test:

Label1 = Form1.Text1.Text

So basically my question is, how do I access variable from another form. I remember something about have to declare the variables somewhere else, but I don’t remember the specifics of how you do it.

Tiny Tim
09-14-2003, 11:09 PM
VB 6 or .Net?

In .Net you create a new instance of your form i.e.

dim myform as new form1()

then say

myform.myvariable = currentform.textbox.text

where myvariable is a public global variable on form1

then

myform.show()

and myvariable on your new form will have the value of the currentform.textbox.text

xtremcoder
09-14-2003, 11:20 PM
its vb 6 if i read what you wrote right, thats what i did. but i got an error saying that my variable wasnt an object of my form. so i need to declare what i guess would be like global variables?

Tiny Tim
09-14-2003, 11:24 PM
declare it as a global variable. you should be able to get it then. i haven't coded in vb6 in quite a while so I am a bit rusty.

xtremcoder
09-14-2003, 11:28 PM
and i declare global variables how:confused:

Tiny Tim
09-14-2003, 11:30 PM
oh yeah. sorry :) you put them outside of your procedures/functions.

i.e.

dim globalv as integer

private sub form1_load()

blah blah blah

end sub

this way any procedure/function can access the variable. hence the reason why it is called a global variable.

xtremcoder
09-14-2003, 11:36 PM
cool, so its just as in C++. thanks.