Dim HHs As String
HHs = Mid("2345", 1, 2)
If Val(HHs) > 23 Then
"Log the Error that needs to be logged"
End If
上述代碼未通過驗證。 這似乎是一個非常簡單的問題 任何想法爲什麼?在VB6中使用Val()函數進行比較失敗?
Dim HHs As String
HHs = Mid("2345", 1, 2)
If Val(HHs) > 23 Then
"Log the Error that needs to be logged"
End If
上述代碼未通過驗證。 這似乎是一個非常簡單的問題 任何想法爲什麼?在VB6中使用Val()函數進行比較失敗?
如果HHs
尚未聲明(和你沒有使用Option Explicit
),或者你還沒有分配一個值HHs
,然後Val(HHs)
永遠是0
....
因此,Val(HHs) > 23
將永遠是False
。
看起來你可能犯了一個錯字,並打算使用HHe
?
嘿是的,這是一個打字錯誤。我編輯了這個問題。 – rohit
的代碼按預期方式工作:如果條件爲假,因爲纈氨酸(HHS)爲23。
Option Explicit
Private Sub CommandTest_Click()
Dim HHs As String
HHs = Mid("2345", 1, 2)
If Val(HHs) > 23 Then
MsgBox "Log the Error that needs to be logged"
End If
End Sub
哪裏'MMs'分配??? –
'HHe'與'HHs'不同 - **總是**使用'Option Explicit',你將避免99次出現這些錯誤。 – ThunderFrame
'「記錄需要記錄的錯誤」 '不是一個有效的陳述。你可能是指'Debug.Print「記錄需要記錄的錯誤」'或者''記錄需要記錄的錯誤'? – ThunderFrame