VB Anyone? - DFWstangs Forums
 
LinkBack Thread Tools Display Modes
post #1 of 7 (permalink) Old 09-14-2003, 10:21 PM Thread Starter
 
Join Date: Mar 2003
Posts: 1,394
VB Anyone?

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.
xtremcoder is offline  
Sponsored Links
Advertisement
 
post #2 of 7 (permalink) Old 09-14-2003, 11:09 PM
Timmay
 
Tiny Tim's Avatar
 
Join Date: Aug 2001
Posts: 4,898
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
Tiny Tim is offline  
post #3 of 7 (permalink) Old 09-14-2003, 11:20 PM Thread Starter
 
Join Date: Mar 2003
Posts: 1,394
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?
xtremcoder is offline  
 
post #4 of 7 (permalink) Old 09-14-2003, 11:24 PM
Timmay
 
Tiny Tim's Avatar
 
Join Date: Aug 2001
Posts: 4,898
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.
Tiny Tim is offline  
post #5 of 7 (permalink) Old 09-14-2003, 11:28 PM Thread Starter
 
Join Date: Mar 2003
Posts: 1,394
and i declare global variables how
xtremcoder is offline  
post #6 of 7 (permalink) Old 09-14-2003, 11:30 PM
Timmay
 
Tiny Tim's Avatar
 
Join Date: Aug 2001
Posts: 4,898
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.
Tiny Tim is offline  
post #7 of 7 (permalink) Old 09-14-2003, 11:36 PM Thread Starter
 
Join Date: Mar 2003
Posts: 1,394
cool, so its just as in C++. thanks.
xtremcoder is offline  
Sponsored Links
Advertisement
 
Reply

Bookmarks

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the DFWstangs Forums forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



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

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

 
For the best viewing experience please update your browser to Google Chrome