i'm trying to write a simple currency converter that will show several currencies at the same time. the idea is that if i key-in in one edit-box the others would change as well.
however this does not happen. the numbers are continuously processed. can someone take a look and help me find the bug?
Code:
#Persistent
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
SetFormat, Float, 0.2
currencydataxml := A_ScriptDir "\Resources\Rates\eurofxref-daily.xml"
imageDir := A_ScriptDir "\Resources\Images"
euro_rate := 1 ; Euro is the base rate
IfNotExist, %currencydataxml%
{
Text=Downloading the latest currency rates.
SplashImage, , b CTWhite CW000000 fs12, %Text%.
URLDownloadToFile, http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml, %currencydataxml%
Sleep, 4000
SplashImage, Off
}
path = %currencydataxml%
xpath_load(rss, path)
date1 := XPath(rss, "/gesmes:Envelope/Cube/Cube/@time/text()")
currency1 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""JPY""]/@currency/text()")
rate1 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""JPY""]/@rate/text()")
currency2 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""USD""]/@currency/text()")
rate2 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""USD""]/@rate/text()")
currency3 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""GBP""]/@currency/text()")
rate3 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""GBP""]/@rate/text()")
currency4 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""SGD""]/@currency/text()")
rate4 := XPath(rss, "/gesmes:Envelope/Cube/Cube/Cube[@currency=""SGD""]/@rate/text()")
GoSub, LoadGUI
Return
LoadGUI:
Gui, Font, S7 CDefault, Verdana
Gui, Add, GroupBox, x6 y6 w290 h150 , Last Update: %date1%
Gui, Font, S10 CDefault, Verdana
Gui, Font, W700
Gui, Add, Picture, x26 y35 , %imageDir%\flag_jpy.png
Gui, Add, Text, xp+40 y35 w100 h20 , JPY
Gui, Add, Edit, xp+120 y35 w90 h20 vEdit1 gEditNum, 0.00
Gui, Add, Picture, x26 y60 , %imageDir%\flag_usd.png
Gui, Add, Text, xp+40 y60 w100 h20 , USD
Gui, Add, Edit, xp+120 y60 w90 h20 vEdit2 gEditNum, 0.00
Gui, Add, Picture, x26 y85 , %imageDir%\flag_gbp.png
Gui, Add, Text, xp+40 y85 w100 h20 , GBP
Gui, Add, Edit, xp+120 y85 w90 h20 vEdit3 gEditNum, 0.00
Gui, Add, Picture, x26 y110 , %imageDir%\flag_sgd.png
Gui, Add, Text, xp+40 y110 w100 h20 , SGD
Gui, Add, Edit, xp+120 y110 w90 h20 vEdit4 gEditNum, 0.00
Gui, Show, Center, Currency Convertor
Return
EditNum: ;--- update converted figures
Gui, Submit, NoHide
If (A_GuiControl = "Edit1")
{
GuiControlGet, Numb,,%A_GuiControl%
If Numb is Number
{
ControlSetText, Edit2, % (euro_rate/rate2)/(euro_rate/Numb)
ControlSetText, Edit3, % (euro_rate/rate3)/(euro_rate/Numb)
ControlSetText, Edit4, % (euro_rate/rate4)/(euro_rate/Numb)
}
}
Else If (A_GuiControl = "Edit2")
{
GuiControlGet, Numb,,%A_GuiControl%
If Numb is Number
{
ControlSetText, Edit1, % (euro_rate/rate1)/(euro_rate/Numb)
ControlSetText, Edit3, % (euro_rate/rate3)/(euro_rate/Numb)
ControlSetText, Edit4, % (euro_rate/rate4)/(euro_rate/Numb)
}
}
Else If (A_GuiControl = "Edit3")
{
GuiControlGet, Numb,,%A_GuiControl%
If Numb is Number
{
ControlSetText, Edit1, % (euro_rate/rate1)/(euro_rate/Numb)
ControlSetText, Edit2, % (euro_rate/rate2)/(euro_rate/Numb)
ControlSetText, Edit4, % (euro_rate/rate4)/(euro_rate/Numb)
}
}
Else If (A_GuiControl = "Edit4")
{
GuiControlGet, Numb,,%A_GuiControl%
If Numb is Number
{
ControlSetText, Edit1, % (euro_rate/rate1)/(euro_rate/Numb)
ControlSetText, Edit2, % (euro_rate/rate2)/(euro_rate/Numb)
ControlSetText, Edit3, % (euro_rate/rate3)/(euro_rate/Numb)
}
}
Return
GuiEscape:
GuiClose:
ExitApp
Return