hi
how to i make an expection when the user input a char??
example
dim n,m,p as Double
n=textbox.text
m=textbox2.text
p= m-n
etc...i know it's NaN but how to declare or write them???
Printable View
hi
how to i make an expection when the user input a char??
example
dim n,m,p as Double
n=textbox.text
m=textbox2.text
p= m-n
etc...i know it's NaN but how to declare or write them???
what you are doing would give you an errror anyways (if you have option strict on, which you should)Quote:
Originally posted by kryton
hi
how to i make an expection when the user input a char??
example
dim n,m,p as Double
n=textbox.text
m=textbox2.text
p= m-n
etc...i know it's NaN but how to declare or write them???
VB Code:
Option Strict On ' Put this at the top top top top top part of the code, not in a subrutine ' in a sub: dim n,m,p, as double try n = cdbl(textbox.text) m = cdbl(textbox2.text) p = m-n catch ' probably an invalid character was entered... handle the exception here end try
I dont know what you want to do with Nan? I think a NaN is "not a number"? I cant remember. It's basically something undefined. I think if you set your variable to something/0, it's gunno be nan.
i wanted the program to be able to catch is the user input a char instead of a number..
like if the program asked the user to input age and he/she input "abc", it will appear a msgbox to tell the user to input a number...
hey it's okay
ElseIf Not IsNumeric(Booked.Text) Then
MsgBox("Entry must be numeric")
all i did was this...hehe..
One solution might be not to catch anything but to prevent the user from being able to type text. I made my own "NumberBox" for this, maybe it might be useful for someone. :)
When a character is pressed nothing happens, but if a number och backspace is pressed it works as anormal textbox.Code:<System.Drawing.ToolboxBitmap(GetType(System.Windows.Forms.TextBox))> _
Public Class NumberBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Not Char.IsNumber(e.KeyChar) AndAlso Not (Strings.Asc(e.KeyChar) = 8) Then
e.Handled = True
End If
End Sub
End Class