Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Getting a variable froma diff form VB


rockbll4's Avatar
[TheN00bHacker]
0 0

Does ne one kno how to get a variable form a diff form? like i have a variable loaded on one form that i need to access form a diff form….

also is ther e away to get a function from one form and load it into another?

plz andt hnx


ghost's Avatar
0 0

You have to use a module. Make a new module, and declare the variable in that as public, like:

Public intx as integer

then, as long as you don't dim intx in any of your other forms, you can use it in all of them.


rockbll4's Avatar
[TheN00bHacker]
0 0

alright thnx, can i put an array in a module too?


ghost's Avatar
0 0

Yes, of course. They work in the same way. Just declare them as Public instead of Dim.:)


rockbll4's Avatar
[TheN00bHacker]
0 0

lol ok thnx… ok, how do i use the module on the form? :D


ghost's Avatar
0 0

the module will run when you run the the code, and to call the variable just use is as normal……


rockbll4's Avatar
[TheN00bHacker]
0 0

i created a module and made an array and its not letting me use it. when it loads it says: Invalid Outside Procedure

hers a part of it:

Public ChemArr(1 To 18, 1 To 4) As String

'the element hydrogen

ChemArr(1, 1) = "Hydrogen" ChemArr(1, 2) = "H" ChemArr(1, 3) = "1+" ChemArr(1, 4) = "1"


AldarHawk's Avatar
The Manager
0 0

what exactally are you trying to do here? A little background would help a lot.


ghost's Avatar
0 0

You can't assign a variable a value in a module, you will either need to declare it a constant (which should work fine if I understand what you are doing), or assign it a value in one of your forms.


rockbll4's Avatar
[TheN00bHacker]
0 0

J-Wreck wrote: You can't assign a variable a value in a module, you will either need to declare it a constant (which should work fine if I understand what you are doing), or assign it a value in one of your forms.

ok, well can i access the array from all forms if i assign them in one form?


ghost's Avatar
0 0

Yes, that would work fine.