Jump to content

Get specific numbers from website


Recommended Posts

Hello everyone, thank you for helping me out. I program with AutoIT Script for about 2-3 months, so I am trying to get familiar with it. I created a roll-over rate calculator because I thought that was pretty interesting. I put the source code and the application on my website.

http://www.hau-wai-kit.com/Rollover_calculator

It can calculate the roll-over rate if the user enters which currency pairs they want to trade, the currency exchange rate of the currency pairs, and both of the currency's interest rate. Users need to enter all these rates manually, which means they need to go to the central bank website, check the rate and enter into the application. I want to make this application easier for general use. 

So is there any way to get numbers/rate from website directly? Thank you so much.

Link to comment
Share on other sites

To get information from a web site you could either use the browser specific UDFs or function INetGet.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here are 2 examples using _IE* funcs

#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate("http://www.xe.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 0)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
For $i = 2 To 6 step 2
   For $j = 10 to 1 step -1
      $aTableData[$i][$j] = $aTableData[$i][$j-1] 
   Next
Next
_ArrayDisplay($aTableData)
#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
_ArrayDisplay($aTableData)

The IE way is efficient but slow so you can also do like this :

$html = BinaryToString(InetRead("http://www.dailyfx.com/"))
$txt = StringRegExpReplace($html, '(?s).+?bank-rates-widget-table.+?<tr>(.+?)</tbody>.+', '$1')
$titles = StringRegExp($txt, '<th.*?>([^<]+)', 3)
$rates= StringRegExp($txt, '<td.*?>([^<]+)', 3)
Dim $array[UBound($rates)/3+1][3]
For $i = 0 to 2
      $array[0][$i] = $titles[$i]
Next
For $i = 0 to UBound($array)-2
      $array[$i+1][0] = $rates[$i*3]
      $array[$i+1][1] = $rates[$i*3+1]
      $array[$i+1][2] = $rates[$i*3+2]
Next
_ArrayDisplay($array)
Edited by mikell
Link to comment
Share on other sites

Glad to be of service :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Dear Mr: mikell:

At this moment, I have 2 questions I do not quite understand. The first one is, I understand you got the inverse rates from www.xe.com by using the loop (those msgbox are there just for me to look at those values)

For $i = 2 To 6 step 2
   For $j = 10 to 1 step -1
      $aTableData[$i][$j] = $aTableData[$i][$j-1] 
      msgbox(0,"i",$i)
      msgBox(0,"j",$j)   
      msgBox(0,"j",$aTableData[$i][$j-1])
      msgBox(0,"j",$aTableData[$i][$j])
   Next
Next

But how did you get those non-inverse ones? Even though I saw the pop up table shows both non-inverse rates and the inverse rates, I do not find the loop that get the non-inverse rates. Sorry if my question is a little bit stupid.

 

and my second question is: from this line, why is the $i_index = 18? how do I determine that? Thank you so much for your help.

$oTable = _IETableGetCollection($oIE, 18)
Link to comment
Share on other sites

For the 1st question : _IETableWriteToArray()  grabs all the needed data but returns a shifted table, as you can see if you comment the whole loop, so the loop is used to fix this and provide a correct range (and a clean display)

2nd question :

the index for the desired table is not easy to find so we have to use a trick

In the source code the id of this table is "bank-rates-widget-table", so I did it like this (I didn't mention this, sorry)

#include <IE.au3>
;#include <Array.au3>

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)

$oTables = _IETableGetCollection($oIE)  ; get the collection
$n = 0
For $oTable In $oTables   ; search the tables
  If $oTable.id == "bank-rates-widget-table" Then Exitloop  ; please note the '==' because '=' wont work
  $n += 1
Next
msgbox(0,"", "the table we look for is at index : " & $n)

#cs
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
_ArrayDisplay($aTableData)
#ce
Edited by mikell
Link to comment
Share on other sites

 

For the 1st question : _IETableWriteToArray()  grabs all the needed data but returns a shifted table, as you can see if you comment the whole loop, so the loop is used to fix this and provide a correct range (and a clean display)

2nd question :

the index for the desired table is not easy to find so we have to use a trick

In the source code the id of this table is "bank-rates-widget-table", so I did it like this (I didn't mention this, sorry)

#include <IE.au3>
;#include <Array.au3>

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)

