#176359 - 2007-05-21 10:45 AM
Adding items to an Array during a loop
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
I've been trying to add items to an array during a loop without success, in VB there is the Array.Add() but apprantly this doesn't work in KiX. Can anyone shed some light on this for me ?
To be more exact, I'm trying to do this without the Split() Join() functions. Here's my example test code
Dim $fso, $txt
Dim $Array[5]
$fso = CreateObject("Scripting.FileSystemObject")
$txt = $fso.OpenTextFile("c:\boot.ini",Not 0)
While Not $txt.AtEndOfStream
;? $txt.ReadLine
$Array.Add($txt.ReadLine)
Loop
$txt.Close
For Each $item in $Array
? "Line: " + $item
Next
|
|
Top
|
|
|
|
#176367 - 2007-05-21 02:26 PM
Re: Adding items to an Array during a loop
[Re: DrillSergeant]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
For this particular application you could get away with ReadAll and a single split:
Dim $fso, $txt
$fso = CreateObject("Scripting.FileSystemObject")
$txt = $fso.OpenTextFile("c:\boot.ini",Not 0)
$Array=Split($txt.ReadAll,@CRLF)
$txt.Close
For Each $item in $Array
? "Line: " + $item
Next
|
|
Top
|
|
|
|
#176372 - 2007-05-21 04:01 PM
Re: Adding items to an Array during a loop
[Re: Richard H.]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Richard, I wrote this particular code as per example to illustrate what I ment I know about the ReadAll, thanks though 
Drill Sergeant: Your second suggestion works perfect  I've implented it like this:
Dim $fso, $txt, $item, $Array
$fso = CreateObject("Scripting.FileSystemObject")
$Array = CreateObject("System.Collections.ArrayList")
$txt = $fso.OpenTextFile("c:\boot.ini",Not 0)
While Not $txt.AtEndOfStream
$Array.Add($txt.ReadLine)
Loop
$txt.Close
For Each $item in $Array
? "Line: " + $item
Next
I still find it weird that there is no builtin kix way to Add stuff to an array. Besides, this way works fine however it does require the dotnet framework.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 302 anonymous users online.
|
|
|