Sign in to follow this  
Followers 0
BlackDawn187

Help with ArrayDelete on 2D Array

10 posts in this topic

#1 ·  Posted (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)

;$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 by BlackDawn187

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by jaberwacky

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So as of my last attempt to get this working, This is what I have for code:

Func 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 by BlackDawn187

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Updated OP to clarify a few things, As well as partially commented the code.

Share this post


Link to post
Share on other sites

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".


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 & "")

Share this post


Link to post
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
Sign in to follow this  
Followers 0