shornw Posted July 27, 2017 Share Posted July 27, 2017 Hi all, This is quite frustrating (probably user error) but hopefully someone will be able to see and explain what I'm missing / doing wrong. Basically created an array (which is working fine) then trying to use an element of the array as a SWITCH but get 'Array variable has incorrect number of subscripts or subscript dimension range exceeded'. The variable get's populated correctly in the MsgBox but fails even when I tried declaring a new variable ie $os = $aOS[1][1] $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") ; MsgBox(0, "", $aOS[1][1]) Switch $aOS[1][1] Any ideas gratefully received and thanks in advance [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Danp2 Posted July 27, 2017 Share Posted July 27, 2017 Have you tried checking the value of @error after the call to the AD function? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
shornw Posted July 27, 2017 Author Share Posted July 27, 2017 (edited) No, because an _ArrayDisplay shows the array populated correctly. Also, the variable gets populated correctly in the MsgBox I added to test it Edited July 27, 2017 by shornw [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Danp2 Posted July 27, 2017 Share Posted July 27, 2017 If that were true in all instances, then you wouldn't be running into that error message. ;-) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 27, 2017 Share Posted July 27, 2017 3 minutes ago, shornw said: No, because an _ArrayDisplay shows the array populated correctly. Also, the variable gets populated correctly in the MsgBox I added to test it @shornw Which of the two arrays are you displaying? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 27, 2017 Moderators Share Posted July 27, 2017 How about providing your whole code, rather than just a couple lines, or at least a reproducer, so we can see (and replicate) what you're doing? Danp2 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
shornw Posted July 27, 2017 Author Share Posted July 27, 2017 #include<AD.au3> #include<Array.au3> _AD_Open() $Comp = _AD_GetObjectsInOU("OU=?????, DC=?????, DC=??????, DC=???", "(objectclass=computer)") _ArrayDisplay($comp) Dim $aNoOS[1][2] Dim $aW2k3[1][2] For $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") Switch $aOS[1][1] Case StringInStr($aOS, "MAC") ContinueLoop Case "" _ArrayAdd($aNoOS, $Comp[$i] & "|" & $aOS[1][1]) MsgBox(0, "No OS", $comp[$i] & @TAB & $aOS) Case StringInStr($aOS, "Windows Server 2003") _ArrayAdd($aw2k3, $comp[$i] & "|" & $aOS[1][1]) EndSwitch Next [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
shornw Posted July 27, 2017 Author Share Posted July 27, 2017 12 minutes ago, FrancescoDiMuro said: Which of the two arrays are you displaying? For test purposes I always do an _ArrayDisplay to confirm expected results so I have displayed both arrays and the results were as expected [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 27, 2017 Share Posted July 27, 2017 (edited) 25 minutes ago, shornw said: Case StringInStr($aOS, "Windows Server 2003") Maybe here? $aOS becomes an array at the starting of the loop, and everytime the loop repeats... So, you should check with the right syntax: Case StringInStr($aOS[1][1], "Windows Server 2003") ; Maybe... ? Edited July 27, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
shornw Posted July 27, 2017 Author Share Posted July 27, 2017 Thank you for this Franceso - you are right, that would have failed and would have come to light later, however what I'm trying to identify is why the following line causes the script to fail with the error ' Array variable has incorrect number of subscripts or subscript dimension range exceeded ' Switch $aOS[1][1] Incidentally, it works fine if I use If - Then instead of Switch - Case For $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") If UBound($aOS) < 2 Then _ArrayAdd($aNoOS, $comp[$i] & "| No OS Info") ContinueLoop ElseIf $aOS[1][1] = "Windows Server 2003" Then _ArrayAdd($aw2k3, $comp[$i] & "|" & $aOS[1][1]) ElseIf $aOS[1][1] = "Windows Server 2008 R2 Standard" Then _ArrayAdd($aw2k8, $comp[$i] & "|" & $aOS[1][1]) EndIf Next _ArrayDisplay($aNoOS, "No OS") _ArrayDisplay($aw2k3, "W2K3") _ArrayDisplay($aw2k8, "W2K8") [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 27, 2017 Share Posted July 27, 2017 @shornw Happy to have helped What type of value are you trying to compare? String? Integer? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
shornw Posted July 27, 2017 Author Share Posted July 27, 2017 the value is a string - it's the Operating System of devices extracted from AD What you pointed out would have caused a failure to populate an array later but l don't understand what is causing the failure when using the variable with Switch [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Danp2 Posted July 27, 2017 Share Posted July 27, 2017 49 minutes ago, shornw said: Incidentally, it works fine if I use If - Then instead of Switch - Case Does it work with the Switch - Case scenario if you add in the UBound check before the Switch? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 28, 2017 Share Posted July 28, 2017 @shornw Good morning Can you try to replace the Switch with the Select statement? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
shornw Posted July 28, 2017 Author Share Posted July 28, 2017 16 hours ago, Danp2 said: Does it work with the Switch - Case scenario if you add in the UBound check before the Switch? No - With Ubound check/continueloop, it runs but operates the ContinueLoop statement so ignores anything beyond it and doesn't populate any of the arrays. I Changed the behaviour of the If Ubound and it failed. Iadded a new MsgBox to identify the value of Ubound before it hits the Switch command - as expected the value is generally 2 expandcollapse popupFor $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") MsgBox(0, "Ubound", UBound($aOS)) ; added to test whether the variable is populated # If UBound($aOS) < 2 Then ContinueLoop If UBound($aOS) < 2 Then _ArrayAdd($aNoOS, $Comp[$i] & "|" & $aOS[1][1]) ; added to test if the script runs Switch $aOS[1][1] Case StringInStr($aOS, "MAC") ContinueLoop Case "" _ArrayAdd($aNoOS, $Comp[$i] & "|" & $aOS[1][1]) MsgBox(0, "No OS", $comp[$i] & @TAB & $aOS) Case StringInStr($aOS, "Windows Server 2003") _ArrayAdd($aw2k3, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS, "Windows Server 2008 standard") Or StringInStr($aOS, "Windows 2008 Enterprise") _ArrayAdd($aw2k8, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS, "Windows Server 2008 R2") _ArrayAdd($aw2k8R2, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS, "Windows Server 2012 Standad") _ArrayAdd($aW2k12, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS, "Windows Server 2012 R2") _ArrayAdd($aW2k12R2, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS, "Windows Server 2016") _ArrayAdd($aW2k16, $comp[$i] & "|" & $aOS[1][1]) EndSwitch If UBound($aOS) < 2 Then _ArrayAdd($OperatingSys, $Comp[$i] & "|" & "No OS information") ContinueLoop Else _ArrayAdd($OperatingSys, $Comp[$i] & "|" & $aOS[1][1]) EndIf Next _ArrayDisplay($aw2k3, "W2K3") _ArrayDisplay($aw2k8, "W2K8") [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Danp2 Posted July 28, 2017 Share Posted July 28, 2017 I meant something like this -- For $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") If UBound($aOS) < 2 Then _ArrayAdd($OperatingSys, $Comp[$i] & "|" & "No OS information") ContinueLoop EndIf Select Case StringInStr($aOS[1][1], "Windows Server 2003") _ArrayAdd($aw2k3, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS[1][1], "Windows Server 2008 standard") Or StringInStr($aOS[1][1], "Windows 2008 Enterprise") _ArrayAdd($aw2k8, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS[1][1], "Windows Server 2008 R2") _ArrayAdd($aw2k8R2, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS[1][1], "Windows Server 2012 Standad") _ArrayAdd($aW2k12, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS[1][1], "Windows Server 2012 R2") _ArrayAdd($aW2k12R2, $comp[$i] & "|" & $aOS[1][1]) Case StringInStr($aOS[1][1], "Windows Server 2016") _ArrayAdd($aW2k16, $comp[$i] & "|" & $aOS[1][1]) EndSelect Next _ArrayDisplay($aw2k3, "W2K3") _ArrayDisplay($aw2k8, "W2K8") Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
shornw Posted July 28, 2017 Author Share Posted July 28, 2017 Thanks for this Danp2 - I ran this and on the plus side it didn't bomb out. On the downside, the $aw2k8 array failed to populate which is of no consequence as I'm sure can easily be remediated. I know this works perfectly with If - Then which is little difference to Select - Case so I'm able to produce a working script. What's driving my curiosity now is why Switch fails to work with variable $aOS[1][1] - it must be something to do with the output as $test = $aOS[1][1] also fails yet a MsgBox(0, "Test", $aOS[1][1]) gets populated fine in the same location which is messing with my head. I need to understand cos I don't like unexpected [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Danp2 Posted July 28, 2017 Share Posted July 28, 2017 21 hours ago, Danp2 said: Have you tried checking the value of @error after the call to the AD function? I asked this earlier... and it still applies here. Basically, you need to confirm the results of the function call before moving on. Check @error, test using IsArray(), do the UBound check, etc. before assuming that the array contains the data you are expecting. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
shornw Posted July 28, 2017 Author Share Posted July 28, 2017 OK... so the below confirms an array but goes into a loop at the MsgBox and doesn't process Switch onwards For $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") If IsArray($aOS) Then MsgBox(0, "ArrayTest", "Array confirmed") Switch $aOS[1][1] whereas the below fails immediately it hits the Switch For $i = 1 To UBound($Comp) -1 $aOS = _AD_GetObjectProperties( $Comp[$i], "OperatingSystem") If Not IsArray($aOS) Then MsgBox(0, "ArrayFail", "No Array") Switch $aOS[1][1] @error of the _AD_GetObjectProperties returns 0 If the array DOESN'T contain the data I'm expecting to see, how is it populating MsgBox(0, "Test", $aOS[1][1]) and how is it working correctly with If - Then or Select - Case? [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
shornw Posted July 31, 2017 Author Share Posted July 31, 2017 Just wondering if anyone can offer any suggestion as to why Switch seems to fail with multidimensional array field or if anyone has used this combination successfully.... Any suggestions or ideas gratefully received [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] 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