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!

How to comunicate with modal forms?

Status
Not open for further replies.

BirdieNamNam

Programmer
Feb 12, 2004
52
0
0
SE
Hello dear friends!

I have som modal forms that I use as input to some things in my main form. The communication, that is the variables set by the modal form, is taking place through global variables. Is there a smarter way to do this, something like calling variables set in the form from the main form.

Actually, this is a question about programming concepts. It works fine with the global variables, but if anyone has any better suggestion, I'll gladly accept it.

Best regards, Sebastian.
 
You can access variables from another form using the following:

in Form1:
Option Explicit
Public variablename as String

in Form2:

Form1.variablename


But i usually work in a different way; to tell you the truth it started out using global variables within a module but know i use a class which is initialized at the begining of the application and works trhoughout setting properties on the go! I use this class for Application Settings! I don;t know exactly what you want these public variables for.

If they are used once and thats all then neat global variable wouldn't harm.

GoodLuck

Nick
 
Ok. Thanks Nick, I think I'll stay with my global varables then.

/Sebastian.
 
you could also add properties to your main form

Code:
' this is in the form
Private myProperty As String ' this could be anything

Public Property Get MyVal() As String
    MyVal = myProperty
End Property

Public Property Let MyVal(MyNewVal As String)
    myProperty = MyNewVal
End Property

You can the access them the same way as using public variables.

This is the 'proper' way of doing it, but you can use public variables as well. The public variable way is probably better than global variables, it is cleaner.


Matt


If you can keep your head while those around you are losing theirs, you obviously haven't grasped the seriousness of the situation
 
Oh tTo me it looks like the properties of the form and the public variables of the form are more or less the same thing. Thanks, I'll program proper!

/Sebastian.
 
I agree with MatDavies! thats the proper way of doing it...and thats what i was saying when i mentioned the properties in a class!

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top