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
52 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 45

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 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

822 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