Page 1 of 1 1
Topic Options
#124354 - 2004-08-03 07:36 PM Why is my array reference out of bounds !?
GyroTwister Offline
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
#124355 - 2004-08-03 07:44 PM Re: Why is my array reference out of bounds !?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
DON'T use GOTO! Especially not in the middle of an IF construct!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124356 - 2004-08-03 07:50 PM Re: Why is my array reference out of bounds !?
GyroTwister Offline
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 Offline
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
#124358 - 2004-08-03 07:57 PM Re: Why is my array reference out of bounds !?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Your code just plain does not work. If I had an inkling of what you are trying to do, I might make some suggestions but I am at a loss.

I don't know how you are supposed to get BOTH the $User AND the $Computer from the same var.
$User = Left ($UserDir,2)
$Computer = Left ($UserDir,4)

It simply fails all the IFs and falls through to the end, where you ReDim() to a negative number and that throws the error.

I guess you did not run this in debug cuz you would have seen that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124359 - 2004-08-03 08:02 PM Re: Why is my array reference out of bounds !?
GyroTwister Offline
Fresh Scripter

Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
Bryce,

Thanks! It works!

By the way is there a FAQ or How To about FSO?

_________________________
-------------------------------------------------------------- With kind regards, GyroTwister

Top
#124360 - 2004-08-03 08:22 PM Re: Why is my array reference out of bounds !?
GyroTwister Offline
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 Offline
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 Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#124363 - 2004-08-03 08:45 PM Re: Why is my array reference out of bounds !?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

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



You can NOT find BOTH the user AND computer name in that folder. Therefor, the second IF will always fail, $RunCount never increment, and a ReDim() to a negative number. If you single step in debug, that should be obvious.

Also, you say "\\OldMachine\C$\Documents and Settings" but the first code showed "C:" and the latest shows "O:"

You could use one of the NetView() UDFs to list out all the computer names. I am not sure how you determine what is an OLD vs NEW computer but am thinking maybe the OLD ones start with "NLZZ"since you seem to want to count how many of those there are. Not sure what the purpose is of counting them.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124364 - 2004-08-03 08:50 PM Re: Why is my array reference out of bounds !?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

SetOption ('CaseSensitivity','ON')



Not sure why you would want that on and then do 'NL' OR 'nl'.

You can force case sensitivity on an individual basis by doubling up the == if need be.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124365 - 2004-08-03 11:23 PM Re: Why is my array reference out of bounds !?
GyroTwister Offline
Fresh Scripter

Registered: 2003-01-29
Posts: 15
Loc: Hoogeveen, The Netherlands
OK, Howard, Les,

I think I've got it right this time. See the following code.
Code:

$RunCount = 0

$UserDir = Dir ('O:\Documents and Settings')
While $UserDir <> '' AND @ERROR = 0
$User = Ucase (Left ($UserDir,2))
$Length = Len ($UserDir)
If $User = 'NP' AND $Length = 8
$UserArray[$RunCount] = Ucase ($UserDir)
$RunCount = $RunCount + 1
EndIf
$UserDir = Dir()
Loop

ReDim PRESERVE $UserArray[$RunCount-1]



Thanks for helping me out!
_________________________
-------------------------------------------------------------- With kind regards, GyroTwister

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2175 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.064 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org