How can I read an INTEGER VALUE from text box - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can I read an INTEGER VALUE from text box

HyBRiD_HeLLHyBRiD_HeLL Posts: 7Member
How can I read an INTEGER VALUE from text box and process it through command button?

Comments

  • Xtreme.NETXtreme.NET Posts: 112Member
    you can get the value and convert it to a string using the Convert class
    HTH...

    [size=1][COLOR=blue]"Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."[i]1Thess. 5:16-18[/i][/color][/size]

  • eaglemaneagleman Posts: 28Member
    : How can I read an INTEGER VALUE from text box and process it through command button?
    :

    If you want to convert numbers in a textbox to an integer you could use this

    [code]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Replace invalid characters with empty strings.
    ' Put invalid characters between []
    Me.TextBox1.Text = System.Text.RegularExpressions.Regex.Replace(Me.TextBox1.Text, "[a-zA-Z.<>@ -+]", "")
    Dim myint As Integer
    Try
    myint = CInt(Me.TextBox1.Text)
    Catch ex As Exception
    MsgBox(ex.Message, , )
    End Try
    End Sub
    [/code]

    Hope this helps
    //eagleman
  • HyBRiD_HeLLHyBRiD_HeLL Posts: 7Member
    At first i want to thanx u for the help and the lost time BUT i need sth else I need from a textbox1.text = "SOME VALUE" and when i will click on the cmd button for ex:to read the value from the textbox1.text and intAdd = text1box.text + text2.text(FOR INTEGER VALUE)

    ex:texbox1.text = "2"
    textbox2.text = "3"

    when cmd clicked 2+3 = 5





  • Xtreme.NETXtreme.NET Posts: 112Member
    if you are trying to learn VB.NET from scratch in a messageboard. Let me tell you that its a big mistake. Perhaps you should grab a book and read and practice. Or perhaps you can download some info and examples on vb.NET and practice with it.
    If you ask these kind of questions here, the rate at which you get replies is a total waste of your time. You can achieve much more by putting some effort.

    Anywho,
    If you have configured you textbox to take it only numbers, then all you have to do is to get those values and simply add it
    smth = (Convert.ToInt32(textbox1.text) + Convert.ToInt32(textbox2.text))
    If you have not, you need to put some validations and then perform the same task.
    HTH....

    [size=1][COLOR=blue]"Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."[i]1Thess. 5:16-18[/i][/color][/size]

  • sachin007sachin007 Posts: 1Member
    : How can I read an INTEGER VALUE from text box and process it through command button?
    : It's very easy
    for example y have a textbox1 with integer value 420
    then u can read this value in a variable say var as
    var = val(textbox1.text)

    here val is a function that returns the integer value of a string.


Sign In or Register to comment.