1 Attachment(s)
[RESOLVED] Pressing Calculate button a 2nd time zeros 2 variables
Gentlemen:
A form with 6 variables now behaves properly in the first run of entering the 6 variables, and pressing the calculate command button.
But if the same calculate button is again pressed two of the variables namely the first and the last which call for Currency values are zeroed out.
I also get an error in the value of the final calculation if I change any of the variable values on the form. The process again zeros out the first and last fields.
Attached is a zipped of the form, and code.
Any suggestions???? :(
Re: Pressing Calculate button a 2nd time zeros 2 variables
when you first run the command the textbox is holding a numeric value so if the textbox held say 23
TmpPrice = Val(TxtPrice.Text), TmpPrice becomes 23 but then you format the textbox to show a currency format, $23.00. Now, if you run the command again, the Val() function wont recognise it because of the currency symbol and it will return zero. try this instead
TmpPrice = CCur(TxtPrice.Text)
casey.
Re: Pressing Calculate button a 2nd time zeros 2 variables
Dear Miss VBasicgirl:
Thank you for the tip. I shall try it, and report any success.
Thanks again.
:wave:
Back again:
It worked very well by changing all Currency values to use the CCur for the Textboxes.
Now I can change any variable on the form and the recalculation works.
May I present another question on this same topic:
How do I code for the calculations to be made and displayed automatically without resorting to the use of the Calculate Button???
:thumb: :)
Re: Pressing Calculate button a 2nd time zeros 2 variables
I ran your program and it had several errors.
First of all the Down payment is specified in % not dollars so let the user know this.
The problem is that you are reformatting the text the user enters, so the next time you press the button it assumes it has user entered data rather than the new formatted data
You can expect Val(100000) to give the same results as Val($100,000)
Edit: VBA SIC GIRL has beat me to it
One more suggestion
most Users hate it when a program asks if they really want to exit.
Re: Pressing Calculate button a 2nd time zeros 2 variables
Dear Moeur:
Thank you for your observations. I followed through on Vbasicgirl's tips and all is well now.
Please you mention that Users do not like to prompted for an Exit option..
What do you suggest instead - The X on the form or something other that that.
I have not finished writing up the Help section for this application, and so I apologize for not indicating that the Dwn Pmt calls for a number between 0 and 99.
Thanks again. :blush:
I copied your 3 code submissions, and will study them later. I am but a beginner in VB6, and the questions raised pertain to my first application in VB6. Thanks for the links.
Re: Pressing Calculate button a 2nd time zeros 2 variables
The problem you face when trying to calculate something automatically is knowing when the user as actually finished typing everything in the fields. I would keep things user friendly and just make sure the tab index's are in order and maybe put the Default property of the calculation command button to true (pressing enter activates it). Following moeur's point of the exit, is there anything major that could be lost by accidently closing the program ?, if not then theres no real need for it.
casey.
Re: Pressing Calculate button a 2nd time zeros 2 variables
The Exit button is OK, but why then does the user have to press a second button confirming his intentions?
Re: Pressing Calculate button a 2nd time zeros 2 variables
Dear Vbasicgirl and Moeur:
Thank you very much for your help.
Now I understand your point on the merits of the confimation of exiting. -I agree it is unnecessary.
As to the automation of the calculate I changed the default property to true, and will retest.
Thanks again. your help was quick and very efficient.
;)