BlackDawn187 Posted February 9, 2014 Posted February 9, 2014 (edited) So, I have a 2D Array, There's a surprise. Anyways, I'm doing a For loop through it and, I need to delete something within it. Then echo/GUICtrlSetData the change(s). The Array is populated by a IniReadSection. So my variable looks like $Array[$i][0], The problem is, I don't know how to delete a line that is predeclared. For example: ($Array = $Plugins in this example) expandcollapse popup;$Plugin is predeclared elsewhere ProcessClose("" & $Plugin & ".exe") $Plugins = IniReadSection("" & @ScriptDir & "\Plugins\Config.ini", "Plugins") ;Read Section names from ini file and populate array If @error Then ;$Plugins is empty $ConsoleMessage = "Found Plugin(s): 0" GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") Return ("Error") Else ;$Plugins is not empty For $i = 1 To $Plugins[0][0] ;For this example, $Plugins[0][0] = 1 _ArrayDelete($Plugins[$i][0], "" & $Plugin & "") ; Delete a value/element within $Plugins[$i][0] ;Some non-example code, You can ignore this $AutoRun = IniRead("" & @ScriptDir & "\Plugins\Plugins.ini", "" & $Plugins[$i][0] & "", "AutoRun", "False") If $AutoRun = "True" Then GUICtrlSetData($LoadedPlugins, "" & $Plugins[$i][0] & "") GUICtrlSetData($Label2, "(" & $Plugins[0][0] & ")") GUICtrlSetColor(-1, 0x66FFFF) ElseIf $AutoRun <> "True" Then Sleep("100") EndIf ;End Ignore =) Next MsgBox(0, "", "" & $Plugins[0][0] & "") ;This is for debugging purposes If ProcessExists("" & $Plugin & ".exe") = "0" And $Plugins[0][0] > "0" Then ;If the process doesn't exists and the list of section names returned > "0", Do -> $ConsoleMessage = 'Plugin "' & $Plugin & '" successfully unloaded' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") GUICtrlSetData($LoadedPlugins, "" & $Plugins[$i][0] & "") GUICtrlSetData($Label2, "(" & $Plugins[0][0] & ")") ElseIf ProcessExists("" & $Plugin & ".exe") = "0" And $Plugins[0][0] = "0" Then ;If the process doesn't exists and the list of section names returned = "0", Do -> $ConsoleMessage = 'Plugin "' & $Plugin & '" successfully unloaded' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") GUICtrlSetData($LoadedPlugins, "") GUICtrlSetData($Label2, "(0)") ElseIf ProcessExists("" & $Plugin & ".exe") Then ;If the process still exists echo $consolemessage, Do -> $ConsoleMessage = 'Plugin "' & $Plugin & '" could not be unloaded' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") Sleep("100") EndIf Return ("Success") EndIf EndFunc Edited February 9, 2014 by BlackDawn187
jaberwacky Posted February 9, 2014 Posted February 9, 2014 (edited) One issue I see so far is that the @error test in the unload function should just be If @error Then because IniReadSection can return any non-zero number. Also, checking for @error = '1' may lead to unexpected results. I believe that autoit will convert the string to a 0 when tested. Edit: Possibly the same issue here too: ProcessExists("" & $Plugin & ".exe") = "0". Also, I see this: "" & $Plugin & "". Is that supposed to be surrounded with quotes? If so, then make it like this: """" & $Plugin & """". Helpfile says that using -1 in a function such as GUICtrlSetColor(-1, 0x66FFFF) will reference the last created control. Unless you know for sure that's what you want? It's probably best to use the variable which references that control. Anyways, have fun, correct those issues, and then come back to tell us if they made any difference. Edited February 9, 2014 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
BlackDawn187 Posted February 9, 2014 Author Posted February 9, 2014 Seems like once I do $Plugins, Followed by ArrayDelete($Plugins, $Plugin) that my script is having issues with the array being empty if no other elements exist on the array. The @error is not returning as it should which may possibly bea conflict with ArrayDelete. @jaberwacky - You'll notice in the help file that if ProcessExists fails it returns 0. That's what my code checks for. As well, "" & $Plugin & "" merely translates the variable into a string regardless of its value. I've updated some of the code on my end but haven't got around to posting it yet.
jaberwacky Posted February 9, 2014 Posted February 9, 2014 This line: For $i = 1 To $Plugins[0][0] And $Plugins[$i][0] <> $Plugin may or may not do what you expect. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
BlackDawn187 Posted February 9, 2014 Author Posted February 9, 2014 (edited) So as of my last attempt to get this working, This is what I have for code: expandcollapse popupFunc Unload($Plugin) ProcessClose("" & $Plugin & ".exe") $Plugins = IniReadSection("" & @ScriptDir & "\Plugins\Config.ini", "Plugins") _ArrayDelete($Plugins, "" & $Plugin & "") If @error = "1" Then $ConsoleMessage = "Found Plugin(s): 0" GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") Return ("Error") Else For $i = 1 To $Plugins[0][0] $AutoRun = IniRead("" & @ScriptDir & "\Plugins\Plugins.ini", "" & $Plugins[$i][0] & "", "AutoRun", "False") If $AutoRun = "True" Then GUICtrlSetData($LoadedPlugins, "" & $Plugins[$i][0] & "") GUICtrlSetData($Label2, "(" & $Plugins[0][0] & ")") GUICtrlSetColor(-1, 0x66FFFF) ElseIf $AutoRun <> "True" Then Sleep("100") EndIf Next MsgBox(0, "", "" & $Plugins[0][0] & "") If ProcessExists("" & $Plugin & ".exe") = "0" And $Plugins[0][0] <> "0" Then $ConsoleMessage = 'Plugin "' & $Plugin & '" successfully unloaded' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") GUICtrlSetData($LoadedPlugins, "" & $Plugins[$i][0] & "") GUICtrlSetData($Label2, "(" & $Plugins[0][0] & ")") ElseIf ProcessExists("" & $Plugin & ".exe") = "0" And $Plugins[0][0] = "0" Then $ConsoleMessage = 'Plugin "' & $Plugin & '" successfully unloaded' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") GUICtrlSetData($LoadedPlugins, "") GUICtrlSetData($Label2, "(" & $Plugins[0][0] & ")") ElseIf ProcessExists("" & $Plugin & ".exe") Then $ConsoleMessage = 'Plugin "' & $Plugin & '" could not be found' GUICtrlSetData($Console, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $ConsoleMessage & "") Sleep("100") EndIf Return ("Success") EndIf EndFunc It seems like everything works up until the "If" statements after "Next". Where "If ProcessExists("" & $Plugin & ".exe") = "0" And $Plugins[0][0] <> "0" Then". That line always fires, Although the $Plugins[0][0] variable is empty/zero. Since I have deleted the only element within the array. Edit: Apparently my ArrayDelete isn't deleting the appropriate element as I thought Edited February 9, 2014 by BlackDawn187
jaberwacky Posted February 9, 2014 Posted February 9, 2014 Oh yeah, durr, I got a little confused string conversion to numbers. ::hurrhurrhurr:: Anyways, there shouldn't be a need to explicitly cast a number as a string. I think it's done explicitly according to its use. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
BlackDawn187 Posted February 9, 2014 Author Posted February 9, 2014 Updated OP to clarify a few things, As well as partially commented the code.
guinness Posted February 9, 2014 Posted February 9, 2014 Oh yeah, durr, I got a little confused string conversion to numbers. ::hurrhurrhurr:: Anyways, there shouldn't be a need to explicitly cast a number as a string. I think it's done explicitly according to its use. Thought it's always recommended to cast to Int() rather than relying on AutoIt to convert "123". 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
jaberwacky Posted February 9, 2014 Posted February 9, 2014 I don't know. Do you have any links that go into more detail? I didn't see that in the helpfile. All I know is this code actually discombobulates me. I see this and I don't know what's real anymore. _ArrayDelete($Plugins, "" & $Plugin & "") Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
BlackDawn187 Posted February 9, 2014 Author Posted February 9, 2014 (edited) Here's the online help file for _ArrayDelete : http://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDelete.htm _ArrayDelete($Plugins, "" & $Plugin & "") Here, I'm trying to delete a row in the array($Plugins) where the value = $Plugin. Edited February 9, 2014 by BlackDawn187
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