BryanVest Posted June 6, 2012 Posted June 6, 2012 (edited) Can anyone please help me. The following code worked the first time, but errors out now. Any ideas why?Error:test.au3 (37) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:Code:Func _ListComputers() Local $rArray, $Buff, $Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 6) While Not @error $buff &= StdoutRead($Pid) WEnd $rArray = StringRegExp($Buff, "[]+([w-]+)", 3) If @Error Then $rArray = StringRegExp(@ComputerName, "(.+)", 1) Return $rArray EndFunc $aComputers = _ListComputers() $sData = "" For $i = 0 To Ubound($aComputers) -1 $sData &= $aComputers[$i] & "|" Next GuiCtrlSetData($Combo1, StringTrimRight($sData, 1), $aComputers[1]) Edited June 6, 2012 by BryanVest
Moderators Melba23 Posted June 6, 2012 Moderators Posted June 6, 2012 BryanVest, You need to do some errorchecking to make sure you get an array returned from the function before you try to access it - something along these lines: $aComputers = _ListComputers();; That's the function posted above. If IsArray($aComputers) Then $sData = "" For $i = 0 To Ubound($aComputers) -1 $sData &= $aComputers[$i] & "|" Next Else ; Code to cope with an error when no function is returned Endif all clear? 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
BryanVest Posted June 6, 2012 Author Posted June 6, 2012 (edited) So what I seem to have found out is that GuiCtrlSetData($Combo1, StringTrimRight($sData, 1), $aComputers[1]) causes the error. Any idea why? Edited June 6, 2012 by BryanVest
Moderators Melba23 Posted June 6, 2012 Moderators Posted June 6, 2012 BryanVest, Which part gives you the error? It should be highlighted in the SciTE console. I would suggest the array access is the culprit - you should only try to access the array if you are sure that it exists. M23 P.S. And to answer the question you originally posted - I have no idea why it only worked once, but with so little code to work on it is very difficult to offer a sensible opinion anyway. 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
BryanVest Posted June 6, 2012 Author Posted June 6, 2012 (edited) Here is the full code. Please let me know if you can make any sense of what is going on. It worked 1 time for me and now it just errors out. I have spent like 45 minutes trying to figure this out, but I am stuck. Thank you for your help so far. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=C:Documents and SettingsbvestDesktopkoda_1.7.3.0Formssd.kxf $Form1 = GUICreate("Symantec Uninstall Tool", 475, 168, 225, 231) $Label1 = GUICtrlCreateLabel("Computer Name:", 24, 16, 122, 22) GUICtrlSetFont(-1, 11, 800, 0, "Arial") $Label2 = GUICtrlCreateLabel("Uninstall Command:", 27, 61, 144, 22) GUICtrlSetFont(-1, 11, 800, 0, "Arial") $Button1 = GUICtrlCreateButton("Refresh", 16, 104, 75, 49) $Input2 = GUICtrlCreateInput("", 176, 64, 281, 21) GUICtrlSetFont(-1, 1, 400, 0, "MS Sans Serif") $Button3 = GUICtrlCreateButton("Remove", 384, 104, 73, 49) $Combo1 = GUICtrlCreateCombo("", 152, 16, 193, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Button2 = GUICtrlCreateButton("Get Uninstall String", 360, 16, 105, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func _ListComputers() Local $rArray, $Buff, $Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 6) While Not @error $buff &= StdoutRead($Pid) WEnd $rArray = StringRegExp($Buff, "[]+([w-]+)", 3) If @Error Then $rArray = StringRegExp(@ComputerName, "(.+)", 1) Return $rArray EndFunc $aComputers = _ListComputers() If IsArray($aComputers) Then $sData = "" For $i = 0 To Ubound($aComputers) -1 $sData &= $aComputers[$i] & "|" Next Else Endif GuiCtrlSetData($Combo1,StringTrimRight($sData, 1), $aComputers[1]) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 $Name = GUICtrlRead($Combo1) $sRegKey = "" & $Name &"HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall" $iKey = 1 While 1 $sHold = RegEnumKey($sRegKey, $iKey) If @Error Then ExitLoop $iKey += 1 IF RegRead($sRegKey & $sHold, "DisplayName") = 'Symantec Endpoint Protection' Then $sCur_Val = RegRead($sRegKey & $sHold, "UninstallString") If NOT @Error Then GUICtrlSetData($Input2,$sCur_Val) ExitLoop EndIf EndIf WEnd EndSwitch WEnd This code is for a tool to pull the unistall string from a remote computer, but I wanted to have it query the network using "net view" to bring up online computers. This is the part that errors test.au3 (40) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: GuiCtrlSetData($Combo1,StringTrimRight($sData, 1), $aComputers[1]) GuiCtrlSetData($Combo1,StringTrimRight($sData, 1), ^ ERROR However, if I change it to GuiCtrlSetData($Combo1,StringTrimRight($sData, 1), $aComputers[0]) it pulls my computer name only. Edited June 6, 2012 by BryanVest
Moderators Melba23 Posted June 6, 2012 Moderators Posted June 6, 2012 BryanVest,The returned array starts at the [0] element (like all AutoIt arrays) - if you only have a single computer on the net you only get the [0] element returned. So change the line to read:$aComputers = _ListComputers() If IsArray($aComputers) Then $sData = "" For $i = 0 To UBound($aComputers) - 1 $sData &= $aComputers[$i] & "|" Next Else MsgBox(0, "Error", "No computers found") Exit EndIf GUICtrlSetData($Combo1, StringTrimRight($sData, 1), $aComputers[0]) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<All clear? And I can get it to work many times without problem, so I have no idea why you cannot. 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
BryanVest Posted June 6, 2012 Author Posted June 6, 2012 (edited) Strange when I change it to that I only see my own computer. I have about 85 online right now though. EDIT: Nevermind now it is working now! Thank you! Edited June 6, 2012 by BryanVest
Moderators Melba23 Posted June 6, 2012 Moderators Posted June 6, 2012 BryanVest, Delighted I could help. 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
guinness Posted June 6, 2012 Posted June 6, 2012 I know the question has been answered but as of late of been learning regular expressions with the guidance of a couple of people.With your _ListComputers function I would have changed it a little to always return an array regardless of whether there was an error of not. As you can see I tweaked it as well to have the 0th index return the number of items in the array, just like StringSplit and _FileListToArray.#include <Array.au3> #include <Constants.au3> Local $aArray = _ListComputers() _ArrayDisplay($aArray) ; Returns an array with the 0th index being the total count. Func _ListComputers() Local $sData = _RunStdOutRead('net view', @SystemDir) Local $aArray = StringRegExp('ListComputers-CountIndex' & @CRLF & $sData, '([w-]*)', 3) ; Parse data as well as adding a dummy computer to store the total count. If @error Then ; If an error occurs then return an array with just the @ComputerName. Local $aError[2] = [1, @ComputerName] Return SetError(1, 0, $aError) ; Set @error to show that an error occurred. EndIf $aArray[0] = UBound($aArray, 1) - 1 ; Find the size of the array and change the 0th item to the total size minus 1. Return $aArray EndFunc ;==>_ListComputers Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir) Local $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd Return $sOutput EndFunc ;==>_RunStdOutReadLocal $aComputers = _ListComputers() Local $sData = '' For $i = 1 To $aComputers[0] $sData &= $aComputers[$i] & '|' Next GUICtrlSetData($hCombo, StringTrimRight($sData, 1), $aComputers[1])Sorry Melba23! 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
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