IvanCodin Posted November 18, 2012 Share Posted November 18, 2012 (edited) I have a script where I have a user input up to three ip addresses. I them output them to a file. The entrys need to be comma deliminated. I got the script to work but wonder if there is a better way to do it. He is an example script of what I am tring to do: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $Input1, $Input2, $Input3, $ip1, $ip2, $ip3 $notepad = "notepad.exe" $Form2 = GUICreate("Form2", 225,280, 194, 122) GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close") $Input1 = GUICtrlCreateInput("Input1", 24, 40, 145, 24) GUICtrlSetOnEvent($Input1, "Input1Change") $Input2 = GUICtrlCreateInput("Input2", 24, 72, 145, 24) GUICtrlSetOnEvent($Input2, "Input2Change") $Input3 = GUICtrlCreateInput("Input3", 24, 104, 145, 24) GUICtrlSetOnEvent($Input3, "Input3Change") $Button1 = GUICtrlCreateButton("Go", 24, 168, 57, 17) GUICtrlSetOnEvent($Button1, "Button1Click") $Button2 = GUICtrlCreateButton("Exit", 144, 168, 57, 17) GUICtrlSetOnEvent($Button2, "Button2Click") $Group1 = GUICtrlCreateGroup("Group1", 8, 16, 205, 217) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlSetOnEvent($Button1, "Button1Click") GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Button1Click() MsgBox(0, "Info - GWDocMake", "IP address entrys are item1= " & $ip1 & " Item2= " & $ip2 & " Item3= " & $ip3,4) SplashTextOn("Info", "Creating Item configuration", 380, 55) Sleep(3000) SplashOff() GWDocMake() EndFunc ;==>Button1Click Func Button2Click() Exit EndFunc ;==>Button2Click Func Form2Close() GUIDelete($Form2) Exit EndFunc ;==>Form2Close Func Input1Change() $ip1 = GUICtrlRead($Input1) EndFunc ;==>Input1Change Func Input2Change() $ip2 = GUICtrlRead($Input2) EndFunc ;==>Input2Change Func Input3Change() $ip3 = GUICtrlRead($Input3) EndFunc ;==>Input3Change Func GWDocMake() SplashTextOn("Info", "Creating Item List Document", 380, 55) Sleep(3000) SplashOff() $ItemDoc = "c:" & "ItemsList.txt" $oputfile = FileOpen($ItemDoc, 10) ; => Check if file is opened for writing successfully If $oputfile = -1 Then MsgBox(0, "Error", "Unable to create the gateway document." & $oputfile) Exit EndIf If $ip3 = "" And $ip2 = "" And $ip1 = "" Then MsgBox(0, "Info", "No items were entered!") Return ElseIf $ip3 <> "" Then MsgBox(0, "IP3 is populated", "Item list is " & "set to " & $ip1 & "," & $ip2 & "," & $ip3,4) FileWrite($oputfile, "########## Three items were entered. They were " & $ip1 & ", " & $ip2 & ", " & $ip3 & "############" & @CRLF) FileWrite($oputfile, "########## All Done! ############" & @CRLF) ElseIf $ip2 <> "" Then MsgBox(0, "ip2 is populated", "Item List is " & "set to " & $ip1 & "," & $ip2,4) FileWrite($oputfile, "########## Two items were entered. They were " & $ip1 & ", " & $ip2 & " " & "############" & @CRLF) FileWrite($oputfile, "########## All Done! ############" & @CRLF) ElseIf $ip1 <> "" Then MsgBox(0, "ip1 is populated", "Item List is " & "set to " & $ip1,4) FileWrite($oputfile, "########## One Item was entered. It was " & $ip1 & " " & "############" & @CRLF) FileWrite($oputfile, "########## All Done! ############" & @CRLF) Else ;Continue on ;MsgBox(4096, "Warning!", "You did not enter any items!", 4) FileWrite($oputfile, "########## Test for Item List ############" & @CRLF) FileWrite($oputfile, "########## No entries were made! ##########" & @CRLF) EndIf FileClose($oputfile) Sleep ( 1000 ) MsgBox(0,"Info", "Here is what was written to the file.",4) Run($notepad & $oputfile) ;"notepad.exe " & $GWDoc) If @error Then Run("notepad.exe " & "c:itemslist.txt") Else MsgBox(0, "Error", "Unable to open Notepad!", 4) EndIf EndFunc ;==>GWDocMake Any ideas would be appreciated! Me Edited November 18, 2012 by IvanCodin Link to comment Share on other sites More sharing options...
Decipher Posted November 18, 2012 Share Posted November 18, 2012 Use arrays and the for to loop instead of this eval function for reason I can't seem to remember. For $i = 1 To 3 $sVariable = "ip" & $i $iIPNum = Eval($sVariable) If $iIPNum <> "" Then ;Do whatever EndIf Next Spoiler Link to comment Share on other sites More sharing options...
IvanCodin Posted November 18, 2012 Author Share Posted November 18, 2012 Love the forum!! You guys are great and provide useful ideas! I have never done a array before.:-( I don't understand then very well. I read the helpfile and interpret your array like this this: \For $i = 1 To 3 ; This would be the number of entries I want to test for. $sVariable = "ip" & $i ; This would set the list entry This would step me through each of the entires. $iIPNum = Eval($sVariable) If $iIPNum <> "" Then ;You changed the variable name to test it. Why do we do this? ;Do whatever ;Add my filewrite here based on entires in the list EndIf Next ; Does this exit the test and move on to the next item in the script or does it start the eval over again? Link to comment Share on other sites More sharing options...
Decipher Posted November 18, 2012 Share Posted November 18, 2012 (edited) You got the majority of it down. But the Next statement is used to exit a loop this is what we call recursive programming where you iterate through the same code changing variables aka stepping through and array. If you wish to learn about arrays follow the link below. http://www.autoitscript.com/wiki/Arrays I'm glad I could help and comeback if you need more assistance. *Edit $iIPNum = Eval($sVariable) If $iIPNum <> "" Then ;You changed the variable name to test it. Why do we do this? I used an unnecessary variable there in hope that it would be more understandable. Edited November 18, 2012 by Decipher Spoiler Link to comment Share on other sites More sharing options...
IvanCodin Posted November 18, 2012 Author Share Posted November 18, 2012 Guess if I can understand your response (clever) I should be able to understand your initial recommendation! So what you are sating is: $clue = 1 If $clue = 1 Then MsgBox(0,"Yes", "You got it") ElseIf $clue < 1 Then MsgBox(0,"Idiot", "Read the help file!") Else MsgBox(0, "RTFM", "Read the helpfile") Endif Me Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2012 Share Posted November 18, 2012 I don't think Decipher called you an idiot. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
JohnOne Posted November 18, 2012 Share Posted November 18, 2012 He did put the OP on a bum steer though. iterating is Iterative, not recursive. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
IvanCodin Posted November 19, 2012 Author Share Posted November 19, 2012 I didn't think he called me an idiot! I was just good humor back and forth (or bad perhaps). I was making comments on myself. I thought his response was really clever and it made me laugh. Me Link to comment Share on other sites More sharing options...
Decipher Posted November 19, 2012 Share Posted November 19, 2012 (edited) He did put the OP on a bum steer though.iterating is Iterative, not recursive.I understand that the two have different definitions but would you mind distinguishing between them with code? Edited November 19, 2012 by Decipher Spoiler Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2012 Moderators Share Posted November 19, 2012 Decipher,Take a look at the Recursion tutorial in the Wiki - the final 2 scripts show the difference clearly. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted November 19, 2012 Share Posted November 19, 2012 a Recursive script is one having a function or a script that calls itself. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Decipher Posted November 19, 2012 Share Posted November 19, 2012 (edited) Thanks @ Melba23, I now definitely realize the difference and that I had been using recursion unnecessarily to iterate through all the files in a directory and sub directories. Edited November 19, 2012 by Decipher Spoiler Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2012 Moderators Share Posted November 19, 2012 Decipher, My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted November 20, 2012 Share Posted November 20, 2012 (edited) Decipher, You are using the eval statment wrong. Perhaps you are trying to do something like this local $ip1 = '111.111.111', $ip2 = '222.222.222', $ip3 = '333.333.333' For $i = 1 To 3 ConsoleWrite(eval('ip' & $i) & @LF) Next This $iIPNum = Eval($sVariable) resolves to "" and set @error to something other than 0. kylomas Edited November 20, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
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