$oTables = _IETableGetCollection($oIE)  ; get the collection
$n = 0
For $oTable In $oTables   ; search the tables
  If $oTable.id == "bank-rates-widget-table" Then Exitloop  ; please note the '==' because '=' wont work
  $n += 1
Next
msgbox(0,"", "the table we look for is at index : " & $n)

#cs
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
_ArrayDisplay($aTableData)
#ce

Thank you Mr.kikell for the explanation, and now I understand how they work.

I created 2 buttons. One for getting the interest rate table and another one for getting the exchange rate. And I found that one table must be closed before another opens. (They can not display together)

Then I tried to find a way to allow 2 tables show up together, and I found one tutorial about interrupt. http://www.autoitscript.com/wiki/Interrupting_a_running_function

But they used for loop to keep checking for interrupt. Does that mean interrupt can not be used in my code? or are there any way to let 2 tables show up together?

Thank you once again for your time. I am learning a lot from you!

Link to comment
Share on other sites

Here is a quick example of what you need

#include <IE.au3>
;#include <Array.au3>

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
;_ArrayDisplay($aTableData)

GuiCreate("test", 280, 200)
$listview = GUICtrlCreateListView("Currency|CB Rate|O. Rate ", 10, 10, 260, 180)
For $i = 1 To UBound($aTableData)-1
   GUICtrlCreateListViewItem($aTableData[$i][0] &"|"& $aTableData[$i][1] &"|"& $aTableData[$i][2], $listview)
Next
GUISetState()

While GUIGetMsg()<>-3
Wend
Edited by mikell
Link to comment
Share on other sites

 

Here is a quick example of what you need

#include <IE.au3>
;#include <Array.au3>

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
;_ArrayDisplay($aTableData)

GuiCreate("test", 280, 200)
$listview = GUICtrlCreateListView("Currency|CB Rate|O. Rate ", 10, 10, 260, 180)
For $i = 1 To UBound($aTableData)-1
   GUICtrlCreateListViewItem($aTableData[$i][0] &"|"& $aTableData[$i][1] &"|"& $aTableData[$i][2], $listview)
Next
GUISetState()

While GUIGetMsg()<>-3
Wend

Thank you so much. I have a question. Below is the code of my rollover rate calculator application. I added a menu item "Request both rates" that allows users to look at the 2 tables with exchange rates and interest rate.

But when I tried to close the table, it would not close. And when I pressed "close" one more time, it closed the whole application. I want to see if this is normal.

#include <IE.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=C:\Users\Ric\Desktop\au3\Roll_Over_Calculator.kxf
Global $MaxArrayItem = 30
Global $MaxArrayItem_2 = 11
Global $ComboArray[$MaxArrayItem] = ["-- Major Currency Pairs --", "EUR/USD", "USD/JPY", "GBP/USD", "USD/CHF", "USD/CAD", "AUD/USD", "NZD/USD", "-- Minor Currency Pairs --", "EUR/CHF", "EUR/GBP", "EUR/CAD", "EUR/AUD", "EUR/NZD", "EUR/JPY", "GBP/JPY", "CHF/JPY", "CAD/JPY", "AUD/JPY", "NZD/JPY", "GBP/CHF", "GBP/AUD", "GBP/CAD", "GBP/NZD", "AUD/CHF", "AUD/CAD", "AUD/NZD", "CAD/CHF", "NZD/CHF","NZD/CAD"]
Global $ComboArray_2[$MaxArrayItem_2] = ["-- Other Currency Pairs --","EUR/TRY", "USD/TRY", "USD/SEK", "USD/NOK", "USD/DKK", "USD/ZAR", "USD/HKD", "USD/SGD", "USD/THB", "USD/MXN"]

Global $MaxArrayItem_Contract_Size = 3
Global $ComboArray_Contract_Size[$MaxArrayItem_Contract_Size] = ["Standard Lot", "Mini Lot", "Micro Lot"]

