H
Herfried K. Wagner [MVP]
Larry,
'CLng' can throw an exception too when the parsed number does not fit into
the 'Long' datatype...
;-)
Larry Serflaten said:Well, I know that, but what are the alternatives in this particular case,
as
long as there is no 'Int32.TryParse'? OK, maybe we could utilize
'Double.TryParse' or regular expressions + range check, but this is IMO
far
too complicated to implement and should be possible out of the box (which
is
the case for .NET 2.0).
Too complicated? Since when has writting user interface code been a
breeze ???
<g>
[...]
A more robust solution would be:
Dim user As String
Dim value As Integer
Do
user = InputBox("Enter a number")
If user.Length = 0 OrElse user Like "*[!0-9]*" Then
MsgBox("A numeric value is required to continue.")
Else
If user.Length < 11 _
AndAlso CLng(user) <= Integer.MaxValue _
AndAlso CLng(user) >= Integer.MinValue Then
value = CInt(user)
Exit Do
Else
MsgBox("Please enter a whole number between " _
& Integer.MinValue & " and " &
Integer.MaxValue)
End If
End If
Loop
'CLng' can throw an exception too when the parsed number does not fit into
the 'Long' datatype...
;-)
Basically looks