• Welcome to Jose's Read Only Forum 2023.
 

O2 question about initializing array of strings

Started by Ed Davis, July 27, 2022, 08:59:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ed Davis

I'm using the following code to (re)initialize an array of strings:

includepath "$\inc\"
include "console.inc"

% c_maxlines = 7000
dim pgm(1 to c_maxlines) as string

sub newstmt()
  dim i as integer

  print("In newstmt, starting for loop" & cr)
  for i = 1 to c_maxlines
    print(i & " ")
    pgm(i) = ""
  next i
  print(cr & "Returning from newstmt" & cr)
end sub

print(version & " Calling newstmt" & cr)
call newstmt()
print("Done" & cr)
getkey()


But it crashes at either 851 or 1641 rows initialized.  What am I doing wrong?
This is in 040 downloaded from github.

Anyone else able to try it, to see if it works for you?

Zlatko Vid

hello Ed
this code work

includepath "$\inc\"
include "console.inc"

% c_maxlines = 7000
dim pgm(c_maxlines) as string

sub newstmt()
  dim i as integer

  print("In newstmt, starting for loop" & cr)
  for i = 1 to c_maxlines
    print(i & " ")
    pgm(i) = ""
  next i
  print(cr & "Returning from newstmt" & cr)
end sub

print("Calling newstmt" & cr)

newstmt()

print("Done" & cr)
getkey()

Charles Pegge

Yes, the dim statement was the only problem.

o2 defaults to indexbase 1 anyway


''dim pgm(1 to c_maxlines) as string
indexbase 1
dim pgm(c_maxlines) as string