#124354 - 2004-08-03 07:36 PM
Why is my array reference out of bounds !?
|
GyroTwister
Fresh Scripter
Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
|
Hello, KiX community,
I am still trying to get the software installed and the data copied in a way that I want. But I stumbled upon this; hereafter you'll see a snippet of code to determine which users reside on an old machine.
Code:
; ----- Which users reside on the old machine -------------------------------------------------- SetOption ('Explicit','ON') SetOption ('NoVarsInStrings','ON') SetOption ('CaseSensitivity','ON')
Global $UserArray[100] Dim $UserDir, $User, $Computer, $RunCount
$RunCount = 0
$UserDir = Dir ('C:\Documents and Settings') While $UserDir <> '' AND @ERROR = 0 $User = Left ($UserDir,2) If $User = 'NP' $Computer = Left ($UserDir,4) If $Computer = 'NLZZ' GoTo Continue Else $UserArray[$RunCount] = $UserDir $RunCount = $RunCount + 1 EndIf EndIf :Continue $UserDir = Dir() Loop
ReDim PRESERVE $UserArray[$RunCount-1]
For your information every user has a name starting with NP and followed by a 6 digit employee no.
All the computernames are starting with NLZZ and followed by there serial no which is read from the BIOS.
Everytime I run this script I get an error message:
ERROR: array reference out of bounds!
Does anyone see what I don't?
t.i.a.
_________________________
--------------------------------------------------------------
With kind regards,
GyroTwister
|
|
Top
|
|
|
|
#124356 - 2004-08-03 07:50 PM
Re: Why is my array reference out of bounds !?
|
GyroTwister
Fresh Scripter
Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
|
As in your recommendation I changed the code to:
Code:
SetOption ('Explicit','ON') SetOption ('NoVarsInStrings','ON') SetOption ('CaseSensitivity','ON') Global $UserArray[100] Dim $UserDir, $User, $Computer, $RunCount $RunCount = 0
$UserDir = Dir ('C:\Documents and Settings') While $UserDir <> '' AND @ERROR = 0 $User = Left ($UserDir,2) If $User = 'NL' $Computer = Left ($UserDir,4) If $Computer <> 'NLZZ' $UserArray[$RunCount] = $UserDir $RunCount = $RunCount + 1 EndIf EndIf $UserDir = Dir() Loop
ReDim PRESERVE $UserArray[$RunCount-1]
Still the same error. Any other suggestion?
_________________________
--------------------------------------------------------------
With kind regards,
GyroTwister
|
|
Top
|
|
|
|
#124357 - 2004-08-03 07:50 PM
Re: Why is my array reference out of bounds !?
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I am guessing taht you are trying to use a $runcount value that is greater than 100.
a simpler way of doing this.....using FSO.
Code:
for each $userfolder in getfolders("c:\Documents and Settings")
? $userfolder.name
next
function Getfolders($path)
dim $fso
$fso = CreateObject("Scripting.FileSystemObject")
$getfolders = $fso.getfolder($path).subfolders
endfunction
Edited by Bryce (2004-08-03 07:51 PM)
|
|
Top
|
|
|
|
#124360 - 2004-08-03 08:22 PM
Re: Why is my array reference out of bounds !?
|
GyroTwister
Fresh Scripter
Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
|
Les,
I have tried to run it in DEBUG but I don't see where it is going wrong.
Ok, your question
Als antwoord op:
If I had an inkling of what you are trying to do, I might make some suggestions but I am at a loss.
I'm (trying to) read(ing) all the subdirectories from \\OldMachine\C$\Documents and Settings.
In this directory I will find useraccount starting with 'nl' and computeraccounts starting with 'nlzz'. There both followed by a six digit number to be complete.
So if I read the subdir the only names I want to have in my array are names starting with nl<digit><digit> and NOT starting with nlzz.
After the other remarks you made i have rewritten the code. Maybe with this explanation you'll get the picture.
Code:
SetOption ('Explicit','ON') SetOption ('NoVarsInStrings','ON') SetOption ('CaseSensitivity','ON') Dim $UserDir, $User, $Computer, $RunCount Global $UserArray[100] $UserDir = Dir ('O:\Documents and Settings') While $UserDir <> '' AND @ERROR = 0 $User = Left ($UserDir,2) $Computer = Left ($UserDir,4) If $User = 'NL' AND $Computer <> 'NLZZ' $UserArray[$RunCount] = $UserDir $RunCount = $RunCount + 1 ? $UserDir Get $x EndIf $UserDir = Dir() Loop
ReDim PRESERVE $UserArray[$RunCount-1]
I hope to hear from you!!!
t.i..a
_________________________
--------------------------------------------------------------
With kind regards,
GyroTwister
|
|
Top
|
|
|
|
#124361 - 2004-08-03 08:38 PM
Re: Why is my array reference out of bounds !?
|
GyroTwister
Fresh Scripter
Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
|
Les,
I've got it working.
To be complete here is the code I use:
Code:
SetOption ('ASCII','ON') SetOption ('HideCursor','ON') SetOption ('WrapAtEOL','ON') SetOption ('Explicit','ON') SetOption ('NoVarsInStrings','ON') SetOption ('CaseSensitivity','ON') Global $UserArray[100] Dim $UserDir, $User, $Length, $RunCount $RunCount = 0
$UserDir = Dir ('O:\Documents and Settings') While $UserDir <> '' AND @ERROR = 0 $User = Left ($UserDir,2) $Length = Len ($UserDir) If $User = 'NL' OR 'nl' AND $Length = 8 $UserArray[$RunCount] = $UserDir $RunCount = $RunCount + 1 ? $UserDir EndIf $UserDir = Dir() Loop
ReDim PRESERVE $UserArray[$RunCount-1]
_________________________
--------------------------------------------------------------
With kind regards,
GyroTwister
|
|
Top
|
|
|
|
#124362 - 2004-08-03 08:44 PM
Re: Why is my array reference out of bounds !?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Code:
If $User = 'NL' OR 'nl' AND $Length = 8
Is invalid syntax for checking $USER. The If will always be TRUE.
Code:
If $User = 'NL' OR $User = 'nl' AND $Length = 8
or
If ucase($User) = 'NL' AND $Length = 8
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2375 anonymous users online.
|
|
|