#21609 - 2002-05-12 12:21 AM
Arrays
|
Vig
Starting to like KiXtart
Registered: 2001-11-14
Posts: 166
Loc: Saudi Arabia
|
I understan what an array is but I don't understand how to set them.
I'm trying to take the info from a .dat file and set each line as part of the array.
code:
Computer1 Computer2 Computer3 Computer4
This is the section in my script where I want to set the array. It's marked with the arrow.
code:
$SelectedDomain = $DomainBox.Text shell '%comspec% /c net view /domain:$SelectedDomain | Find /i "\\" > Domain.dat' $nul = open (2,Domain.dat,2) $Domain = Readline(2) Do Select Case Substr($Domain,1,12) = "" $= $Form.MsgBox("Could not find $SelectedDomain Domain", "Domain not found") $Nul = Close(2) Del Domain.dat Exit Case Substr($Domain,1,2) = "\\" $CompListBox.Additem (Rtrim(Substr($Domain,3,))) (Rtrim(Substr($Domain,3,)));<---------------------------------------------------------------Add this to an array Case 1 EndSelect $Domain = Readline(2) Until $Domain = "" $Nul = Close(2) Del Domain.dat
Thanks
|
|
Top
|
|
|
|
#21611 - 2002-05-12 03:43 AM
Re: Arrays
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
Les' suggestion is definitely good, but here's a solution for your particular piece of code. I am using a counter to see how many computers I've been reading and redimensionize the array each time I'm adding a computer to the array. It is not the most effective solution because of the constant resizing but it shows you how to use the arrays.
code:
Dim $Computerlist[0], $NumberComputers $SelectedDomain = $DomainBox.Text shell '%comspec% /c net view /domain:$SelectedDomain | Find /i "\\" > Domain.dat' $nul = open (2,Domain.dat,2) $Domain = Readline(2) $NumberComputers=0 Do Select Case Substr($Domain,1,12) = "" $Nul= $Form.MsgBox("Could not find $SelectedDomain Domain", "Domain not found") $Nul = Close(2) Del Domain.dat Exit Case Substr($Domain,1,2) = "\\" $CompListBox.Additem (Rtrim(Substr($Domain,3,))) redim preserve $ComputerList[$NumberComputers] $ComputerList[$NumberComputers]=(Rtrim(Substr($Domain,3,))) $NumberComputers=$NumberComputers+1 Case 1 EndSelect $Domain = Readline(2) Until $Domain = "" $Nul = Close(2) Del Domain.dat
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1592 anonymous users online.
|
|
|