Results 1 to 8 of 8

Thread: Equation Help ::: How to Concatenate a Equation and Answer to text Box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Question Equation Help ::: How to Concatenate a Equation and Answer to text Box

    Hello Everyone,

    In our school theres a programming class and the teachers gone for the week and the sub is starting to get very frustrated, so I offered to help in any way i can. I have never programmed Visual Basic but I have programmed Ms-Dos, Javascript, HTML, *.vbs, *.ahk, *.gml, and a variety of other languages.

    The class is going to build a program that calculate how many rabbits are born in a family. So when they click the button it shows in a text box the actual equation and then the answer after the equal sign that where i assume concatenation comes in.

    Here's the code I've thrown together for when the buttons pressed:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim RabitAmount As Integer
            Dim ShowEquation As String
    
            RabitAmount = TextBox1.Text
            ShowEquation = "Textbox1.text * 4 = "
            TextBox2.Text = ShowEquation
            TextBox2.Text = ((RabitAmount) * 4)
    
        End Sub
    End Class
    I got the equation to answer it self and show in the text box but it won't show the equation before hand can you please let me know what i'm doing wrong and how to fix it?

    Thanks,

    -PsycoZL

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    vb Code:
    1. RabitAmount = cint(TextBox1.Text)
    2. ShowEquation = RabitAmount.tostring  & " * 4 = "
    3. TextBox2.Text = ShowEquation
    4. TextBox2.Text &= " = " & ((RabitAmount) * 4).tostring

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    Ok I fixed some of it Heres the new code:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim RabitAmount As Integer
            Dim ShowEquation As String
    
            RabitAmount = TextBox1.Text
            ShowEquation = TextBox1.Text & " * 4 = "
    
            TextBox2.Text = ShowEquation & (RabitAmount * 4)
    
    
    
        End Sub
    End Class
    Is there a way to not overwrite the data entered into textbox2?

    Also is there a simpler way of doing this?

    Thanks,

    -PsycoZL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    Oh cool thanks for the quick reply I didn't see this i was typing out other reply thanks.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    By the way, CInt will throw an exception if you enter anything that is not an integer. Integer.TryParse would be the safer way to go, but whether or not you want to go there depends on where the class is at.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Smile Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    So what if you wanted to reverse i and allow only letters and no numbers? Also is there a way to prevent the overwriting of the data sent to textbox2? Because every time the the buttons pressed the old data disappears and the new appears I want them both there old below the new.

    Thanks,

    -PsycoZL

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    TextBox2.Text &= environment.newline & ShowEquation & (RabitAmount * 4)

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Talking Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box

    This is great thank you guys for all your help I really appreciate it!!!

    Thanks,

    PsycoZL

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