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
4
Medium Priority
?
127 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
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

by:rayluvs
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

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
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

by:
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

Open in new window

n
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

886 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