ronnie32 Posted March 29, 2016 Posted March 29, 2016 Hello there, I just started AutoIT recently and already need some help. What I'm trying to perform in my script: Comparing a sequence of numbers that are stored in my database; from a starting number I put in the inputbox The sequence must be: Quote Number 1: starting Number Number 2: Number 1 + 12345 Number 3: Number 2 + 12345 And so on until Number 10 (this is where I'm lost) Put these numbers in a ListView (ok) Save the results in a txt file (ok) Here is my piece of code so far: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include "WinHttp.au3" #include <String.au3> #include <Array.au3> $hGUI = GUICreate("Window", 500, 400, -1, -1) $hInput = GUICtrlCreateInput("Input", 37, 24, 159, 21) $hButton = GUICtrlCreateButton("Ok", 216, 22, 42, 22) $hListView = GUICtrlCreateListView("Number|Correct|Exp|Type", 43, 65, 213, 204) GUISetState() While 1 $hMsg = GUIGetMsg() Switch $hMsg Case $GUI_EVENT_CLOSE Exit Case $hButton _OpenLink() EndSwitch WEnd Func _OpenLink() $hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0') $sHost = '127.0.0.1' $sReq = _WinHttpConnect($hSession, $sHost, $INTERNET_DEFAULT_HTTPS_PORT) $Num = GuiCtrlRead($hInput) $NumAft = ($Num+12345) $sResponse = _WinHttpSimpleSSLRequest($sReq, 'GET', '/index.php?chk=' & $NumAft ) Dim $valDateChk $ExpDate = _StringBetween($sResponse,'"expdate":"', '"}') $Type = _StringBetween($sResponse,'"type":"', '"') If StringInStr($sResponse, 'OK') Then GUICtrlCreateListViewItem($NumAft & "| Yes" & "|" & $ExpDate[0] & "|" & $Type[0], $hListView) Else GUICtrlCreateListViewItem($NumAft & "| No", $hListView) EndIf EndFunc I'm not sure I would have to use loops or while...If someone could point me to a direction with an example, I would be grateful.
rodent1 Posted March 29, 2016 Posted March 29, 2016 (edited) in a while statement of the type while with an entrance condition such as $a < $b, to enter the first loop, you need to have a value for $a and $b. If that value is going to be generated first during the first loop, you should use the do/until loop so you can check the exit condition instead. Of course, if you use "while 1", this does not apply. Edited March 29, 2016 by rodent1 Found that I forgot an important word when reading the post
JohnOne Posted March 29, 2016 Posted March 29, 2016 #include <Array.au3> Local $StartingNumber = 23 Local $Increment = 12345 Local $array[10] _ArrayDisplay($array) For $i = 0 To 9 if $i > 0 Then $array[$i] = $array[$i -1] + $Increment Else $array[$i] = $StartingNumber EndIf Next _ArrayDisplay($array) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
ronnie32 Posted March 30, 2016 Author Posted March 30, 2016 Thanks everyone for the help!!! Now I'm trying to save the results in a text file, I assume _FileWriteFromArray is what I need, problem the file is empty: Here is my function so far: Func _OpenLink() Local $StartingNumber = GuiCtrlRead($hInput) Local $Increment = 12345 Local $array[4] Local $valDateChk $aListView = _GuiCtrlListView_CreateArray($hListView, Default) $hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0') $sHost = '127.0.0.1' $sReq = _WinHttpConnect($hSession, $sHost, $INTERNET_DEFAULT_HTTPS_PORT) For $i = 0 To 3 if $i > 0 Then $array[$i] = $array[$i -1] + $Increment $sResponse = _WinHttpSimpleSSLRequest($sReq, 'GET', '/index.php?chk=' & $array[$i] ) $ExpDate = _StringBetween($sResponse,'"expdate":"', '"}') $Type = _StringBetween($sResponse,'"type":"', '"') If StringInStr($sResponse, 'true') Then $GetIt = GUICtrlCreateListViewItem($array[$i] & "| Yes" & "|" & $ExpDate[0] & "|" & $Type[0], $hListView) Else GUICtrlCreateListViewItem($array[$i] & "| No", $hListView) EndIf _FileWriteFromArray("test.txt", $GetIt) Else $array[$i] = $StartingNumber EndIf Next EndFunc Also, I'm wondering if it would be possible to sort the results in the same text file all the corrects numbers together and all the invalid together, or I think saving them in 2 different files by implementing the saves in if conditions would be a better idea and would require way less hassle.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now