Reputation: 461
I want to know how it is possible to check for an empty string.
I created a SQL statement which selects some datas in my database.
qry_pkv = "SELECT DISTINCT MANDT, PATH301 FROM NC301B " & _
"WHERE EDIPROC like 'P30_'" & _
"AND (LF301M > 0) " & _
"AND (PATH301 LIKE '%\pkv_dav\%') " & _
"OR (PATH301 LIKE '%\PKV_DAV\%');"
The statement works great but I don't know how to check if there is any value inside of qry_pkv
.
rs.open qry_pkv, cn, 3
Zeile = "Skriptausfuehrung wird gestartet."
Call Trace (3, "I", Zeile)
If qry_pkv <> Null Then
rs.MoveFirst
ReDim Preserve AusgabeDir_pkv(0)
i = 0
Zeile = "PKV_DAV Verzeichnisse" 'Überschrift für LOG-Datei.
Call Trace (3, "@", Zeile) 'Überschrift wird in LOG-Datei geschrieben.
Do While Not rs.EOF 'Schleife für durchsuchen der Datenbank.
ReDim Preserve AusgabeDir_pkv(i)
ReDim Preserve MANDT_pkv(i)
AusgabeDir_pkv(i) = rs("DIRIN") 'Ausgabeverzeichnis wird in Variable gespeichert und verarbeitet.
MANDT_pkv(i) = rs("MANDT")
Zeile = "Verzeichnis in Bearbeitung: " & "MDT " & MANDT_pkv(i) & " PFAD " & AusgabeDir_pkv(i) 'Status der Verarbeitung.
Call Writelog (Zeile) 'Status wird in LOG-Datei geschrieben.
' call loeschen_gio(AusgabeDir_gio(i)) 'Funktion löschen wird aufgerufen um Verzeichnis zu leeren wenn älter n Tage.
i = i+1
rs.MoveNext
Loop
Else
Zeile = "PKV_DAV Verzeichnisse" 'Ergebnis wird in LOG-Datei geschrieben.
Call Trace (3, "@", Zeile) 'Prozedur "WriteLog" wird aufgerufen
Zeile = "Keine PKV_DAV Verzeichnisse vorhanden." 'Ergebnis wird in LOG-Datei geschrieben.
Call Trace (3, "-", Zeile) 'Prozedur "WriteLog" wird aufgerufen
End If
My plan was that the script is jumping to the Else
statement in case of an empty qry_pkv
.
Upvotes: 0
Views: 2185
Reputation: 797
Check the length of the string. if it's <= 0, then you don't have the bolus of content you want in it:
If len(qry_pkv) <= 0 Then
'//...the rest of your code
else
'//...the else
end if
FYI, my habit is to use the three characters '// as my vbscript comment because my eye skips over the ' alone.
see https://msdn.microsoft.com/en-us/library/42byt104(v=vs.84).aspx for more info on the Len() function.
Upvotes: 0
Reputation: 200193
As @SearchAndResQ pointed out qry_pkv
is your query string, so it's unlikely ot be Null
. Check the cursor position in the recordset instead:
If Not rs.EOF Then
...
Else
...
End If
Upvotes: 1
Reputation: 200193
Null
is not the same as Empty
is not the same as ""
(empty string). And a comparison var <> Null
doesn't even work in the first place.
IsNull
to check for Null
values.IsEmpty
to check for Empty
values (mainly uninitialized variables). Comparisons with empty strings also cover Empty
values, so if you want to distinguish between Empty
and ""
you need to test for Empty
values before testing for empty strings.In your case you probably want something like this:
If qry_pkv <> "" Then
...
Else
...
End If
Upvotes: 0