|
-
Feb 19th, 2000, 08:36 AM
#1
Thread Starter
Member
How would you pass a variable from one form to another? The only thing I can think of is to setup some global variables. I am trying to keep the project clean and that would seam to waste a lot of memory.
-
Feb 19th, 2000, 08:58 AM
#2
You can use a Public variable..
this variable can you use everywhere in your project.
Public String As String
-
Feb 19th, 2000, 11:46 PM
#3
New Member
Yes, you can use Public variables declared at the form level:
Public MyString as String ‘ Declared in Form1
Then you can access MySring from another form by using a fully qualified name:
Form1.MyString ‘ Used in another form
But you said you wanted to keep your project “clean” Maybe you should consider making your variable a property of Form1. This gives you some advantages over a simple variable. One advantage is you can validate the data when it’s being set (so it’s in a specific range or something - and raise an error if it doesn’t fit). Also you can make it read-only. And you can encapsulate the procedure of achieving the value of the property to hide the process from other parts of the program (for example, let’s say the variable represents the average of certain text boxes on the form – all you have to do is access the variable it IS the average automatically). You can also assign a default value for the variable. Another advantage that I think is cool is that the “variable” appears in the dropdown list with the other properties of the form.
Another advantage is the variable can be an event responding to some other action in the program.
And it can be a method as well (although methods and properties are very similar)
It is actually very easy to make your variable a property of the form. If you want to know how simply send me a dollar and I will tell you 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|