Redhatcc Posted April 13, 2009 Posted April 13, 2009 very new with the 2008 vb lol... but lets say i have textbox1 textbox2 and textbox3. I type in 2 into textbox1 and 13 into textbox2, and i want it to add them together and post them in textbox3 as 15. How do you do this? Im getting alot of mixed results on google lol
r3incarnat0r Posted April 13, 2009 Posted April 13, 2009 TextBox3.Text = CInt(TextBox1.Text) + CInt(TextBox2.Text)or if you have option strict on:TextBox3.Text = CStr(CInt(TextBox1.Text) + CInt(TextBox2.Text))
gunsmokingman Posted April 13, 2009 Posted April 13, 2009 You will need 3 texboxes and a button for this code to work.Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "Add Numbers" Then Button1.Text = "Clear Numbers" If TextBox1.Text = "" And TextBox2.Text = "" Then MsgBox("Please Fill In TextBox1 And TextBox2") Else Try Dim A As Integer = TextBox1.Text / 1 Dim B As Integer = TextBox2.Text / 1 TextBox3.Text = A + B Catch ex As Exception MsgBox("There Must Be Only Numbers In TextBox1 And TextBox2") End Try End If Else Button1.Text = "Add Numbers" TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End If End SubEnd Class
Redhatcc Posted April 14, 2009 Author Posted April 14, 2009 sorry took a bit of time to get back. what i did was make a timer so that it calculated everything without a button but here is what i did. Public Class Form1 Dim intNum1 As Integer Dim intNum2 As Integer Dim intNum3 As Integerand so on... and so on...Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If TextBox1.Text = "" Then TextBox1.Text = "0" If TextBox2.Text = "" Then TextBox2.Text = "0" If TextBox3.Text = "" Then TextBox3.Text = "0" If TextBox4.Text = "" Then TextBox4.Text = "0"and so on... and so on... intNum7 = TextBox1.Text intNum8 = TextBox2.Text intNum9 = TextBox3.Text intNum10 = TextBox4.Textand so on.... and so on...(reason for that is if you deleted the number 0 out of the textbox before you typed in it the app would crash )TextBox33.Text = intNum1 + intNum2 + intNum3 + intNum4 + intNum5 + intNum6 + intnum25 + intnum26 + intnum27 + intnum28 + intnum29 + intnum30 TextBox34.Text = intNum7 + intNum8 + intNum9 + intNum10 + intNum11 + intNum12 + intNum13 + intNum14 + intNum15 + intNum16 + intNum17 + intNum18 + intNum19 + intNum20 + intNum21 + intNum22 + intNum23 + intNum24and that last code was a part of the math that i needed in the app so just ignore that, that is only for ref to someone that needs help in how it works . hope someone eventually finds this helpfulr3incarnat0r and gunsmokingman thank you both for your help on this issue !
r3incarnat0r Posted April 14, 2009 Posted April 14, 2009 TextBox33.Text = intNum1 + intNum2 + intNum3 + intNum4 + intNum5 + intNum6 + intnum25 + intnum26 + intnum27 + intnum28 + intnum29 + intnum30 TextBox34.Text = intNum7 + intNum8 + intNum9 + intNum10 + intNum11 + intNum12 + intNum13 + intNum14 + intNum15 + intNum16 + intNum17 + intNum18 + intNum19 + intNum20 + intNum21 + intNum22 + intNum23 + intNum24If you need so many variables, you should rather consider to use an array of them imo:Dim tmp(2) As Integer 'array of 3 integers - tmp(0), tmp(1) and tmp(2)Dim ints() As Integer = {2, 4, 0, 5, -1} 'array of 5 integersDim tmpint As Integer = 0For i = 0 To ints.Length - 1 'i.e. ints(0) to ints(4) tmpint += ints(i) 'adds all valuesNext 'tmpint will be 2 + 4 + 0 + 5 - 1 = 10
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now