Page 1 of 1 1
Topic Options
#21609 - 2002-05-12 12:21 AM Arrays
Vig Offline
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
#21610 - 2002-05-12 01:10 AM Re: Arrays
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... usually I jump on a chance to teach something, but in this case, the lesson is why do it the hard way when Shawn has a UDF that can simplify it.

NetView - Enumerate all computers in your domain
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#21611 - 2002-05-12 03:43 AM Re: Arrays
Sealeopard Offline
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
#21612 - 2002-05-12 08:34 AM Re: Arrays
Vig Offline
Starting to like KiXtart

Registered: 2001-11-14
Posts: 166
Loc: Saudi Arabia
Thanks, that makes sense and I see how it's not the most effective way of doing it.
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 1592 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.051 seconds in which 0.026 seconds were spent on a total of 11 queries. Zlib compression enabled.

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