Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Euro Value Conversion

Status
Not open for further replies.

rgh

Programmer
Feb 2, 2000
33
GB
I want to easily convert fields displayed within a system
from one currency to another, in my case this is Pound to
Euro. Currently our code has

LblDisplayValue.Caption = format(curValue,”Currency”)

I know that it is possible to change the Currency part
to be the name of a function, e.g.

LblDisplayValue.Caption = Format(curValue,ConvertEuro)

and the function will be called, however is it possible
to pass the value to be formatted to the function.


Thanks,

Richard.
 
If I understand you correctly is should be:

LblDisplayValue.Caption = Format(ConvertEuro,"currency")

Since it is the value that you want to convert and not the format. You could also:

LblDisplayValue.Caption = FormatCurrency(ConvertEuro)

Sunaj
 
Possibly I did not explain as well as I could.

The system currently uses the currency as per the set up
of the PC. so

LblDisplayValue.Caption = Format(23.44,"Currency")

will return £23.44 into the label. However what I want to
be able to do is allow the user to view the currency in
either Pound or Euro so

LblDisplayValue.Caption = Format(23.44,ConvertEuro)

Will either display the value as £23.44 if they are
currently viewing in Pound or say €30 if they choose to
display in Euros.

Richard.
 
I obviously misunderstood that.

What about:
LblDisplayValue.Caption = Format(23.234234,"€" & ".00")

Or you could make a function that returns "$" or "£" depending on the choosen format...

Sunaj
 
That is what I want to do. If you set up a new exe and
just add the code

-----

Private Sub Form_Load()

Dim strValue As String

strValue = Format(23.44, EuroConvert)

End Sub

Private Function EuroConvert()

MsgBox "EuroConvert"

End Function

------

The Message box in the function will display, however I do
not know how to get the value 23.44 to the function, or if
it is possible.
 

I'm not sure exactly what you mean....

-------------------------------------------------------
Private function EuroConvert(Value as single) as String
EuroConvert = Format(Value,"€" & ".00")
end function
--------------------------------------------------------

Or if you want to make if fancy
-------------------------------------------------------
Enum CurrencyFormat
Euro = 0
Dollar = 1
Pounds = 2
End Enum

Private function Convert(Value as single, optional Currency as CurrencyFormat = Euro) as String
Select Case CurrencyFormat
Case 0: Convert = Format(Value,"€" & ".00")
Case 1: Convert = Format(Value,"$" & ".00")
Case 2: Convert = Format(Value,"£" & ".00")
end function
--------------------------------------------------------

I guess the value also have to be converted, for which you'll need the exchange rates.....

Sunaj
 
Thanks Sunaj,

The last example is roughly how I have the coding done,
however I was looking for a lazy way of changing the
statement to populate the label. I was hoping that
somehow I could call a function from within the
format statment and pass the value to be formatted.

Thanks again,

Richard.
 
Yes you could do that, but it wouldn't be smart, would it?
What would you gain by putting it into a function?

LblDisplayValue.Caption = Format(23.23423, EuroFormat)

Private Function EuroFormat as string
EuroFormat = "€" & ".00"
end function


X-)Sunaj

 
The reason for putting it into a function is so that is
the routine can convert both ways.

System is in Pound, user wants to display Pound and
have the option to convert to Euro.

Run a conversion on system to convert all values to Euro.
System will be in Euro, user wants option to display in
Pound.
Code for Routine looks like this:
------------------------------------------------
Public Function EuroConvert(ByVal curInputVal As Currency) As String
' If System(Base) is same as display just format Value
If (puntbase And puntdisp) Or (Eurobase And eurodisp) Then
EuroConvert = Format(curInputVal, gstrBaseSymbol)
Else
' Convert to required display and currency symbol
If Eurobase And puntdisp Then
EuroConvert = Format(curInputVal * gdblEuro, gstrConvertedSymbol)
Else
EuroConvert = Format(curInputVal / gdblEuro, gstrConvertedSymbol)
End If
End If
End Function
-------------------------
It would be easy to change all my
lbl.caption = format(value,"Currency")
to
lbl.caption = format(value,Euroconvert)

instead I will have to change to
lbl.caption = Euroconvert(value)

As I said - just trying to be lazy :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top