Results 1 to 3 of 3

Thread: Masked Edit Box Formatting?!?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    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!!

  2. #2
    Junior Member
    Join Date
    Dec 1999
    Location
    houston,tx
    Posts
    20

    Post

    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!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width