Dim HHs As String
HHs = Mid("2345", 1, 2)
If Val(HHs) > 23 Then
"Log the Error that needs to be logged"
End If
The above code is failing in the validation . This seems to be a very simple problem Any idea why?
Dim HHs As String
HHs = Mid("2345", 1, 2)
If Val(HHs) > 23 Then
"Log the Error that needs to be logged"
End If
The above code is failing in the validation . This seems to be a very simple problem Any idea why?
If HHs hasn't been declared (and you haven't used Option Explicit), or you haven't assigned a value to HHs, then Val(HHs) will always be 0....
As such, Val(HHs) > 23 will always be False.
It seems likely you made a typo, and meant to use HHe?
The code works as expected: the if condition is false since Val(HHs) is 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