Results 1 to 5 of 5

Thread: textbox to integer or double etc...

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Faroe Islands
    Posts
    15

    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

  2. #2
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    this will give you an integer

    dim num as integer
    if isnumeric(textbox1.text) then num=integer.parse(textbox1.text)

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try this :
    VB Code:
    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
    2. TextBox1.TextChanged
    3.         If System.Char.IsNumber(TextBox1.Text, 0) = True Then
    4.             TextBox1.Text = CType(TextBox1.Text, Integer)
    5.         Else
    6.             TextBox1.Text = 0
    7.         End If
    8.  End Sub

  4. #4
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    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

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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:
    1. Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    2.  
    3.         Dim mynum As Integer
    4.         If IsNumeric(TextBox1.Text) Then
    5.             mynum = Integer.Parse(TextBox1.Text)
    6.         Else
    7.             MsgBox("You must enter a numeric value for X ")
    8.             TextBox1.Focus()
    9.         End If
    10.     End Sub
    VB Code:
    1.  

    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
  •  



Click Here to Expand Forum to Full Width