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
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

761 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