Go Premium for a chance to win a PS4. Enter to Win

x
Solved

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

Posted on 2016-11-10
Medium Priority
127 Views
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
``````
However, if Canadian currency is sent gives a run-time 13 type mismatch error.

``````Print ccur("C\$16,000.1")
``````

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.

0
Question by:rayluvs
• 2

LVL 76

Expert Comment

ID: 41883126
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

ID: 41883136
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
``````
0

LVL 46

Expert Comment

ID: 41883848
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

GrahamSkan earned 2000 total points
ID: 41883902
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
``````
n
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
###### Suggested Courses
Course of the Month11 days, left to enroll