News:

Current release: WB 2024B (6.24bxb)

Main Menu

Array

Started by Hacnstein, January 22, 2016, 10:20:02 AM

Previous topic - Next topic

Hacnstein

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.

td

Please read the ArrayFileGet function topic in the Consolidated WIL Help file
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jtrask

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.