- 帖子
- 132
- 主題
- 56
- 精華
- 0
- 積分
- 190
- 點名
- 0
- 作業系統
- Win10
- 軟體版本
- Office 365
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-5-17
- 最後登錄
- 2025-4-8
|
要確認某一陣列是否存在時該用什麼方法判斷?
ReDim HeadSone(20)
t1 = 0
t2 = 0
j = 0
For fsi = 15 To 238
If Cells(fsi, 5) = Cells(fsi + 1, 5) And Cells(fsi, 5) <> Cells(fsi - 1, 5) Then t1 = fsi
If Cells(fsi, 5) = Cells(fsi - 1, 5) And Cells(fsi, 5) <> Cells(fsi + 1, 5) Then t2 = fsi
If t1 <> 0 And t2 <> 0 Then
Set HeadSone(j) = Range(Cells(t1, 5), Cells(t2, 5))
HS_S(j) = t1
HS_E(j) = t2
j = j + 1
t1 = 0
t2 = 0
End If
Next fsi
m = j - 1 '共有m-1組
If HeadSone(0) = Empty Then '判斷HeadSone(0)是否存在
m = 0
Else
m = j - 1 '共有m-1組
End If
ReDim Preserve HeadSone(m)
當HeadSone(0)不存在時上述寫法OK,可是當HeadSone(0)不存在時上述寫法就會出現錯誤(型態不符合)
改成:
If HeadSone(0) = Is Nothing Then
m = 0
Else
m = j - 1 '共有m-1組
End If
當HeadSone(0)不存在時則會出現錯誤(此次需要物件),可是當HeadSone(0)不存在時該寫法就OK
請問Is Nothing與Empty的用法有何不同?該如何改? |
|