RDC00312: Empty string literal
Severity: Information · Family: RDC (Rubberduck Core analyzers) ·
Raised by: EmptyStringLiteralAnalyzer
The string literal "" is written.
"" and the constant vbNullString (MS-VBAL §6.1.2.2 Constants Module) are both a String of no characters,
and compare equal. vbNullString says so by name, where "" can be mistaken for a missing character or an unfinished literal.
The two differ in one way: StrPtr(vbNullString) is 0, and vbNullString given to a procedure of a DLL (Declare) passes a null pointer, where "" passes the
address of an empty string. An API that tells the two apart needs the one it documents.
The finding is the literal.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
"" in an expression. |
If foo = "" Then |
If foo = vbNullString Then, or If Len(foo) = 0 Then. |
"" as the value of a constant or a default value. |
Optional ByVal bar As String = "" |
Optional ByVal bar As String = vbNullString. |
Quick fix
Where "" is compared (=, <>, <, <=, >, >=, Like) or is a value of a Case clause, the diagnostic comes with a quick fix, Replace "" with
vbNullString. Only the characters are compared there, so the program does the same.
Anywhere else, the String can reach StrPtr or a procedure of a DLL, possibly through a variable, and no quick fix is offered.
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca