|
-
Mar 22nd, 2011, 12:58 PM
#1
Thread Starter
Junior Member
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
-
Mar 22nd, 2011, 01:14 PM
#2
Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box
vb Code:
RabitAmount = cint(TextBox1.Text)
ShowEquation = RabitAmount.tostring & " * 4 = "
TextBox2.Text = ShowEquation
TextBox2.Text &= " = " & ((RabitAmount) * 4).tostring
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 22nd, 2011, 01:19 PM
#3
Thread Starter
Junior Member
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
-
Mar 22nd, 2011, 01:20 PM
#4
Thread Starter
Junior Member
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.
-
Mar 22nd, 2011, 01:27 PM
#5
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
 
-
Mar 22nd, 2011, 01:54 PM
#6
Thread Starter
Junior Member
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
-
Mar 22nd, 2011, 01:57 PM
#7
Re: Equation Help ::: How to Concatenate a Equation and Answer to text Box
TextBox2.Text &= environment.newline & ShowEquation & (RabitAmount * 4)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 22nd, 2011, 05:55 PM
#8
Thread Starter
Junior Member
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
|