Exchange rate (1 Viewer)

Gismo

Registered User.
Local time
Today, 16:42
Joined
Jun 12, 2017
Messages
1,298
I suspect the problem is that the currency conversion code you are using is always applying the dot as decimal separator (in strings) while your local decimal separator is a comma.
Not knowing the code, I cannot suggest a practical fix for the problem, but this info might help @arnelgp reproducing the issue.
Hi Sonic8,

you are correct, you are on the right track here
I removed the dot from the equation and the type mismatch error disappeared
I received a exchange outcome for the fist time now
Only, the result is now value of 973585 and should be 217.973585 or 217,973585
So I will have to play around with the expression:
Const Keys As String = ",.0123456789"
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:42
Joined
Sep 21, 2011
Messages
14,311
Leave alone what you do not understand.
It would have been better to replace the . with the , and see if that worked.

It should not be 217.973585 as you have already had a value like that and it fails. :(

Just use Replace() to swap the . for a ,
 
Last edited:

Gismo

Registered User.
Local time
Today, 16:42
Joined
Jun 12, 2017
Messages
1,298
Leave alone what you do not understand.
It would have been better to replace the . with the , and see if that worked.

It should not be 217.973585 as you have already had a value like that and it fails. :(

Just use Replace() to swap the . for a ,
Thank you

This seem to work like a charm

sRet = char & Replace(sRet, ".", ",")

Public Function StrToDbl(ByVal s As String) As Double
Const Keys As String = ",.0123456789"
Dim sRet As String, char As String
Dim i As Long, ln As Long
ln = Len(s)
For i = ln To 1 Step -1
char = Mid$(s, i, 1)
If InStr(1, Keys, char) <> 0 Then
If char <> "," Then
sRet = char & Replace(sRet, ".", ",")
End If
Else
Exit For
End If
Next
Debug.Print sRet

StrToDbl = CDbl(sRet)

End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:42
Joined
Sep 21, 2011
Messages
14,311
No ! :(
Do not replace every time in the loop, just do it once at the end, either before you convert to double or as part of the convert function.
 

Gismo

Registered User.
Local time
Today, 16:42
Joined
Jun 12, 2017
Messages
1,298
No ! :(
Do not replace every time in the loop, just do it once at the end, either before you convert to double or as part of the convert function.
Amended,

Thank you so much

Public Function StrToDbl(ByVal s As String) As Double
Const Keys As String = ",.0123456789"
Dim sRet As String, char As String
Dim i As Long, ln As Long
ln = Len(s)
For i = ln To 1 Step -1
char = Mid$(s, i, 1)
If InStr(1, Keys, char) <> 0 Then
If char <> "," Then
sRet = char & sRet
End If
Else
Exit For
End If
Next
'Debug.Print sRet
sRet = Replace(sRet, ".", ",")
StrToDbl = CDbl(sRet)

End Function
 

Users who are viewing this thread

Top Bottom