Complete Example
In the following code, notice techniques notice techniques 2a and 2c fail with Null values.
<%@LANGUAGE='VbScript'%>
<%Option Explicit%>
<html>
<body>
<h1>Empty String Check</h1>
<%
Dim s
''''''''''''''''''''''''''''
''' 1. Unassigned value. '''
''''''''''''''''''''''''''''
''Technique A
'''''''''''''
If s = "" Then
Response.Write("<br>1a. Quotes say unassigned empty")
End If
''Technique B
'''''''''''''
If s&"" = "" Then
Response.Write("<br>1b. Quotes say unassigned empty")
End If
''Technique C
'''''''''''''
If Len(s) = 0 Then
Response.Write("<br>1c. Len says unassigned is empty")
End If
''Technique D
'''''''''''''
If Len(s&"") = 0 Then
Response.Write("<br>1d. Len with &'' says unassigned is empty")
End If
''''''''''''''''''''''
''' 2. Null value. '''
''''''''''''''''''''''
s = Null
''Technique A
'''''''''''''
If s = "" Then
Response.Write("<br>2a. Quotes say null is empty") ''Fails!!!
End If
''Technique B
'''''''''''''
If s&"" = "" Then
Response.Write("<br>2b. Quotes with &'' say null is empty")
End If
''Technique C
'''''''''''''
If Len(s) = 0 Then
Response.Write("<br>2c. Len says null is empty") ''Fails!!!
End If
''Technique D
'''''''''''''
If Len(s&"") = 0 Then
Response.Write("<br>2d. Len with &'' says null is empty")
End If
''''''''''''''''''''
''' 3. "" value. '''
''''''''''''''''''''
s = ""
''Technique A
'''''''''''''
If s = "" Then
Response.Write("<br>3a. Quotes say '' is empty") ''Fails!!!
End If
''Technique B
'''''''''''''
If s&"" = "" Then
Response.Write("<br>3b. Quotes with &'' say '' is empty")
End If
''Technique C
'''''''''''''
If Len(s) = 0 Then
Response.Write("<br>3c. Len says '' is empty") ''Fails!!!
End If
''Technique D
'''''''''''''
If Len(s&"") = 0 Then
Response.Write("<br>3d. Len with &'' says '' is empty")
End If
''vbNullString is the code version of ""
''''''''''''''''''''''''''''''''''''''''
If Len(s&vbNullString) = 0 Then
Response.Write("<br>Using vbNullString also works!")
End If
%>
</body>
</html>