|
-
Nov 11th, 2003, 05:13 PM
#1
Thread Starter
Lively Member
Absolute value of numbers
I am trying to use the Abs function to return the absolute value of a range of numbers. The range includes both positive and negative numbers. The numbers are also being formatted as currency. The code I'm using is returning the value of the positive numbers minus the value of the negative numbers.
VB Code:
lblFinImp_r.Caption = Format(Abs(CCur(txtTmpVal1 + txtTmpVal2)), "$#,##.##")
What am I doing wrong?
-
Nov 11th, 2003, 05:34 PM
#2
Addicted Member
your code says to take txtTempVal1 and add it to txtTempVal2, after tht has been done, convert it to currency, after that has been done take the abs and then format it - if you want the abs of each item then take the abs of each item prior to the add
-
Nov 11th, 2003, 05:49 PM
#3
PowerPoster
"absolute value" is a math concept which is applied to a single number, so what do you MEAN when you say you want the absolute value of a range?
-
Nov 11th, 2003, 05:51 PM
#4
Personally, I'm a bit fuzzy on what the problem is..... Do you get an error? Are you getting in correct result? What?
Syntatically, what you've done looks right, but it depends on what you are trying to accomplish.
TG
-
Nov 11th, 2003, 08:08 PM
#5
FinChase is either getting a type mismatch error or incorrect results. It depends on the values of the textboxes (assuming txtTmpVal1 and txtTmpVal2 are TextBoxes)
Adding two strings is not addition in the math sense, its the concatenation if two values. Even if the values are numeric. So, if
txtTmpVal1 = 1 and txtTmpVal2 = -2 then (txtTmpVal1 + txtTmpVal2) = "1-2". The CCur("1-2") will result in a type mismatch.
if
txtTmpVal1 = 3 and txtTmpVal2 = 2 then (txtTmpVal1 + txtTmpVal2) = "32" - which is an incorrect result as it should be 5.
Convert each textbox value individually.
<on soap box>
Just curious (again assuming txtTmpVal1 is a textbox). Why did you rely on the default property of the textbox and not code txtTmpVal1.Text, yet for the Label you specified the default property (.Caption). When coding try to be consistent, do it one way or the other but don't mix and match. Sorry, it just drives me nuts.
<off soap box>
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
|