$Roll_Over_Calculator = GUICreate("Roll Over Calculator", 615, 440, 192, 124)
$Group1 = GUICtrlCreateGroup(" Roll Over Calculator  ", 24, 32, 561, 393)
$Label1 = GUICtrlCreateLabel("Please select the currency pairs you are buying/selling in:", 40, 72, 274, 17)
$Combo1 = GUICtrlCreateCombo("", 320, 72, 121, 25, BitOR($CBS_DROPDOWNLIST ,$CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button3 = GUICtrlCreateButton("More", 450, 70, 105, 25)
$Exchange_Rate_Label = GUICtrlCreateLabel("The currency exchange rate: ", 173, 101, 140, 17)
$Exchange_Rate_Input = GUICtrlCreateInput("", 320, 99, 121, 20)
$Button4 = GUICtrlCreateButton("Set Currency Pairs", 450, 95, 105, 25)

GUICtrlSetData($Combo1, "|")
   For $i = 0 To 29
      GUICtrlSetData($Combo1, $ComboArray[$i])
   Next
   
$Label2 = GUICtrlCreateLabel("'s Currenly Interest Rate:", 32, 128, 160, 17)
$Label3 = GUICtrlCreateLabel("'s Currenly Interest Rate:", 32, 160, 160, 17)
$Input1 = GUICtrlCreateInput("", 170, 128, 89, 21)
$Input2 = GUICtrlCreateInput("", 170, 160, 89, 21)
$Label4 = GUICtrlCreateLabel("Contract Size:", 280, 192, 70, 17)
$Input3 = GUICtrlCreateInput("", 360, 192, 41, 21)

$check1 = GUICtrlcreateCheckbox("", 32, 192, 20, 20)
$check2 = GUICtrlcreateCheckbox("", 150, 192, 20, 20)
$Label_checkbox1 = GUICtrlCreateLabel("Buy ", 55, 195, 80, 17)
$Label_checkbox2 = GUICtrlCreateLabel("Sell ", 170, 195, 80, 17)

$Combo2 = GUICtrlCreateCombo("-- Contract Type --", 416, 192, 121, 25, BitOR($CBS_DROPDOWNLIST ,$CBS_DROPDOWN,$CBS_AUTOHSCROLL))

GUICtrlSetData($Combo2, "|")
   For $i = 0 To 2
      GUICtrlSetData($Combo2, $ComboArray_Contract_Size[$i])
   Next
   
$Label5 = GUICtrlCreateLabel("For the Contract Size, please enter the amount and the lot type.", 280, 128, 302, 17)
$Label6 = GUICtrlCreateLabel("Example: 2 Standard Lot", 280, 152, 120, 17)
$Button1 = GUICtrlCreateButton("Calculate", 112, 248, 105, 25)
$Button2 = GUICtrlCreateButton("Reset", 352, 248, 105, 25)
$Label7 = GUICtrlCreateLabel("Result of Calculation:", 40, 312, 104, 17)
$Label9 = GUICtrlCreateLabel("Daily Rate Received:", 40, 352, 400, 17)
;$Label9 = GUICtrlCreateLabel("Daily Rate Received:", 304, 352, 200, 17)
$menu1 = GuiCtrlCreateMenu("File")
$help = GuiCtrlCreateMenuItem("Help", $menu1)
$exit = GuiCtrlCreateMenuItem("Exit", $menu1)
$menu2 = GuiCtrlCreateMenu("Request Rates")
$request_interest_rate = GuiCtrlCreateMenuItem("Request Interest Rate", $menu2)
$request_exchange_rate = GuiCtrlCreateMenuItem("Request Exchange Rate", $menu2)
$request_both_rate = GuiCtrlCreateMenuItem("Request Both Rates", $menu2)
GUICtrlCreateGroup("", -99, -99, 1, 1)

   Global $Base
   Global $Quote


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
       
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            Calculate()
         Case $Button2
            Reset()
        Case $Button3
            More_Pairs()
        Case $Button4
            Set_Currency_Pairs()            
        Case $help
            Help()
        Case $exit()
            Exit_Func()
        Case $request_interest_rate
            Request_interest_rate()
        Case $request_exchange_rate
            Request_exchange_rate()
         Case $request_both_rate
            Request_both_rate()
    EndSwitch
WEnd

Func Request_both_rate()

$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)
$eIE = _IECreate("http://www.xe.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 18)
$eTable = _IETableGetCollection($eIE, 0)
$aTableData = _IETableWriteToArray($oTable, 1)
$eTableData = _IETableWriteToArray($eTable, 1)
_IEQuit($oIE)
_IEQuit($eIE)

For $i = 2 To 6 step 2
   For $j = 10 to 1 step -1
      $eTableData[$i][$j] = $eTableData[$i][$j-1] 
   Next
Next
GuiCreate("Currency Rate and Exchange Rate", 650, 500)
$listview = GUICtrlCreateListView("Currency|Central Bank Rate|Overnight Rate ", 10, 10, 303, 180)
For $i = 1 To UBound($aTableData)-1
   GUICtrlCreateListViewItem($aTableData[$i][0] &"|"& $aTableData[$i][1] &"|"& $aTableData[$i][2], $listview)
Next
GUISetState()

$listview = GUICtrlCreateListView("Currecny|USD|EUR|GBP|INR|AUD|CAD|ZAR|NZD|JPY ", 10, 200, 630, 280)
For $i = 1 To UBound($eTableData)-1
   GUICtrlCreateListViewItem($eTableData[$i][1] &"|"& $eTableData[$i][2]&"|"& $eTableData[$i][3]&"|"& $eTableData[$i][4]&"|"& $eTableData[$i][5]&"|"& $eTableData[$i][6]&"|"& $eTableData[$i][7]&"|"& $eTableData[$i][8]&"|"& $eTableData[$i][9]&"|"& $eTableData[$i][10], $listview)
Next
GUISetState()

While GUIGetMsg()<>-3
Wend
EndFunc

Func Request_interest_rate() 
$oIE = _IECreate("http://www.dailyfx.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
_ArrayDisplay($aTableData)
EndFunc


Func Request_exchange_rate()
$oIE = _IECreate("http://www.xe.com/", 0, 0)
$oTable = _IETableGetCollection($oIE, 0)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
For $i = 2 To 6 step 2
   For $j = 10 to 1 step -1
      $aTableData[$i][$j] = $aTableData[$i][$j-1] 
   Next
Next
_ArrayDisplay($aTableData)
EndFunc

Func Calculate()
   Global $Base_Input = GUICtrlRead($Input1)
   Global $Quote_Input = GUICtrlRead($Input2)
   Global $Contract_amount = GUICtrlRead($Input3)
   Global $Contract_type = GUICtrlRead($Combo2)
   Global $Check1_input = GUICtrlRead($check1)
   Global $Check2_input = GUICtrlRead($check2)
   Global $Exchange_Rate = GUICtrlRead($Exchange_Rate_Input)
   
 
      if $Base = "" AND $Quote = "" Then
         msgbox(0,"No selected currency pair", "Please select a currency pair.")
      ElseIf $Exchange_Rate = "" Then
         msgbox(0,"Empty Input", "Please enter the current exchange rate of the currency pair.") 
      ElseIf StringIsInt($Exchange_Rate) = 0 And StringIsFloat($Exchange_Rate) = 0 Then
         msgbox(0,"Incorrect Input", "Please enter the correct value for the exchange rate.")  
      ElseIf $Base_Input = "" Or $Quote_Input = "" Then
         msgbox(0,"Empty Inputs", "Please make sure you enter the interest rate for both currencies.")
      ElseIf StringIsInt($Base_Input) = 0 And StringIsFloat($Base_Input) = 0 Then
         msgbox(0,"Incorrect type of Inputs", "Please make sure your enter correct value for the Base currency's interest rate.")
      ElseIf StringIsInt($Quote_Input) = 0 AND StringIsFloat($Quote_Input) = 0 Then
         msgbox(0,"Incorrect type of Inputs", "Please make sure your enter correct value for the Quote currency's interest rate.")
      ElseIf $Contract_amount = "" Or $Contract_type = "" Then
         msgbox(0,"Empty Contract Size", "Please enter the value and the type of your contract size.")
      ElseIf StringIsInt($Contract_amount) = 0 And StringIsFloat($Contract_amount) = 0 Then
         msgbox(0,"Incorrect type of Inputs", "Please enter correct value for the value of your contract size.")
      ElseIf BitAnd($Check1_input, $GUI_CHECKED)  And BitAnd($Check2_input, $GUI_CHECKED) Then
         msgbox(0,"Both checkboxes are checked", "Please choose either buy or sell.")
      ElseIf BitAnd($Check1_input, $GUI_UNCHECKED)  And BitAnd($Check2_input, $GUI_UNCHECKED) Then
         msgbox(0,"No Decision", "Please choose either buy or sell.")
      Else                      
                        if $Contract_type = "Standard Lot" Then
                              
                              $lot_size = 100000
                              Call("Calculation_Start", $lot_size, $Contract_amount)
                              
                              if BitAnd($Check1_input, $GUI_CHECKED) Then
                                    GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote & "   or   " & Round($Result_to_match_base,6) & " " & $Base)
                              Else
                                    GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_base,6) & " " & $Quote & "   or   " & Round($Selling_Result_to_match_quote,6) & " " & $Base)
                              EndIf
                                 
                        ElseIf $Contract_type = "Mini Lot" Then
                           
                              $lot_size = 10000
                              Call("Calculation_Start", $lot_size, $Contract_amount)
                              
                              if BitAnd($Check1_input, $GUI_CHECKED) Then
                                 GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote & "   or   " & Round($Result_to_match_base,6) & " " & $Base)
                              Else
                                 GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_quote,6) & " " & $Quote & "   or   " & Round($Selling_Result_to_match_base,6) & " " & $Base)
                              EndIf
                              
                        Else
                        
                              $lot_size = 1000
                              Call("Calculation_Start", $lot_size, $Contract_amount)
                              
                           if BitAnd($Check1_input, $GUI_CHECKED) Then
                              GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote  & "    or    " & Round($Result_to_match_base,6) & " " & $Base)
                           Else
                              GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_base,6) & " " & $Quote & "   or   " & Round($Selling_Result_to_match_quote,6) & " " & $Base)
                           EndIf
                        
                        EndIf

         
      EndIf
