none
convert single value to one decimal and allow value not more than 99999

    Question

  •  

    i want that text box allow value not more than 99999 and 

    i want if i type in text box 9 then it convert to 9.0

    following code i try, for in put number only its work fine,

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged

    TextBox5.Text = Format(Convert.ToSingle(TextBox5.Text), "#.#") this line not work
            If TextBox5.Text = "" Then
                GoTo ex
            Else
                If IsNumeric(TextBox5.Text) Then
                    GoTo ex
                Else
                    MsgBox("Please Input The Numbers Only !", vbCritical)
                    TextBox5.Text = ""
                    searchback()
                End If
            End If
    ex:
            Exit Sub
        End Sub

     
    Wednesday, November 27, 2013 2:02 PM

Answers

  • Hope this helps as start..
      Dim input As Int32
            If Not Int32.TryParse(TextBox5.Text, input) Then
                MsgBox("Please Input The Numbers Only !", vbCritical)
            Else
                If input > 99999 Then
                    MsgBox("Input should be less than 99999", vbCritical)
                Else
                    ' one digit decimal
                    TextBox5.Text = String.Format("{0:F1}", input)
                    'Do your work
    
                End If
            End If

    Wednesday, November 27, 2013 2:36 PM
  • Hi,

    >>Please Input The Numbers Only

    Because every you input first char,the TextChanged events will fired twice.

    As Venkat786 said ,  and I just slight modificate code like below:

            Dim input As Int32
            input = TextBox1.Text
            If Not IsNumeric(input) Then
                MsgBox("Please Input The Numbers Only !", vbCritical)
            Else
                If input > 99999 Then
                    MsgBox("Input should be less than 99999", vbCritical)
                Else
                    ' one digit decimal
                    TextBox1.Text = String.Format("{0:F1}", input)
                    'Do your work
    
                End If
            End If
    Reagrds,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 28, 2013 9:41 AM

All replies

  • Hope this helps as start..
      Dim input As Int32
            If Not Int32.TryParse(TextBox5.Text, input) Then
                MsgBox("Please Input The Numbers Only !", vbCritical)
            Else
                If input > 99999 Then
                    MsgBox("Input should be less than 99999", vbCritical)
                Else
                    ' one digit decimal
                    TextBox5.Text = String.Format("{0:F1}", input)
                    'Do your work
    
                End If
            End If

    Wednesday, November 27, 2013 2:36 PM
  • it in not working

    i replace my code with your code 

    when i type number value in text box and press any key on key board  then it show msgbox -

    Please Input The Numbers Only

    Thursday, November 28, 2013 5:35 AM
  • Hi,

    >>Please Input The Numbers Only

    Because every you input first char,the TextChanged events will fired twice.

    As Venkat786 said ,  and I just slight modificate code like below:

            Dim input As Int32
            input = TextBox1.Text
            If Not IsNumeric(input) Then
                MsgBox("Please Input The Numbers Only !", vbCritical)
            Else
                If input > 99999 Then
                    MsgBox("Input should be less than 99999", vbCritical)
                Else
                    ' one digit decimal
                    TextBox1.Text = String.Format("{0:F1}", input)
                    'Do your work
    
                End If
            End If
    Reagrds,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 28, 2013 9:41 AM