LEN seems linked to issue with array referencing
circular opened this issue · 2 comments
circular commented
Hi, I'm enjoying SmallBASIC and wanted to share this issue in case it's relevant.
Version: SmallBasic FLTK 12.23, 7 Sep 2021
OS: Linux / AppImage
As an example, running the example here, an error is thrown:
https://smallbasic.github.io/pages/features.html
Code:
tload "/etc/passwd", buffer
for row in buffer
split row, ":", fields()
if (len(fields) > 0) then
local user
user.name = fields(0)
user.passwd = fields(1)
user.userId = fields(2)
user.groupId = fields(3)
users << user
fi
next row
? users
Error: RTE-ERROR AT untitled.bas:7 *
Description:
Array: Index '1' out of range. (Max = 1)
(Note: I changed the HTML codes for less-than, to << in the code to get it to work)
As a workaround, I changed LEN to UBOUND and the code worked fine.
chrisws commented
Thanks for reporting this. The problem was SPLIT with empty input was returning an array with one empty item. It should return LEN(fields) == 0
chrisws commented
Fixed in next update