In a previous tip, we showed you an object-oriented way to pass values
to form variables. To do so, we added property Get and Let statements
to the form's underlying code module. This created a public property for
the form that you could set with code similar toForm1.myProperty = "Fifty"
Many of you pointed out that as an alternative to the lengthy Get and
Let procedures we used in the tip, you could also simply declare a
form-level public variable, as inPublic myProperty as Integer
Given this declaration, you could then set and retrieve the property
using the same syntax we used above.
While declaring the property in this manner is perfectly legal, it does
have a broader potential for errors than do Get and Let statements --
though it's still better than using full-blown, application level,
global variables.
The problem occurs because under the shorter property declaration
scenario, there's no way to validate the value to which you want to set
the property. For instance, given the property declaration above, as an
integer data type, the earlier statementForm1.myProperty = "Fifty"
would generate a type mismatch error. When you use Get and Let
procedures, on the other hand, you can not only validate potential
property settings and provide meaningful error feedback; but you can
also perform complicated calculations when retrieving or setting these
property values.
Shorter Visual Basic code isn't always efficient code
By ElementK Journals, published on 14 Jul 2001
| Filed in
You might also like...
VB 6 forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
Send SMS with SMPP
by mmahmoud (0 replies)
VB 6 podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments