Results 1 to 5 of 5

Thread: NaN

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    11

    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???

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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:
    1. Option Strict On ' Put this at the top top top top top part of the code, not in a subrutine
    2.  
    3. ' in a sub:
    4. dim n,m,p, as double
    5. try
    6.     n = cdbl(textbox.text)
    7.     m = cdbl(textbox2.text)
    8.     p = m-n
    9. catch
    10. ' probably an invalid character was entered... handle the exception here
    11. 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!!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    11
    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...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    11

    Wink

    hey it's okay

    ElseIf Not IsNumeric(Booked.Text) Then
    MsgBox("Entry must be numeric")

    all i did was this...hehe..

  5. #5
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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
  •  



Click Here to Expand Forum to Full Width