|
Thread: NaN
-
Feb 5th, 2003, 09:27 PM
#1
Thread Starter
New Member
NaN
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???
-
Feb 5th, 2003, 09:59 PM
#2
Re: NaN
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???
what you are doing would give you an errror anyways (if you have option strict on, which you should)
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.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 5th, 2003, 10:07 PM
#3
Thread Starter
New Member
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...
-
Feb 5th, 2003, 10:18 PM
#4
Thread Starter
New Member
hey it's okay
ElseIf Not IsNumeric(Booked.Text) Then
MsgBox("Entry must be numeric")
all i did was this...hehe..
-
Feb 7th, 2003, 03:41 AM
#5
Registered User
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. 
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
When a character is pressed nothing happens, but if a number och backspace is pressed it works as anormal textbox.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|