|
-
Jun 23rd, 2004, 11:49 AM
#1
Thread Starter
Addicted Member
IsNumeric [RESOLVED]
There is a way to verify that the contents of the text box are indeed numbers before putting them into variables. I know it's a function called IsNumeric. Can anyone post a code example on how to use it??
Last edited by twisted; Jun 23rd, 2004 at 12:13 PM.
Twisted
-
Jun 23rd, 2004, 11:54 AM
#2
VB Code:
Dim x As Double
If IsNumeric(TextBox1.Text) Then
x = TextBox1.Text
MsgBox(x)
End If
-
Jun 23rd, 2004, 11:57 AM
#3
Frenzied Member
VB Code:
Imports Microsoft.VisualBasic.Information
Dim num1 As Integer = 10
If IsNumeric(num1) Then
'It is numeric
Else
'It is not numeric
End If
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jun 23rd, 2004, 12:13 PM
#4
Thread Starter
Addicted Member
Thanks!
-
Jun 23rd, 2004, 12:28 PM
#5
Sleep mode
This is the .NET WAY :
VB Code:
Try
Dim int As Integer = Integer.Parse(Me.TextBox1.Text)
Catch x As Exception
MessageBox.Show("Please input numeric value")
End Try
-
Jun 28th, 2004, 03:36 PM
#6
-
Jun 28th, 2004, 03:51 PM
#7
Lively Member
I don't recommend using Pirate's way.
Try...Catch...End Try statement is used for watching a specific are of code for throwing an exception, in other words for identifying exceptions and responding to them, not for such small type situations. I recommend using the VB.Net's built is IsNumeric function, using such function saves time and lines.
You may not find this a big problem, but what will you do if you have a program under development? where you type handreds of lines daily?
I recommend also using Try...Catch...End Try statement for covering a whole subroutine and catching specific errors and exceptions.
Last edited by TLord; Jun 28th, 2004 at 03:57 PM.
Do you think my life is easy?
Do you think it's good to win?
do you think it's nice to kill?
Do you think learning is a must?
Do you think computers are nothing?
Do you think this post is stupid?
Do ypu think we're really humen?
DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !
-
Jul 5th, 2004, 04:43 AM
#8
Sleep mode
Originally posted by TLord
I don't recommend using Pirate's way.
Try...Catch...End Try statement is used for watching a specific are of code for throwing an exception, in other words for identifying exceptions and responding to them, not for such small type situations. I recommend using the VB.Net's built is IsNumeric function, using such function saves time and lines.
You may not find this a big problem, but what will you do if you have a program under development? where you type handreds of lines daily?
I recommend also using Try...Catch...End Try statement for covering a whole subroutine and catching specific errors and exceptions.
IsNumeric is not pure .NET function . It's only for compatibilitiy issues . Everybody expect that MS will stop supporting this class (Microsoft.VisualBasic) in the future releases . As for the the Parse method it's the only pure code that does the job ! There's no problem with Try...Catch block as long as the conversion is applicable . I always use this way and it's been working great . Never fail me !
look at VIP's replies
-
Jul 5th, 2004, 05:13 AM
#9
PowerPoster
Originally posted by Negative0
VB Code:
Dim x As Double
If IsNumeric(TextBox1.Text) Then
x = TextBox1.Text
MsgBox(x)
End If
This is a hangover from VB6. It will not work in .NET unless Option Strict is OFF. You would have to use
x=val(TextBox1.Text) or x=cdbl(TextBox1.Text)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|