未初始化的VBScript變量爲Empty
;計算中的空值「count」爲0或「」。見here。
>> Dim e
>> WScript.Echo CStr(IsEmpty(e)), TypeName(e), CStr(e = Empty)
>> WScript.Echo e + 1 + e
>>
True Empty True
1
因此,使用IsEmpty()捕獲空單元格值。
更新WRT評論:
我解決了這個問題
的問題是,當我在「裁判」文件中的「O」值和 「空單元格」在另一個文件中,如果 相同(因爲我已經理解VB的empty = 0,因爲任何 未初始化的變量的值爲0),所以我評論比較的結果。這就是我的代碼不能在「0」值單元格和空白之間做出區別細胞
顯然,這是從
不同,使不同 「0」 之間 「」
對於這一點,只要看看:
type 37673790.vbs
Option Explicit
Dim n : n = 0
Dim s : s = " "
If s = n Then
WScript.Echo "Surprise"
Else
WScript.Echo "Not s = n"
End If
cscript 37673790.vbs
Not s = n
這
>> a = Array(Empty, 0, "", " ")
>> For Each e In a
>> WScript.Echo CStr(IsEmpty(e))
>> Next
>>
True
False
False
False
應停止unbased猜測WRT
的差異不會在環路中可以看出
更新II:
所以它仍然是是否「0比空白單元格是不同的」 ...
我最後一次嘗試:
Option Explicit
Dim a : a = Array(Empty, 0, "", " ")
Dim i, j
For i = 0 To UBound(a)
For j = 0 To UBound(a)
WScript.Echo i, j, Cmp(a(i), a(j))
Next
Next
Function Cmp(a, b)
If VarType(a) <> VarType(b) Then
Cmp = "type diff (" & TypeName(a) & "<->" & TypeName(b) & ")"
Else
If a = b Then
Cmp = "val equal"
Else
Cmp = "val diff (" & Join(Array(a, b), "|") & ")"
End If
End If
End Function
輸出:
cscript 37673790.vbs
0 0 val equal
0 1 type diff (Empty<->Integer)
0 2 type diff (Empty<->String)
0 3 type diff (Empty<->String)
1 0 type diff (Integer<->Empty)
1 1 val equal
1 2 type diff (Integer<->String)
1 3 type diff (Integer<->String)
2 0 type diff (String<->Empty)
2 1 type diff (String<->Integer)
2 2 val equal
2 3 val diff (|)
3 0 type diff (String<->Empty)
3 1 type diff (String<->Integer)
3 2 val diff (|)
3 3 val equal
請問您可以發佈您的代碼嗎? –
http://www9.0zz0.com/2016/06/07/11/782086843.png 謝謝 – bben147