#31181 - 2002-10-22 11:58 AM
Array behaviour
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
I've never done a great deal of work with arrays before, and certainly not multi-dimensional ones, but I seem to have hit a slight limitation.
Basically, what I want to do is this:
code:
$x = 1,2,3 Dim $y for $count = 0 to ubound($x) $y[$count] = $x[$count] next
As I understand it, this should be the same as
code:
$x = 1,2,3 Dim $y $y = $x
But for some reason, only the second example works. Even avoiding the For...Next construct and just trying...
code:
$x = 1,2,3 Dim $y $y[0] = $x[0]
...fails. Is this because I'm not declaring the size of the $y array when I Dim it? Should I try something like...
code:
$x = 1,2,3 Dim $y[ubound($x)]
...to get around this? Any advice would be appreciated. Later on in my process, I will want to assign the resultant $y array to an element of the $z array, which will become a series of $y's. Is this going to fail horribly? Can anyone suggest another way of doing this? Or will I need to do something entirely different to start working with multi-dimensional arrays?
Thanks in advance,
Breaker
_________________________
================================================ Breaker
|
|
Top
|
|
|
|
#31183 - 2002-10-23 12:28 AM
Re: Array behaviour
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
Lonkero... thanks. I understand that part (I think) but then looking at my actual code, I'm not sure why its failing. I'd better post the actual code I've got. Basically it's using srvcheck.exe to generate a temp file listing shares and permissions on those shares for a server, and then parsing that file to give me a listing of those share details.
The file is generated in the format
quote: \\server\share1 [tab][tab]BUILTIN\Administrators [tab] Full Control [tab][tab]DOMAIN\Usergroup [tab] Change
\\server\share2 [tab][tab]BUILTIN\Administrators [tab] Full Control [tab][tab]DOMAIN\Usergroup1 [tab] Change [tab][tab]DOMAIN\Usergroup2 [tab] Read
\\server\share3 etc....
So my code, reading line by line, first checks whether I am reading the details for a new share, a new ACE, or the blank line in between shares.
Because I don't know how many shares, or permissions entries for each share I will have, I'm trying to build the results into an array of strings like this:
code:
$Share[0] = "\\server\share1" $Share[1] = "BUILTIN\Administrators" $Share[2] = "Full Control" $Share[3] = "DOMAIN\Usergroup" $Share[4] = "Change"
And then build these arrays, which will all be of different sizes, into a larger array called $Shares, where each element will represent a share on the server.
The code I'm currently working with is...
code:
$shellstr = "cmd.exe /c srvcheck.exe \\" + $computer + " > c:\shares.txt" ? $shellstr Shell $shellstr $x = Open(1,"c:\shares.txt") $x = Readline(1) $ShareCount = 0 While @ERROR = 0 $PermsCount = 0 If Instr($x,"\\") $ShareCount = $ShareCount + 1 $Share[$PermsCount] = $x $PermsCount = $PermsCount + 1 $x = Readline(1) Endif While Instr($x," ") $x = Right($x,(Len($x)-2)) $y = Split($x," ") $Share[$PermsCount] = $y[0] $PermsCount = $PermsCount + 1 $Share[PermsCount] = $y[1] $PermsCount = $PermsCount + 1 $x = Readline(1) Loop If $x = "" $x = Readline(1) Endif If $ShareCount $Shares[$ShareCount - 1] = $Share Endif Loop $x = Close(1)
It falls over at the line $Share[$PermsCount] = $y[0]. I suppose this is because when I first use $y, $PermsCount is 0. What should I do to get around this - I don't see how I can declare the size of $Share in advance?
Thanks for the quick response,
Breaker [ 22. October 2002, 12:28: Message edited by: Breaker ]
_________________________
================================================ Breaker
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 363 anonymous users online.
|
|
|