-
Dec 1st, 2016, 01:42 PM
#1
Thread Starter
New Member
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
-
Dec 1st, 2016, 01:44 PM
#2
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.
-
Dec 1st, 2016, 02:49 PM
#3
Thread Starter
New Member
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)
-
Dec 1st, 2016, 03:57 PM
#4
Re: IsNaN in VB help
Originally Posted by philbob
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."
-
Dec 1st, 2016, 03:58 PM
#5
Hyperactive Member
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:
Private Sub write_TextChanged(sender As Object, e As EventArgs) Handles write.TextChanged write.Text = System.Text.RegularExpressions.Regex.Replace(write.Text, "[A-Za-z/w]", "") If Not Double.TryParse(write.Text, Nothing) AndAlso write.Text.Length <> 0 Then write.Text = write.Text.Substring(0, write.Text.Length - 1) End If write.Select(write.Text.Length, 0) End Sub
-
Dec 1st, 2016, 04:07 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|