Algar Posted July 30, 2003 Posted July 30, 2003 I have 9 Textboxes which hold numbers. I want to add the 9 numbers together and put the total in a 10th Testbox Dim R1 As Long R1 = Trim(CInt(Trim(txtH1R.Text))) + Trim(CInt(Trim(txtH2R.Text))) + Trim(CInt(Trim(txtH3R.Text))) + Trim(CInt(Trim(txtH4R.Text))) + Trim(CInt(Trim(txtH5R.Text))) + Trim(CInt(Trim(txtH6R.Text))) + Trim(CInt(Trim(txtH7R.Text))) + Trim(CInt(Trim(txtH8R.Text))) + Trim(CInt(Trim(txtH9R.Text))) txtTotal.Text = Trim(CStr(R1)) As far as I know "+" only appends when theres 2 strings. The CInt should take care of that, but for some reason its appending all 9 numbers togther. Anyone have any ideas ? Quote
Algar Posted July 30, 2003 Author Posted July 30, 2003 Ok, everything works now after I removed the outside Trim. CInt(Trim(txtH1R.Text)) rather then: Trim(CInt(Trim(txtH1R.Text))) Not sure why exactly though, does the Trim return strings only ? If thats the case how would it allow putting a string into a Long variable ? Quote
*Experts* mutant Posted July 30, 2003 *Experts* Posted July 30, 2003 (edited) Yes Trim returns a String, but you should be using the Trim method of the String object rather than the old VB6 method. The cast from String to Long is invalid, do you have Option Strict On when compiling? Edited July 30, 2003 by mutant Quote
Algar Posted July 31, 2003 Author Posted July 31, 2003 Ahhh im pretty new to .NET. I didn't know about Strict, or the object methods. Thanks a lot ! Quote
JABE Posted July 31, 2003 Posted July 31, 2003 You can remove the Trim call and the effect will be the same: CInt(txtH1R.Text) Instead of CInt, I prefer to use Convert.ToInt32 because you can use it in any .NET language. Convert.ToInt32(txtH1R.Text) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.