Chapter 5 Visual Basic Variables and Formulas, and the .NET Framework 139
Scroll to the top of the Code Editor to see the dozen or so program statements I added
to declare 11 variables in your program—one for each of the fundamental data types
in Visual Basic. (I didn’t create an example for the SByte, UShort, UInteger, and ULong
types, because they closely resemble their signed or unsigned counterparts .) By placing
each Dim statement here, at the top of the form’s code initialization area, I’m ensuring
that the variables will be valid, or will have scope, for all of the form’s event procedures.
That way, I can set the value of a variable in one event procedure and read it in another.
Normally, variables are valid only in the event procedure in which they’re declared.
To make them valid across the form, you need to declare variables at the top of your
form’s code.
Note I’ve given each variable the same name as I did in the data types table
earlier in the chapter so that you can see the examples I showed you in actual
program code.
- Scroll down in the Code Editor, and examine the Form1_Load event procedure.
You’ll see the following statements, which add items to the list box object in the
program. (You might remember this syntax from Chapter 3, “Working with Toolbox
Controls”—I used some similar statements there .)
- Scroll up and examine the ListBox1_SelectedIndexChanged
event procedure.