|
-
Sep 28th, 2003, 01:53 PM
#1
Thread Starter
New Member
textbox to integer or double etc...
Hi!
I am having this problem.
I have some textboxes that I want to have converted to a numeric value (as standard they are string)
how can I change that, so that they are fx double as standard?
Snorri
-
Sep 28th, 2003, 01:57 PM
#2
Addicted Member
this will give you an integer
dim num as integer
if isnumeric(textbox1.text) then num=integer.parse(textbox1.text)
-
Sep 28th, 2003, 02:12 PM
#3
Sleep mode
Try this :
VB Code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
If System.Char.IsNumber(TextBox1.Text, 0) = True Then
TextBox1.Text = CType(TextBox1.Text, Integer)
Else
TextBox1.Text = 0
End If
End Sub
-
Sep 28th, 2003, 02:21 PM
#4
Addicted Member
i think its better to use my code, in pirates code an exeption will b e thrown if textbox1.text="9thentext", and why did you put it in TEXTCHANGED?
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim mynum As Integer
If IsNumeric(TextBox1.Text) Then
mynum = Integer.Parse(TextBox1.Text)
Else
MsgBox("You must enter a numeric value for X ")
TextBox1.Focus()
End If
End Sub
-
Sep 28th, 2003, 04:51 PM
#5
Sleep mode
Originally posted by persianboy
i think its better to use my code, in pirates code an exeption will b e thrown if textbox1.text="9thentext"
True but I assumed he would do the part of diabling letter keys . Basically , it's quick one and just hint ......
and why did you put it in TEXTCHANGED?
That would validate and Change values intered immediately .
VB Code:
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim mynum As Integer
If IsNumeric(TextBox1.Text) Then
mynum = Integer.Parse(TextBox1.Text)
Else
MsgBox("You must enter a numeric value for X ")
TextBox1.Focus()
End If
End Sub
I've not tested it but even if it's working , you didn't make use of Convert class which is apparenly created for .
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
|