WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Hacnstein on January 22, 2016, 10:20:02 AM

Title: Array
Post by: Hacnstein on January 22, 2016, 10:20:02 AM
I'm trying out WinBatch, I know some VB6, used InstantEXE, back in the day BASIC, CoBOL, ForTran and Pascal.
The problem, I have a text file I want to read line by line and load an array, then search it.
I started with the line count example
fn="C:\test\test.txt"
count=0
c = ArrDimension (count)
handle=FileOpen(fn,"READ")
While @TRUE
line=FileRead(handle)
If line=="*EOF*"
Break
Else
count=count+1
c[count] = line
EndIf
EndWhile
FileClose((handle))

It errors on c[count] = line.  I can't find a simple array example, they all are 2d or matrix like.
Title: Re: Array
Post by: td on January 22, 2016, 10:28:34 AM
Please read the ArrayFileGet function topic in the Consolidated WIL Help file
Title: Re: Array
Post by: jtrask on February 05, 2016, 02:03:14 PM
ArrayFileGet is the way to go in this instance, but you're script is failing because it you're trying to write to an element that does not exist.

ArrDimension(0) will yield an array with no rows.  ArrayDimension(1) will create as single dimension will one row.  The address of the elements are zero-indexed, but when you're creating the array, you're entering an actual count.

Also, by creating an array that doesn't already have all of the rows you'll need, you'll need to re-dimension the array with each new line you want to add.