Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules
Private countries As List
Private fromCountry, toCountry, FromTo As String
Private XRate As HttpJob
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Portrait")
Canvas1.Initialize(Activity)
XRate.Initialize("currency", Me)
End Sub
Sub CurrencyFrom
'Load list with countries
If countries.IsInitialized = False Then countries.Initialize
If countries.Size = 0 Then countries = File.ReadList(File.DirAssets, "CountryCodes.txt"): countries.Sort(True)
'"CountryCodes.txt" is a list from Erel's Currency Converter example.
End Sub
Sub ConvFromView_ItemClick (Position As Int, Unit As Object)
If Not(F_common) Then Return
Private temp As String = 1
fromCountry = "ABC"
Select AllData
Case 0: temp = LengthData(Position,2)
Case 1: temp = AreaData(Position,2)
Case 2: temp = VolumeData(Position,2)
Case 3: temp = MassData(Position,2)
Case 4: temp = SpeedData(Position,2)
Case 5: temp = PowerData(Position,2)
Case 6: fromCountry = countries.get(Position)
End Select
fromCountry = fromCountry.SubString2(0, 3) 'Gets 3 letter code representing the countries currency IE USD
ConvertCommon = Disp / temp
ConvFromView.RemoveView 'Exit ListView.
lblTitle.Top = 0%y
ListBack.Top = lblTitle.Top
lblTitle.SendToBack
ListBack.SendToBack
CallSub("",NextConvTo) 'Sub CurrencyTo
End Sub
Sub ConvToView_ItemClick (Position As Int, ResultsValue As Object)
Private temp As String
toCountry = "ABC"
Select AllData
Case 0: Disp = LengthData(Position,3): temp = LengthData(Position,1)
Case 1: Disp = AreaData(Position,3): temp = AreaData(Position,1)
Case 2: Disp = VolumeData(Position,3): temp = VolumeData(Position,1)
Case 3: Disp = MassData(Position,3): temp = MassData(Position,1)
Case 4: Disp = SpeedData(Position,3): temp = SpeedData(Position,1)
Case 5: Disp = PowerData(Position,3): temp = PowerData(Position,1)
Case 6: toCountry = countries.get(Position)
End Select
toCountry = toCountry.SubString2(0, 3)
If AllData <> 6 Then 'Do for all except Currency
Buffer = ""
StackPush
send_to_display(Disp)
If Two_flag = 1 Then
Idisplay.Text = IDispTXT
Two_flag = 0
End If
Idisplay.Text = temp
Else
FromTo = fromCountry&toCountry
XRate.Download("http://finance.yahoo.com/d/quotes.csv?s="&FromTo&"=X&f=l1") 'Gets conversion rate between 2 currency's
End If
ConvToView.RemoveView 'Exit ListView.
lblTitle.Top = 0%y
ListBack.Top = lblTitle.Top
lblTitle.SendToBack
ListBack.SendToBack
ListFlag = 0
ConvToView.Initialize("ConvToView")
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
Private Rate, FromDisp, ToDisp As String 'result,i, i2,
Private ToResult, FromAmmount As Double
FromAmmount = Rdisplay.Text
Rate = job.GetString
If Rate < 0 Then
Msgbox("Invalid response.", "Error")
Return
End If
If IsNumber(Rdisplay.Text) = False Then
Msgbox("Please enter a valid number.", "Error")
Return
End If
' Set the answer
FromDisp = Rdisplay.Text&" "&fromCountry
ToResult = Rate * FromAmmount
ToResult = NumberFormat2(ToResult,1,2,2,False)
ToDisp = ToResult&" "&toCountry&" "
If ToResult = 0 Or ToResult < 0 Then ToDisp = "---- "&toCountry&" "
If IsNumber(ToResult) = False Then ToDisp = "---- "&toCountry&" "
Rdisplay.Text = FromDisp
Idisplay.Text = ToDisp
Else
ToastMessageShow ( "Error connecting to server.", True)
End If
job.Release
End Sub