Results 1 to 15 of 15

Thread: [RESOLVED] Currency datatype

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Resolved [RESOLVED] Currency datatype

    I have created small business application where I have used currency data type. Everything works fine with currency data type until I change system regional settings (date format, currency format ect.). All the calculations on currency data type also changed according to regional settings which gives me wrong calculation on currency. How can I work on specify regional settings even if the system regional setting is changed.

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Currency datatype

    explain and give an example of how you are doing your calculation. The datatype should be unaffected by regional settings. The way it is displayed on screen however is affected by them, and how the format command works is.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Currency datatype



    This what i am getting before changing the regional settings.
    i am getting the exact amount i have specified



    and this the value i am getting after changing regional settings to Germany

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Currency datatype

    ok why are you using val on a number to start with? It already is a number.
    use ccur to convert it to currency
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Currency datatype

    The problem is not in the currency datatype, but in the Val function.

    You used it completely unnecessary here.

    Val expects a string as parameter. VB will convert the value to a string for you, and will use the regional settings for this. If the decimal seperator is a comma, the string will be "23,44"

    Val however, is not regional settings aware, and will only recognize a point as decimal seperator. So it will stop after 23.

    In this case there is no reason to use Val. Just remove it. It only causes an extra implicit conversion (because the parameter is not a string), an exptra function call (Val is not necessary), and a second implicit conversion (Val returns a double and not a decimal)

    Your assigment will be
    Curr = 23.44

    Or if you want to be precise, you can use the currency declaration character, so no implicit conversion will occur anymore.

    Curr = 23.44@
    Frans

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Currency datatype

    let me make it simple

    vb Code:
    1. Dim Curr As Currency
    2. Curr = 22.22
    3. 'now Curr will return 22,22 not 22.22
    4. 'bcuz of regional settings

    now if i have to compare Curr with value "22.22" it will return false bcuz of changed separator how can i avoid this?

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Currency datatype

    This is not true.

    If it was true what you said, then the messagebox will not be shown in this code:

    Code:
    Private Sub Command1_Click()
    Dim c As Currency
        c = 22.22
        If c = 22.22 Then MsgBox "Yes"
    End Sub
    The problem only occurs when you are comparing strings.
    Frans

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Currency datatype

    what if i have to compare c with string?

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Currency datatype

    Then don't compare it to a string, cast the string accordingly with CCur() function instead of Val(). Or work with strings with no thousands separator using Format().

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Currency datatype

    thanks Frans C and leinad31

  11. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] Currency datatype

    yeah thanks for saying exactly what i did: Use CCur
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  12. #12
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] Currency datatype

    Yes, for the record it was Lord Orwell's idea. Please don't forget to give him the rep points due to him.

  13. #13
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] Currency datatype

    hey can i help it most of my posts predate ratings?
    leave the board for 2 years and everyone else has green bars!
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  14. #14
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: [RESOLVED] Currency datatype

    I know what you mean.
    My most active years on this board are years ago.

    But slowly I am catching up with the others.
    Frans

  15. #15
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] Currency datatype

    me too. i've got about 50 pts in the last month. I love it when someone with huge post #s rates me. I have a bunch of kudos from people under 20 posts.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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