|
-
Apr 5th, 2000, 01:09 AM
#1
Thread Starter
Addicted Member
I'm able to subtract the values of two textboxes, however, when I go to add the values of the two textboxes using the "+" it's concatenated as a string running the two values together. How do I get around this issue.
Thanks!
-
Apr 5th, 2000, 01:12 AM
#2
Lively Member
Convert one of the values of the textbox to a number when adding them.
-
Apr 5th, 2000, 01:16 AM
#3
Addicted Member
?
If you're putting the results into another TextBox or into a String then it will concatenate. Either assign the results to a numeric variable and then assign that variable to the TextBox <or> use the Val on the TextBox values, for example:
Text1.Text = Val(Text1.Text) + Val(Text2.Text)
Of course with this method you'd have to add your own error checking (the text is actually numeric, decimals, etc). Also try looking into the C___ conversion functions if you need a specific data-type, some of these are CInt, CSng, CDbl, and Clng.
-
Apr 5th, 2000, 01:17 AM
#4
Fanatic Member
Correct a "+" is use for arithmetic and a "&" is use for concatenation in VB.
Your values are in string format and must be convert to a numeric. You can use "Cint" or something similar to that.
Chemically Formulated As:
Dr. Nitro
-
Apr 5th, 2000, 02:08 AM
#5
Thread Starter
Addicted Member
Adding textbox values
Thanks guys. I tried the suggestions above and was able to return a value. However, the return value is truncated, whereas, it would add the outer most numbers to the left of the comma. Ex: 671,435 + -16,443 returns 655 (671-16). For the interim, I was able to get the correct number by using two "-" back to back. It works for now, but afraid it may catch up with me.
-
Apr 5th, 2000, 05:04 AM
#6
Hyperactive Member
Hi, there.
Try this code:
Dim str As String
str = CLng(Text1) + CLng(Text2)
Text3 = Format(str, "###,###")
You need to use Format function to insert coma in your result (654,992), otherwise you'll get a result without coma (654992).
Larisa
-
Apr 5th, 2000, 07:40 PM
#7
Thread Starter
Addicted Member
Adding Textbox values
Thanks Larissa. It works. You wouldn't know a quicker way of doing multiple textboxes. Maybe using an array or something of the sort.
[Edited by Hutty on 04-06-2000 at 09:02 AM]
-
Apr 6th, 2000, 12:19 AM
#8
Fanatic Member
Dim lng_Result As Long
Dim NitroText As Control
For Each NitroText In Form1.Controls
If TypeOf NitroText Is TextBox Then
'PURPOSE: Check if data is numeric or string
If IsNumeric(NitroText.Text) Then
lng_Result = lng_Result + NitroText.Text
Else
MsgBox "Data in " & """" & NitroText.Name & """" & " is not a numeric!."
End If
End If
Next
MsgBox lng_Result
Chemically Formulated As:
Dr. Nitro
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
|