EndFunc

Func Calculation_Start($lot_size, $Contract_amount)
   
   
                              ;Calculating First base currency:
                              $total_size = $lot_size * $Contract_amount
                              $Base_currency_interest_yearly = ($total_size * $Base_Input)/100
                              $Base_currency_interest_daily = $Base_currency_interest_yearly/365
                              
                              
                              ;Calculating Second Quote currency:
                              $Total_Quote_currency_after_exchange_rate = $total_size * $Exchange_Rate
                              $Quote_currency_interest_yearly = ($Total_Quote_currency_after_exchange_rate * $Quote_Input)/100
                              $Quote_currency_interest_daily = $Quote_currency_interest_yearly/365
                              
                              
                              ;Converting Base currency to same currency type                             
                              $After_convert_to_match_quote = $Base_currency_interest_daily * $Exchange_Rate
                              
                              $After_convert_to_match_base = $Quote_currency_interest_daily / $Exchange_Rate
                              
                              
                              ;Get the result
                              Global $Result_to_match_quote = $After_convert_to_match_quote - $Quote_currency_interest_daily
                              Global $Result_to_match_base = $Base_currency_interest_daily - $After_convert_to_match_base
                              
                              ;For Selling
                              Global $Selling_Result_to_match_quote = $Quote_currency_interest_daily - $After_convert_to_match_quote 
                              Global $Selling_Result_to_match_base = $After_convert_to_match_base - $Base_currency_interest_daily
                             
