2 ms·
You do end up with some interesting approaches to error handling with that, e.g. from a sprite editor[0] i wrote a few years ago in VB5 (later ported to VB6) fo
by badsectoracula 4y ago
You do end up with some interesting approaches to error handling with that, e.g. from a sprite editor[0] i wrote a few years ago in VB5 (later ported to VB6) for fun:
Private Sub cmdOk_Click()
On Error Resume Next
WInt = 0
HInt = 0
WInt = CInt(txtWidth.Text)
HInt = CInt(txtHeight.Text)
If CStr(WInt) <> txtWidth.Text Or CStr(HInt) <> txtHeight.Text Then
MsgBox "Invalid numeric values for the dimensions"
txtWidth.SetFocus
Exit Sub
End If
Tag = vbOK
Hide
End Sub
This basically asks for a width and height but the entry boxes are text so anything could be entered there. CInt tries to convert text to integer and if that fails it errors out. With 'On Error Resume Next' it moves on to the next if that fails instead of producing an error and WInt or HInt would remain whatever it was. Since they're initialized to 0 there are always some valid integers in there. CStr would convert the integer to string (0 if the string-to-integer failed) so that the assumption is that if the strings converted to integers and then converted back to strings weren't the same as the original strings there were some invalid characters in there.
(in hindsight i should have also checked for negatives values but eh whatever)
[0] http://runtimelegend.com/tools/mseditor/ http://runtimelegend.com/tools/mseditor/