Solved

convert a string containing currency data into a currency or decimal in vb6, no matter the country currency

Posted on 2016-11-10
4
28 Views
Last Modified: 2016-11-13
We have a code when called, the currency amount is passed to.  If the currency is US Dollar, it's ok.

Example

Print ccur("$16,000.1")
 16000.1 

Open in new window

However, if Canadian currency is sent gives a run-time 13 type mismatch error.

Print ccur("C$16,000.1")

Open in new window


We know it has to do with the regional setup of the computer (we think).

We tried:
val("C$16,000.1")
results is 0

Also CDbl, CDec, CLng, CULng, etc.

Please advice on the correct method to go about it.
0
Comment
Question by:rayluvs
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
CCur is intended to work on numbers, converting any numerical input to the Currrency subtype.

With string input it ignores the regional leading currency symbol. On my system with UK setting the $ sign gives an error, but £ sign does not.

Via the regional settings it is possible to set any single character to be the currency symbol, but not two as in C$.
0
 

Author Comment

by:rayluvs
Comment Utility
Thanx for the info, prior placing the question we tried various setup via Regional but no success.

Is there another way to convert a the following value when the currency is not of USA?

Example, we would like while in the USA, convert a string Canadian currency to decimal value:
"C$16,000.10"  to 16000.1

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
1. C$16,000.1 is not a standard format for international currency.
2. How many different currencies are in need of conversion?
3. Please post examples of those currency string values and the numeric value you need.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
This function should chop of non-numeric leading characters
Function MyCCur(vNumber As Variant) As Currency
    Do Until IsNumeric(Left(vNumber, 1))
        vNumber = Mid(vNumber, 2)
        If Len(vNumber) = 0 Then
            vNumber = 0
        End If
    Loop
    MyCCur = CCur(vNumber)
End Functio

Open in new window

n
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now