All Things Are Variant

Team-Fly    

 
eMbedded Visual Basic: Windows CE and Pocket PC Mobile Applications
By Chris Tacke, Timothy Bassett
Table of Contents
Chapter 2.  Introducing eMbedded Visual Basic


Another major difference between eVB and VB6 is that eVB is far closer to VBScript and, as such, doesn't support strong-typed variables. All variables in eVB are Variants, even if you declare them otherwise . Using the As variable_type syntax simply gives you IntelliSense for objects, making development a bit easier.

However, again, this has consequences to be aware of. First, a variable won't get initialized . Consider the following:

 Dim iMyInteger As Integer 

In VB6, after this declaration, iMyInteger is equal to zero; in eVB, it's just an empty variant. This can sometimes cause logic errors that are difficult to debug, so you should get in the habit of initializing all eVB variables.

Assuming that we have a new project with a single form, Form1, consider this code snippet:

 Dim frmMyForm As Form Dim iMyInteger As Integer frmMyForm = True frmMyForm = frmMyForm + 1 Set iMyInteger = Form1 frmMyForm = iMyInteger.Caption iMyInteger = iMyInteger.Left + 1 

In VB6, this won't even compile, but in eVB it will actually run, with frmMyForm ending up as Form1 and iMyInteger ending up with the value 1 (or something similar). Again, this can cause some difficult-to-debug logic errors if you mix variable types, and is a strong argument for always using Option Explicit and Hungarian notation.


Team-Fly    
Top
 


eMbedded Visual BasicR. WindowsR CE and Pocket PC Mobile Applications
eMbedded Visual BasicR. WindowsR CE and Pocket PC Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 108

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net