Click to See Complete Forum and Search --> : Masked Edit Box Formatting?!?
PhilipG
Dec 4th, 1999, 12:10 AM
I'm using a masked edit box to take a currency formatted input. I'm having problems getting it to do anything at all! Here is what I'm wanting it to do:
When you first start Program, $0.00 should be there.
If the user hits "1", it should now read $0.01
If the user hits "2", it should now read $0.12
If the user hits "4", it should now read $1.24
If the user hits "5", it should now read $12.45
How can I accomplish this?
Thank you very much for the help!!
leif-p
Dec 4th, 1999, 01:45 AM
Phillip:
Paste the code below into a command button, and put a text box on the form as well, then run:
Dim NumberOfInputs As Integer
Dim A(10) As Integer
Dim Power As Integer
Dim Result As Single
'set the array element to user input
A(1) = 1
A(2) = 2
A(3) = 4
A(4) = 5
'set number of times user inputs a number
NumberOfInputs = 4
Result = 0#
Power = NumberOfInputs
If NumberOfInputs <= 0 Then Exit Sub
For i% = 1 To NumberOfInputs
Power = Power - 1
Result = Result + A(i%) * 10 ^ Power
Next i%
'divide result by 100
Result = Result / 100#
'set text box text to result
Text1.Text = "$" & Format(Result, "0.00")
'what you are doing in the above code is basically setting result equal to:
'Result=A(1)*10^3 + A(2)*10^2 + A(3)*10^1 + A(4)*10^0
'which is really equal to:
'Result=1000 + 200 + 40 + 5 = 1245
'which must be divided by 100 to get 12.45.
Good luck!
PhilipG
Dec 4th, 1999, 03:34 AM
Thanks for the code! Unfortunatly the number of inputs won't be known before compile time. I need to allow a user to be able to enter a dollar amount on-the-fly, updating the textbox on keypress.
Maybe I'm missing something, but how can I achieve this?
Thanks!
[This message has been edited by PhilipG (edited 12-04-1999).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.