EndFunc

Func More_Pairs()   
   $Combo_count = _GUICtrlComboBox_GetCount($Combo1)
   if $Combo_count = 30 Then
              GUICtrlSetData($Combo1, "|")
            For $i = 0 To 10
               GUICtrlSetData($Combo1, $ComboArray_2[$i])
            Next
   Else
            GUICtrlSetData($Combo1, "|")
            For $i = 0 To 29
               GUICtrlSetData($Combo1, $ComboArray[$i])
            Next
   EndIf
EndFunc

Func Set_Currency_Pairs()
   $Currency_Pair = GUICtrlRead($Combo1)
   
   if $Currency_Pair = "-- Major Currency Pairs --" Then 
      msgbox(0,"Selection Error","Please select a currency pair")
   ElseIf $Currency_Pair = "-- Minor Currency Pairs --" Then 
      msgbox(0,"Selection Error","Please select a currency pair")
   Elseif $Currency_Pair = "-- Other Currency Pairs --" Then
      msgbox(0,"Selection Error","Please select a currency pair")
   Elseif $Currency_Pair = "" Then
      msgbox(0,"Selection Error","Please select a currency pair")
   Elseif _GUICtrlComboBox_SelectString($Combo1,$Currency_Pair) = -1 And _GUICtrlComboBox_SelectString($Combo2,$Currency_Pair) = -1 Then
      msgbox(0,"No such currency pair.","No such currency pair.")
   Else
      $Currency_Pair_Split = StringSplit($Currency_Pair, "/")
      Global $Base = $Currency_Pair_Split[1]
      Global $Quote = $Currency_Pair_Split[2]
      GUICtrlSetData($Label2, $Base & "'s Currenly Interest Rate:")
      GUICtrlSetData($Label3, $Quote & "'s Currenly Interest Rate:")
      
      GUICtrlSetData($Label_checkbox1, "Buy " & $Currency_Pair)
      GUICtrlSetData($Label_checkbox2, "Sell " & $Currency_Pair)
   EndIf
