PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
WD Euro calculator
Published by Boller
in the category Tools
New features



Description
WD Euro calculator


PROCEDURE WIN_Euro_Calculator(nNumber="", nCurrencyDisp=0, nCurrencyStor=0)

GLOBAL
gfnTotal is currency // calculated total
gfsLastOp is character // last requested operation
gfbCalculate is boolean // 'True' whenever an operation is completed

gfnCurrency is int // Constant of the currency
gfsCurrency is string // Currency
gfsCurrencyDisp is string // Displayed currency
gfsCurrencyName is string // Name of the currency

gfnCurrencyMem is int // Stored currency

gfnCurrencyMem = nCurrencyStor

LOCAL
// if the window receives parameters
IF nNumber<>"" THEN
ParamProc()
ELSE
// Current currency
FindCurrency(eFRF)
gfsCurrencyDisp = " FRF"
EDT_DISPLAY1="0"+gfsCurrencyDisp
CONVERT_BTN..Caption = gfsCurrencyName
END

// tooltip
sTooltip is string
sTooltip = "1 EURO = "+eExchangeRate(gfnCurrency)+gfsCurrency

// Press a key
CONSTANT WM_KEYDOWN=256
Event(OnKeyPressed,"*.*",WM_KEYDOWN)



//-----------------------------------------------------------------------------------------------------------------

PROCEDURE ParamProc()
// the window received the parameters

// Special case: the stored currency and the display currency are the same
IF nCurrencyStor=nCurrencyDisp THEN
// if 2 EURO currencies
IF nCurrencyStor=eEUR THEN
// the stored currency becomes the French Franc
nCurrencyStor=eFRF
// search for the currency
FindCurrency(nCurrencyStor)
ELSE
// the stored currency becomes the EURO
nCurrencyStor=eEUR
// search for the currency
FindCurrency(nCurrencyDisp)
END
// display
EDT_DISPLAY1 = nNumber + gfsCurrencyDisp

ELSE
// if no currency is in EURO
IF (nCurrencyStor<>eEUR AND nCurrencyDisp<>eEUR) THEN
FindCurrency(nCurrencyDisp)

ELSE
// search for the currency
IF nCurrencyStor<>eEUR THEN
FindCurrency(nCurrencyStor)
ELSE
FindCurrency(nCurrencyDisp)
END
END

// fill the edit control with the proper currency
EDT_DISPLAY1=eChangeCurrency(nNumber,nCurrencyStor,nCurrencyDisp,5)+gfsCurrencyDisp
END

// insert a thousand separator
ThouSepar()


//-----------------------------------------------------------------------------------------

PROCEDURE ThouSepar()
// insert a thousand separator
// changes 99999999999999 to 99 999 999 999 999

sFormatNumber is string
nPosComma is int
nPosComma = Position(EDT_DISPLAY1,".")

// if it's a decimal number
IF nPosComma<>0 THEN
sWholePart, sDecimalPart are strings
sWholePart = EDT_DISPLAY1[[1 TO (nPosComma-1)]]
sDecimalPart = EDT_DISPLAY1[[(nPosComma+1) TO (Length(EDT_DISPLAY1)-4)]]
sFormatNumber = sDoSpacing(sWholePart)+"."+sDecimalPart+gfsCurrencyDisp
ELSE
sFormatNumber = sDoSpacing((EDT_DISPLAY1[[1 TO (Length(EDT_DISPLAY1)-4)]]))+gfsCurrencyDisp
END

EDT_DISPLAY1 = sFormatNumber


//------------------------------------------------------------------------------

PROCEDURE OnKeyPressed()

// detection of the key pressed
SWITCH _EVE.wParam
CASE 96,48 // key 0
ClicDigit(0)
CASE 97,49 // key 1
ClicDigit(1)
CASE 98,50 // key 2
ClicDigit(2)
CASE 99,51 // key 3
ClicDigit(3)
CASE 100,52 // key 4
ClicDigit(4)
CASE 101,53 // key 5
ClicDigit(5)
CASE 102,54 // key 6
ClicDigit(6)
CASE 103,55 // key 7
ClicDigit(7)
CASE 104,56 // key 8
ClicDigit(8)
CASE 105,57 // key 9
ClicDigit(9)
CASE 106 // key *
Process("*")
CASE 107 // key +
Process("+")
CASE 109 // key -
Process("-")
CASE 111 // key /
Process("/")
CASE 110,190 // key . or ;
ExecuteProcess(COMMA_BTN,trtClick)
CASE 46,8 // del key
ExecuteProcess(BTN_CLEAR,trtClick)
CASE 13 // Enter key
ExecuteProcess(EQUALS_BTN,trtClick)
CASE 9 // TAB key
ExecuteProcess(CONVERT_BTN,trtClick)
CASE 27 // ESC key
Close()

END


//-----------------------------------------------------------------------------

PROCEDURE Process(sLastOp)

sNumber is string // Number displayed
sNumber = EDT_DISPLAY1[[1 TO Length(EDT_DISPLAY1)-4]]
sNumber = Replace(sNumber," ","")

IF NOT gfbCalculate THEN
SWITCH gfsLastOp
CASE "+"
gfnTotal = gfnTotal + Val(sNumber)
CASE "-"
gfnTotal = gfnTotal - Val(sNumber)
CASE "*"
gfnTotal = gfnTotal * Val(sNumber)
CASE "/"
gfnTotal = gfnTotal / Val(sNumber)
OTHER CASE
gfnTotal = gfnTotal + Val(sNumber)
END

EDT_DISPLAY1 = gfnTotal+gfsCurrencyDisp

// insert a thousand separator
ThouSepar()

IF Length(EDT_DISPLAY1)>18 THEN
EDT_DISPLAY1="ERR"
gfnTotal=0
END

gfbCalculate = True
END

gfsLastOp = sLastOp


Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
No review or comment? Be the first one!