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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing data 1

Status
Not open for further replies.

drewdaman

Programmer
Aug 5, 2003
302
0
0
CA
hello

i have yet another question! i am quite a vb newb!

i get some user input from a form. now if i have, say a module, where i implement what to do with the data, how can i pass the data from the "form code module" to the other module? i guess one way would be to use global vars in the other module.. but that kinda sucks!

i'm building a sort of a "wizard". so i have a bunch of forms with "next" buttons.. so eventually, i would have to get the data and pass it to another module.

thanks!
 
well.. you can't instantiate the object unless you include the header file.. so you can't just instantiate it anywhere.you have to specify (but inclusion of the header file- possibly recursively) where you can and cannot instantiate a certain object.
 
Geoff,

I've certainly used my share of globals. I'm trying to reform.[wink] From what I've read, both from a general programing standpoint (e.g., Code Complete by Steve McConnell) and Excel VBA programming in particular (Professional Excel Development by Bullen, Bovey & Green), the consensus seems to be to limit the use of global variables to where absolutely necessary. One common theme against their use is that it breaks data hiding/encapsulation. Any procedure, anywhere in code can not only see these vars but more importantly, change their value. This can lead to hard to detect bugs. Use of globals tends limit code re-use, as well. As Drewdaman pointed out, these tend to be oop issues in particular.

My 2¢

Regards,
Mike
 
cheers for the update Mike - must admit that I'd never heard of any particular issues with their usage but then my code tends to be for one off use as each project has its own intrcacies - I guess I am less of a programmer and more of an "automator"

I like the idea of creating your own objects but to me, the downsides of using global vars are so minimal that I'm gonna keep right ahead using 'em !!

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
well.. xlbo... don't take this the wrong way.. but if you ever program in java/c++.. you will be fired in a day if you continue to do that!

anyways.. i appreciate teh help people!
 
As I said - not really a programmer - I learnt VBA because it helps me do my job (Analyst) - I come at it from knowing Excel very well and then using VBA to create mini apps / automation. Don't take this the wrong way but I want to learn c++ & java in the same way that I want a large truck to come to a stop on my foot !!

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
[LOL] indeed - hope Mike's response works out for ya !

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
One of the cool features of VB, is that instead of making globals, you can create your own public properties for objects, like forms. For instance:
(inside "Form1")
Code:
option explicit
private strFname as string

public Property Get FirstName() as string
    FirstName = strFname
End Property

Public Property Let FirstName(strInput as string)
   strFname = strInput
End Property

Then in other forms you can access the properties as you would access any object's properties.
Inside the property declaration, you can do anything you want to the data being passed in, integrity control, etc. By leaving out the "Let" property, you can make them read-only, so only the owner form can change them, your other forms can only see them.
If you have lots of variables to pass around, I think Mike's solution is better though.
 
If you are getting info from the user into a series of discrete controls, such as text boxes or whatever, you can directly read the values of those from anywhere in the app.
newvarvalue = formwithdata.controlname.text

and so forth...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top