Trouble displaying "0"

BJS

Registered User.
Local time
Today, 14:50
Joined
Aug 29, 2002
Messages
109
I am coding a calculator within my application.
The field txtResult on my form displays the numbers as they are being clicked and the results of the math.

My problem is:

This works:
pressing 9.99 on the calculator displays 9.99

This does not work:
pressing 9.09 displays 9.99 instead of 9.09

Here is my code:

'WHEN CLICKING ON THE NUMBER 9:
dblNum = 9

"WHEN CLICKIN ON THE NUMBER 0:
dblNum = 0

'HERE THE USER STARTS BY PRESSING THE FIRST NUMBER (9)

db1Num1 = dblNum
Me.txtResult = Format(dblNum1, "0.#######")

'IF THE FIRST NUMBER PRESSED (9) DOES NOT CONTAIN A DECIMAL
'THE RESULT WILL BE THE NEXT NUMBER (0) PRESSED AND A DECIMAL
'APPENDED TO THE FIRST NUMBER (9.0)


If flgDec = false Then
dblNum1 = dblNum1 & "." & dblNum
Me.txtResult = Format(dblNum1, "0.#######")
End If

'IF THE CURRENT NUMBER HAS A DECIMAL, AND ANOTHER NUMBER
'IS PRESSED (9), THEN THIS NUMBER IS APPENDED TO
'THE CURRENT NUMBER. (9.09)


If flgDec = true Then
dblNum1 = dblNum1 & dblNum
Me.txtResult = Format(dblNum1, "0.#######")
End If

I can't seem to get the "0" to display in between the numbers.
Can anyone help me with this?

Thanks,
BJS
 
Last edited:
BJS,

You are storing your number as a NUMBER.

Numbers are NOT 9.0!

You want to build a "string", storing it as a number just confuses the real issue of what you are trying to do.

Wayne
 
Thank you for your response, Wayne!

I will store my numbers as strings.
I did it that way first, but then had problems adding them, so I reverted to numbers.

I'll give it another shot with strings.

Thanks,
BJS
 
Hi,

I can now get my number to display as 9.09, since dimensioning my numbers as strings, but I'm back to my original problem....I can't get them to add:

'dblNum2 = 9.09 + 9.09
dblNum2 = CDbl(dblNum1) + CDbl(dblNum2)

gives error: "Cast from string '9.099.09' to type 'Double' is not valid.

I'd appreciate some help with this .....THANKS! :confused:
 
The code I had was correct:

'dblNum2 = 9.09 + 9.09
dblNum2 = CDbl(dblNum1) + CDbl(dblNum2)

I simply missed converting to double in a portion of my code.
This works now.

BUT.....now the problem is:

After the result of the math is assigned to dblNum2, dblNum1 is set to 0.
This causes a problem when I assign a new number (9) to dblNum1.
When I assign the number 9 to dblNum1 by pressing the "number 9" button, the number displays as 09 instead of 9.

How do I get rid of the 0 in front of the nine?
Note: I would only want to strip off the 0 if the number displays as 09, not if it is 0.9

THANKS IN ADVANCE FOR THE HELP!
 

Users who are viewing this thread

Back
Top Bottom