我正在做遗留应用程序的一些工作,而我的VB6技能并不是那么好.我需要检查String字段是否已初始化并设置为null/nothing或空字符串以外的其他字符串.在C#中,我只是做了类似的事情:
if (string.IsNullOrEmpty(myObj.Str))
Run Code Online (Sandbox Code Playgroud)
我不确定在VB6中它的等价物是什么,而且我对使用If myObj.Str = ""它并将其称为好而感到紧张.这样做的正确方法是什么?
为了澄清,如果满足以下任何条件,我希望返回True:
该字段最初为Long,我正在替换的代码检查它是否设置为0.
Mar*_*rkJ 41
VB6的设计很简单
使用
If str = "" Then
' uninitialised, null or empty ""
Run Code Online (Sandbox Code Playgroud)
War*_*Rox 11
满足您的3个要求的最优化和安全的方法如下:
If LenB(myObj.Str) = 0
Then Debug.Print "String is empty/null/not initialized"
Else Debug.Print "Not Empty"
Run Code Online (Sandbox Code Playgroud)