Results 1 to 12 of 12

Thread: Format-Function

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11
    I hope someone can help me. I'm using this code:

    <code>
    Dim exkl As Single
    Dim inkl As Single
    Dim euro As Single
    Dim gesamt As Single
    Dim zinsen As Single
    Dim mwst As Single
    Dim zwischensumme As Single
    inkl = CSng(Form5.Text16.Text)
    exkl = inkl - ust
    exkl = Format(exkl, "##,##0.00")
    zinsen = (inkl / 100) * 12
    mwst = ((inkl + zinsen) / 100) * 20
    gesamt = inkl + zinsen + mwst + 130
    euro = (inkl + zinsen + 130) / 13.7603
    zwischensumme = inkl + 130
    zwischensumme = CSng(zwischensumme)
    gesamt = Format(gesamt, "##,##0.00")
    euro = Format(euro, "##,##0.00")
    mwst = Format(mwst, "##,##0.00")
    inkl = Format(inkl, "##,##0.00")
    zinsen = Format(zinsen, "##,##00.00")
    zwischensumme = Format(zwischensumme, "##,##0.00")
    </code>

    For example: Form5.Text16.Text = "200", zinsen should be 24,00 and gesamt should be 398,80 but I just get 24 for zinsen and 398,8 for gesamt.

    How can i change it to this "##,##0.00" Format?

    please help me

  2. #2
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550
    Check your regional settings.

    We use a . for a decimal point and , for thousand separators here in the UK, but I developed an Excel VB prog for use in Holland and it went ape - because they had the exact reverse - , for decimals and . for thousand separator. How perverse....

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    The problem lies with your choice of variables.

    You have chosen numeric variables so you can't save the format. You need to save the format in strings.

    Good Luck.
    Iain, thats with an i by the way!

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11


    Thank you for your answers.

    Iain:

    please explain it more exactly?
    I dont know what you mean. how can i save the format in strings

  5. #5
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You will have to declare all of your variables as strings.

    Then you can keep the format in the variable.

    When you want to do calculations you will nedd to use the Val() Function.

    Code:
    Dim stCurFormat As String
    Dim stEuro as String
    
    stCurFormat = "##,##0.00"
    stEuro = 12
    
    stEuro = Format(stEuro, stCurFormat)
    
    msgbox Format (Val(stEuro) * 10, stCurFormat)

    [Edited by Iain17 on 06-06-2000 at 05:54 PM]
    Iain, thats with an i by the way!

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11

    ok, i understand

    but i also want to calculate two single variables, therefore i can't use the val function

  7. #7
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Why not?

    Code:
    msgbox val(stEuro) * val(stPound)
    Iain, thats with an i by the way!

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11


    doesn't the Val()-Function ingnore the comma

    13.3 -> 13
    13,3 -> 13 (for Europe)

    Am i right?

  9. #9
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Careful, guys! Alex is on the right track. The Val function stops at the first non-numeric character (after stripping out all spaces). For example, Val("12,345.67") will evaluate to 12. Not desirable! Val only recognizes the "." as a decimal separator, so it WILL accept "13.3" (i.e., it will convert it properly).

    [Edited by BruceG on 06-06-2000 at 02:34 PM]
    "It's cold gin time again ..."

    Check out my website here.

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11

    Thanks BruceG, i thought i was right.

    In Austria we use the "," as a decimal separator. How can i solve my problem, when you look at my code, i've posted? I wonna change a string (ex. 125,5) to a single or a double, calculate with it and then send it to printer in a format like "##,##0.00" (ex. 1.250,50), but my code returns 1.250 or 1.250,5.

    What's wrong with it?


    alex
    who won't give up

  11. #11
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Sorry, i forgot the Val() funtiob was crap like that.

    Use the Csng() function instead.
    Iain, thats with an i by the way!

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11

    Thumbs up Can anyone explain it to me

    Hi

    Thank you all for your answers!!!!!!

    Could someone explain it to me, why the format-function does not work well with single variables (in my case)?

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