Embedded Visual Basic Windows Ce And Pocket Pc Mobile Applications [Electronic resources]

Chris Tacke; Timothy Bassett

نسخه متنی -صفحه : 108/ 24
نمايش فراداده

eMbedded Visual Basic®: Windows® CE and Pocket PC Mobile Applications

By Chris Tacke, Timothy Bassett

Table of ContentsChapter 2. Introducing eMbedded Visual Basic


All Things Are Variant

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.