Wednesday, October 13, 2010

Basic Basic Scripting Basics (Very Very Basic Basics)

This is BAD:
If X > 5 Then
...do something...
End If

If X < 5 Then
...do something...
End If

If X = 5 Then
...do something...
End If


This is BETTER:

If X > 5 Then
...do something...
ElseIF X < 5 Then
...do something...
Else
...do something...
End If

This is BAD:


If X = 1 Then
...do something...
End If

If X = 2 Then
...do something...
End If

If X = 3 Then
...do something...
End If


This is BETTER:


Select Case X
Case 1: ...do something...
Case 2: ...do something...
Case 3: ...do something...
Case Else: ...do nothing...
End Select


Implicit TRUE expressions:


If AllowedSubnet(ipAddress) Then
...do something...
End If


Is the SAME THING as…


If AllowedSubnet(ipAddress) = True Then
...do something...
End If


Implicit/Default Properties:

Dept = objRecordSet(“department”)

Is the SAME THING as…


Dept = objRecordSet.Fields(“department”)


Is the SAME THING as…


Dept = objRecordSet(“department”).Value


Is the SAME THING as…


Dept = objRecordSet.Fields(“department”).Value

No comments: