JohnWilson Posted June 2, 2014 Posted June 2, 2014 (edited) Hello All, I am new to autoit, and am writing a script that gives a user an opportunity to install printers on the same subnet they are on. In order to accomplish this, I have created a function that grabs the third octet of their IP and then matches that octet with a list of printers in a text file by line number. Then it takes those lines and puts them into an array. How is it that I can create a checkbox for each item of an array and position them properly. I have looked around but have not had any luck as to how to accomplish this. The code I have started with is below, but this only creates one checkbox, even though the array has 6 items in it. What am I doing wrong? For $test in $aResult $firstpart = StringSplit($tester, ",") $final = $firstpart[1] GUISetCoord(10, 10) ;sets X, Y coordinates GUICtrlCreateCheckbox ($final, -1 +50, -1 +50, 255, 17) Thanks for any help you can give! Edited June 2, 2014 by JohnWilson
UEZ Posted June 2, 2014 Posted June 2, 2014 This is only a fragment of the whole script. I would make more sense to post the full code to understand your problem properly. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
JohnWilson Posted June 2, 2014 Author Posted June 2, 2014 Sure thing, he is the whole code. expandcollapse popup#include <MsgBoxConstants.au3> #include <File.au3> #include <array.au3> #include <InetConstants.au3> #include <GuiButton.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #requireadmin Func Octet() ; Creates array called parsed ip, with each octet of the IP address as different items Global $parsedip = StringSplit(@IPAddress1, ".") ; Creates variable called third which grabs only the third octet Global $third = $parsedip[3] EndFunc Octet() Local $sFileName = "C:\Testing\test.txt" Local $searchStr = $third $aResult = _LineNumsOfSearchStr($sFileName, $searchStr, False) _ArrayDisplay($aResult) For $test in $aResult $tester = FileReadLine ( $sFileName, $test ) MsgBox($MB_SYSTEMMODAL, "", "For..IN Arraytest:" & @CRLF & "Result is: " & @CRLF & $tester) InetGet("http://uniprint2/Uniprint/MemorialNSSHP4200_for_Lte.exe","C:\temp\" & $test & ".exe", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Next ; Returns array of found line numbers that contain $searchStr contents. ; Optional delete found line from file. Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 Do $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number ;ConsoleWrite("CharPos: " & $location & " Ln: " & $iCurrentLineNum & @CRLF) $sRes &= $iCurrentLineNum & "|" If $bDeleteLine Then _FileWriteToLine($sFileName, $iCurrentLineNum, "", 1) ; Remove found line from file. Else $iOccur += 1 EndIf Else ExitLoop EndIf Sleep(10) Until 0 ;ShellExecute($sFileName) Return StringSplit(StringTrimRight($sRes, 1), "|") EndFunc ;==>_LineNumsOfSearchStr ; Opt ("TrayIconDebug", 1) Opt ("TrayAutoPause", 0) Opt ("TrayOnEventMode", 1) Opt ("ExpandEnvStrings", 1) Opt ("WinDetectHiddenText", 1) Local $Msg, $button1, $button2, $button3 $Form1 = GUICreate ("Printers Near You", 510, 240, 200, 200) $Label1 = GUICtrlCreateLabel ("Select a Printer to install", 10, 10, 126, 17) GUICtrlCreateGroup ("", +30, +30, 450, 165) For $test in $aResult $firstpart = StringSplit($tester, ",") $final = $firstpart[1] GUISetCoord(10, 10) ;sets X, Y coordinates GUICtrlCreateCheckbox ($final, -1 +50, -1 +50, 255, 17) Next $firstpart = StringSplit($tester, ",") $final = $firstpart[1] GUICtrlCreateCheckbox ($final, -1 +90, -1 +90, 255, 17) #cs $Radio2 = GUICtrlCreateCheckbox ("memo-nss-hp5550c", 30, 70, 135, 17) $Radio3 = GUICtrlCreateCheckbox ("memo-nss-hp5si", 30, 90, 135, 17) $Radio4 = GUICtrlCreateCheckbox ("memo-nss-hpm525", 30, 110, 135, 17) #ce ;========================================================================================= $Button1 = GUICtrlCreateButton ("Start", -1 + 40, 200, 129, 25, 0) GUISetState() $Button2 = GUICtrlCreateButton ("Select All", -1 + 190, 200, 129, 25, 0) GUISetState() $Button3 = GUICtrlCreateButton ("UnSelect All", -1 + 340, 200, 129, 25, 0) GUISetState() While 1 $Msg = GuiGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $button1 If BitAND (GUICtrlRead($Radio1), $GUI_CHECKED) = $GUI_CHECKED then RunWait ("C:\temp\1.exe") EndIf If BitAND (GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED Then RunWait ("C:\temp\2.exe") EndIf If BitAND (GUICtrlRead($Radio3), $GUI_CHECKED) = $GUI_CHECKED Then RunWait ("C:\temp\3.exe") EndIf If BitAND (GUICtrlRead($Radio4), $GUI_CHECKED) = $GUI_CHECKED then RunWait ("C:\temp\4.exe") EndIf Exit Case $button2 _GUICtrlButton_SetCheck($Radio1, $BST_CHECKED) _GUICtrlButton_SetCheck($Radio2, $BST_CHECKED) _GUICtrlButton_SetCheck($Radio3, $BST_CHECKED) _GUICtrlButton_SetCheck($Radio4, $BST_CHECKED) Case $button3 _GUICtrlButton_SetCheck($Radio1, $BST_UNCHECKED) _GUICtrlButton_SetCheck($Radio2, $BST_UNCHECKED) _GUICtrlButton_SetCheck($Radio3, $BST_UNCHECKED) _GUICtrlButton_SetCheck($Radio4, $BST_UNCHECKED) EndSwitch WEnd #ce
JohnWilson Posted June 2, 2014 Author Posted June 2, 2014 Some of it is irrelevant as I am still tweaking it, but it will give you what you need I am sure. Thanks a lot!!!
UEZ Posted June 2, 2014 Posted June 2, 2014 (edited) Please check your posted code - it is not run able (mixed up)!Also post any test files.Br,UEZ Edited June 2, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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