Results 1 to 6 of 6

Thread: IsNaN in VB help

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    IsNaN in VB help

    i have a text box called write.text

    when someone inputs a alphabet letter i need a pop up box to appear

    If IsNaN write.text Then
    Console.WriteLine("please input numbers only")
    Else
    End If

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: IsNaN in VB help

    In the TextChanged event you could use the TryParse event:
    Code:
    If Not Integer.TryParse(write.Text, Nothing) Then
        MessageBox.Show("Please input numbers only.")
    End If
    Alternatively you could use a NumericUpDown control instead.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    Re: IsNaN in VB help

    how would you do it if i put

    Dim write As Decimal
    write = write.Text
    If Not Decimal.TryParse(write, Nothing) Then
    msg(hi)

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: IsNaN in VB help

    Quote Originally Posted by philbob View Post
    how would you do it if i put

    Dim write As Decimal
    write = write.Text
    If Not Decimal.TryParse(write, Nothing) Then
    msg(hi)
    What does the documentation say about Decimal.TryParse? It tells you how to use it.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: IsNaN in VB help

    If your only wanting them to input numbers then you could just do away with the ability to use letters and special characters.

    This will make the write.text only be allowed to have digits 0-9 and , .
    vb.net Code:
    1. Private Sub write_TextChanged(sender As Object, e As EventArgs) Handles write.TextChanged
    2.         write.Text = System.Text.RegularExpressions.Regex.Replace(write.Text, "[A-Za-z/w]", "")
    3.         If Not Double.TryParse(write.Text, Nothing) AndAlso write.Text.Length <> 0 Then
    4.             write.Text = write.Text.Substring(0, write.Text.Length - 1)
    5.         End If
    6.         write.Select(write.Text.Length, 0)
    7.     End Sub

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: IsNaN in VB help

    You should really be using a NumericUpDown control, which would prevent the problem entirely.
    My usual boring signature: Nothing

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