|
-
Jul 25th, 2002, 04:38 PM
#1
Thread Starter
Addicted Member
***RESOLVED*** Data type conversion error
I need to be able to divide two currency values in an MSFlexGrid to come up with a percent value.
The challenge is that I need to have error handling to be sure that if the user puts in a $.0 currency value I do not get an error.
Ex.
Private Sub MSFlexGrid1_LeaveCell()
With MSFlexGrid1
.TextMatrix(1, 1) = Format(.TextMatrix(2, 1) / .TextMatrix(3, 1), "0.0%")
End With
End Sub
Last edited by Jefftopia; Jul 26th, 2002 at 09:07 AM.
-
Jul 25th, 2002, 06:00 PM
#2
Lively Member
Re: Data type conversion error
Originally posted by Jefftopia
I need to be able to divide two currency values in an MSFlexGrid to come up with a percent value.
The challenge is that I need to have error handling to be sure that if the user puts in a $.0 currency value I do not get an error.
Ex.
Private Sub MSFlexGrid1_LeaveCell()
Code:
With MSFlexGrid1
if .textMatrix(3,1) > 0 And .textMatrix(2,1) > 0 then
.TextMatrix(1, 1) = Format(.TextMatrix(2, 1) / .TextMatrix(3, 1), "0.0%")
End
End With
End Sub
You may need to convert the values to decimals...
-
Jul 25th, 2002, 06:01 PM
#3
In addition to what SoCalled said, I'd create variables, do the math in memory with the variables, and then write the results back to the appropriate column in my grid.
-
Jul 25th, 2002, 06:05 PM
#4
Lively Member
Originally posted by Hack
In addition to what SoCalled said, I'd create variables, do the math in memory with the variables, and then write the results back to the appropriate column in my grid.
Nice, am thinking you mean this would be more efficient, since l would imagine vb would have to locate each value in the memory array, as opposed to having a single memory location for each value.
Would also make the code easier to read and reduce the likelyhood of bugs.
-
Jul 25th, 2002, 10:02 PM
#5
Member
Try this
Private Sub MSFlexGrid1_LeaveCell()
Dim x as Double
With MSFlexGrid1
if .textMatrix(3,1) > 0 And .textMatrix(2,1) > 0 then
x = (.TextMatrix(2, 1) / .TextMatrix(3, 1)
End
.TextMatrix(1, 1) =format(x,"0.0%")
End With
End Sub
hope that help
-
Jul 25th, 2002, 10:05 PM
#6
Lively Member
Setting x to 0 above the if then right....
-
Jul 26th, 2002, 09:09 AM
#7
Thread Starter
Addicted Member
thx--I am going with the variable method. Works well!
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
|