| View previous topic :: View next topic |
| Author |
Message |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Wed Apr 30, 2008 10:28 pm Post subject: [VB]Value of?... |
|
|
| Sorry for such a newbie question but, how would you input the state "value of" (if it even exist). I want to have the value of textbox1 and textbox2 added together. Is that possible? Thanks in advance.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Wed Apr 30, 2008 10:52 pm Post subject: |
|
|
you mine adding the text of two textboxes
if they contain strings just do
| Code: | | String = TextBox1.text + TextBox2.text |
if they have only numbers
| Code: | | Numbers = StrToInt(TextBox1.text) + StrToIntTextBox2.text |
_________________
|
|
| Back to top |
|
 |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Wed Apr 30, 2008 10:55 pm Post subject: |
|
|
| Ah dang forgot to mention that I want the value of textbox1 + textbox2 to be inputted into textbox3. And yeah I'm only dealing with numbers right now.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Wed Apr 30, 2008 11:36 pm Post subject: |
|
|
thats easy then
TextBox3.text = TextBox1.text + TextBox2.text
_________________
|
|
| Back to top |
|
 |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Thu May 01, 2008 5:13 pm Post subject: |
|
|
| Snootae wrote: | thats easy then
TextBox3.text = TextBox1.text + TextBox2.text |
Thanks for the reply, I tried that first thing I did and nothing shows up in the 3rd textbox.
This is what I have so fare.
| Code: | Public Class Form1
Dim Y As Integer
Dim X As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
X = 100
TextBox1.Text = X
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Y = 200
TextBox2.Text = Y
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
TextBox3.Text = TextBox1.Text + TextBox2.Text
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class |
Edit1: Hmm It seems that just adding a button solved everything so now I just have to click the button to see the numbers show up but I have a new problem now. It shows up as 100200 where its supposed to be 300. the two text box's are 100 and 200. Any ideas?
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 6:09 pm Post subject: |
|
|
when you add 2 test strings, "text1" and "text2", it'll do "text1text2". You want to add them as ints.
[code]
textbox1.text = IntToStr(StrToInt(textbox1.text)+StrToInt(textbox1.text))
[code]
I don't do vb, so I don't know if the inttostr is necessary.
Also, the reason textbox3 is blank is probably because you don't set it to text1+text2 after you get the input. (Until you put in the button.)
_________________
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Thu May 01, 2008 7:29 pm Post subject: |
|
|
it maybe a good idea to store the textboxes as you x and y values so:
| Code: | X = StrToInt(TextBox1.text)
Y = StrToInt(TextBox2.text) |
then
| Code: | | TextBox3.text = IntToStr(X + Y) |
if not then
| Code: | | TextBox3.text = IntToStr( StrToInt(TextBox1.text) + StrToInt(TextBox2.text) ) |
also, i think i know why your code didn't work, because you tried to add a click handler to your textbox, but vb makes it into TextChanged, try typing i 1 in that box and it should change to 300
_________________
|
|
| Back to top |
|
 |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Thu May 01, 2008 7:54 pm Post subject: |
|
|
| IntToStr is not declared, what is it suppose to be? Dim IntToStr As integer?
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu May 01, 2008 8:15 pm Post subject: |
|
|
| raidos wrote: | | IntToStr is not declared, what is it suppose to be? Dim IntToStr As integer? |
use Convert.ToString and Convert.ToInt32
_________________
|
|
| Back to top |
|
 |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Thu May 01, 2008 8:47 pm Post subject: |
|
|
| Code: | Public Class Form1
Dim Sum As String
Dim Y As Integer
Dim X As Integer
Private Sub Main(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
X = Convert.ToInt32(TextBox1.text)
Y = Convert.ToInt32(TextBox2.text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = 100
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = 200
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
TextBox3.Text = Convert.ToString(X + Y)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox3.Text = Convert.ToString(X + Y)
End Sub
End Class |
My new code. When I try to run it, it gives me this error "Input string was not in correct format". at X = Convert.ToInt32(TextBox1.text)
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu May 01, 2008 8:58 pm Post subject: |
|
|
Um... woudn't you want to get the values AFTER everythings inputted?
like have button_3 get the X and Y value... even better you could have it all in one line
TextBox3.Text = Convert.ToString(Convert.ToInt32(TextBox1.text) + Convert.ToInt32(TextBox2.text))
If that doesnt work try
Convert.ToSingle
_________________
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 9:01 pm Post subject: |
|
|
Did you try it without inttostr?
_________________
|
|
| Back to top |
|
 |
raidos Advanced Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 91
|
Posted: Thu May 01, 2008 9:15 pm Post subject: |
|
|
Yeah my above code does not have any inttostr in it.
Edit: Holy all I had to do was remove
X = Convert.ToInt32(TextBox1.Text)
Y = Convert.ToInt32(TextBox2.Text)
Thanks a lot guys with all the help.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu May 01, 2008 10:07 pm Post subject: |
|
|
| The .NET version of VB usually tries to do the type conversion on it's own if I remember right...
|
|
| Back to top |
|
 |
|