EndFunc

Func Help()
   msgBox(0, "Help", "The calculator is implemented according to the RollOver Rate tutorial in DailyFx, Please go to the link below to check out the tutorial!" & @LF & "" & @LF& "http://www.dailyfx.com/forex/education/learn_forex/the_basics/making_a_forex_trade/4/2009-10-14-0101-Rollover.html ")
EndFunc

Func Exit_Func()
   $exit_confirm = msgBox(4, "Exit the Application", "Do you want to exit this application?")
   if $exit_confirm = 6 Then
      Exit
   EndIf
EndFunc

Func Reset()
   GUICtrlSetData($Input1, "")
   GUICtrlSetData($Input2, "")
   GUICtrlSetData($Input3, "")
   GUICtrlSetData($Exchange_Rate_Input , "")
   GUICtrlSetState($Check1,$GUI_UNCHECKED)
   GUICtrlSetState($Check2,$GUI_UNCHECKED)
   
EndFunc
Link to comment
Share on other sites

Obviously not :)

In such cases EventMode is better but you can manage this using GuiGetMsg()

Here is the main shema (have a look in the helpfile at GuiGetMsg with 'advanced' parameter)

Func Request_both_rate()
   ; ....
   $rates_gui = GuiCreate(...)
   GUISetState()

   While 1
      $nMsg = GUIGetMsg(1)
      Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            If $nMsg[1] = $Roll_Over_Calculator Then Exit
            If $nMsg[1] = $rates_gui Then Exitloop
      EndSwitch
   Wend
   GuiDelete($rates_gui)
EndFunc
Edited by mikell
Link to comment
Share on other sites

 

Obviously not :)

In such cases EventMode is better but you can manage this using GuiGetMsg()

Here is the main shema (have a look in the helpfile at GuiGetMsg with 'advanced' parameter)

Func Request_both_rate()
   ; ....
   $rates_gui = GuiCreate(...)
   GUISetState()

   While 1
      $nMsg = GUIGetMsg(1)
      Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            If $nMsg[1] = $Roll_Over_Calculator Then Exit
            If $nMsg[1] = $rates_gui Then Exitloop
      EndSwitch
   Wend
   GuiDelete($rates_gui)
EndFunc

Thank you very much. I looked at the document, tried the code and it worked!

Have a nice day and thanks once again

Link to comment
Share on other sites

Glad I could help

BTW  loading the data takes several seconds and during this time the application looks stuck, so you should use a trick like this

#include <IE.au3>
;#include <Array.au3>

$n = 0
SplashTextOn ("", "Loading Data ...  " & $n, 280, 55, -1, -1, 49)
$oIE = _IECreate("http://www.dailyfx.com/", 0, 0, 0)
While $oIE.Busy
   $n += 1
   SplashTextOn ("", "Loading Data ...  " & $n, 280, 55, -1, -1, 49)
   Sleep(1000)
Wend
SplashTextOn ("", "Loading Data ...  Done", 280, 55, -1, -1, 49)
Sleep(1500)
$oTable = _IETableGetCollection($oIE, 18)
$aTableData = _IETableWriteToArray($oTable, 1)
_IEQuit($oIE)
;_ArrayDisplay($aTableData)
SplashOff()

GuiCreate("test", 280, 200)
$listview = GUICtrlCreateListView("Currency|CB Rate|O. Rate ", 10, 10, 260, 180)
For $i = 1 To UBound($aTableData)-1
   GUICtrlCreateListViewItem($aTableData[$i][0] &"|"& $aTableData[$i][1] &"|"& $aTableData[$i][2], $listview)
Next
GUISetState()

While GUIGetMsg()<>-3
Wend
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...