0

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.

5
  • try this String.IsNullOrEmpty(qry_pkv); Commented Jun 30, 2016 at 10:30
  • im getting an error. Wrong number of arguments or invalid property assignment: 'String' Commented Jun 30, 2016 at 11:06
  • 3
    But qry_pkv is your sql statement, how can it be null. I think what you need to check if if the recordset is empty or not. If Not rs.EOF Then Commented Jun 30, 2016 at 11:16
  • 1
    @SearchAndResQ that seems to be working. Thank u very much. Commented Jun 30, 2016 at 11:21
  • "AND (PATH301 LIKE '%\pkv_dav\%') OR (PATH301 LIKE '%\PKV_DAV\%');" are the same if collation is case-insensitive or should be "AND (PATH301 LIKE '%\pkv_dav\%' OR PATH301 LIKE '%\PKV_DAV\%');" if case-sensitive. Remove OR part or you will have (cond1 and cond2 and cond3) or cond3 Commented Jul 5, 2016 at 4:59

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

  • Use the function IsNull to check for Null values.
  • Use the function 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.
  • Use regular comparison operators to check for empty strings.

In your case you probably want something like this:

If qry_pkv <> "" Then
  ...
Else
  ...
End If

2 Comments

Thanks for your answer! qry_pk <> "" was my first idea too. But im getting the error "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. The Error is reffering to the line with the rs.MoveFirst command. The Source is ADODB.Recordset.
Use WScript.Echo TypeName(qry_pkv) to determine the actual type of the variable qry_pkv. It's either not a string, or it's not empty and your DB query didn't return results.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.