Professional Documents
Culture Documents
Applications
Walter Milner
Event-driven programming
Dim x as Integer
Dim x,y as Integer NO!
Is case sensitive (kind of)
Variable naming conventions
• Microsoft Simonyi Hungarian Reddick
• House rules
Assignment statement –
x=4
Option Explicit YES!
Constants –
Private Const MyInt As Integer = 5
Comments, line continuation and hex
Integer Long
Single Double
Currency
Byte unsigned 0 - 255
String
Boolean
Date
Object
Variant NO!
Data type conversion
DIM x as integer
x = Cint("10")
Copy this
Correct it
Add other buttons
VB Core II
Conditionalstatements
Exception handling
Loops
Arrays
Debugging
if statements
If c > 5 Then x = 1: y = 3
If c > 5 Then
x=1 If c > 5 Then
y=3 x=1
End If y=3
ElseIf c = 4 Then
z=7
If c > 5 Then
Else
x=1
x=9
y=3
End If
Else
z=7
End If
select
Dim Number
Number = 8 ' Initialize variable.
Select Case Number ' Evaluate Number.
Case 1 To 5 ' Number between 1 and 5, inclusive.
x=4
Case 6, 7, 8 ' Number between 6 and 8.
x=5
Case 9 To 10 ' Number is 9 or 10.
x=6
Case Else ' Other values.
x=7
End Select
Error and exception handling
myErrorHandler:
If Err.Number = 13 Then
MsgBox ("Please enter a valid number")
Else
MsgBox (Err.Description)
End If
Resume Next
End Sub
For next loops
Dim i, j As Integer
For i = 1 To 5
x(i) = 99
Next