while/wend or eof error in Linux

new BookmarkLockedFalling
Psycho
Full Member
***

Psycho Avatar

Posts: 196

Post by Psycho on Jan 14, 2009 23:10:51 GMT -5

I'm not sure which function is causing the error but I narrowed down an example piece of code that works fine in Windows but yields the following error in Linux:
Runtime Error in program 'untitled': #users, username$(m)
Index out of bounds: 3


To test, I created a file in the public folder titled "users.txt" and put the following garbage entries into it:

2
My Name
pass1
1
Another Name
pass2
1

Where it should read the first line as the number of items for the dim statements, then input the actual values from the next 6 lines.

Following is the code excerpt that produces the error:

 open "public/users.txt" for input as #users
line input #users, numberofusers
'Set the variables to match the number of users
dim username$(numberofusers)
dim password$(numberofusers)
dim adminflag(numberofusers)
m=1
while eof(#users) = 0
line input #users, username$(m)
line input #users, password$(m)
line input #users, adminflag(m)
m=m+1
wend
close #users


Using Ubuntu 8.04

John "Psycho" Siejkowski

EDIT: As a side note, anyone using Linux should be able to figure it out but, the readme.txt file for starting RB in Linux still says "-cd to the rb101b3 folder" from the last beta.
Last Edit: Jan 14, 2009 23:14:32 GMT -5 by Psycho
votan
Senior Member
****

votan Avatar

Posts: 304

Last Edit: Jan 15, 2009 15:48:32 GMT -5 by votan
Carl Gundel - admin
Administrator
*****

Carl Gundel - admin Avatar

Posts: 550

Post by Carl Gundel - admin on Jan 16, 2009 21:42:36 GMT -5

Here's an example of the program that also creates the file. Does this work on your machine? It works fine on my Ubuntu system. I changed the file name so it won't overwrite your file.

 open "public/myusrs.txt" for output as #users
print #users, "3"
print #users, "Fred"
print #users, "foo"
print #users, "1"
print #users, "Steve"
print #users, "arf"
print #users, "0"
print #users, "Tim"
print #users, "tiny"
print #users, "1"
close #users
open "public/myusrs.txt" for input as #users
line input #users, numberofusers
'Set the variables to match the number of users
dim username$(numberofusers)
dim password$(numberofusers)
dim adminflag(numberofusers)
m=1
while eof(#users) = 0
line input #users, username$(m)
print username$(m)
line input #users, password$(m)
line input #users, adminflag(m)
m=m+1
wend
close #users

Also, do you realize that saving data into the public folder will allow people on the internet to look at the file if they know the name? The name users.txt is pretty easy to guess for hacker types.

-Carl
Last Edit: Jan 16, 2009 21:44:50 GMT -5 by Carl Gundel - admin
Psycho
Full Member
***

Psycho Avatar

Posts: 196

Post by Psycho on Jan 16, 2009 23:01:43 GMT -5

Carl Gundel - admin Avatar

Also, do you realize that saving data into the public folder will allow people on the internet to look at the file if they know the name? The name users.txt is pretty easy to guess for hacker types.

-Carl


Thanks for the advice on the public folder but I only set this file up in there for testing this issue. Normally it's tucked safely away in another folder ;)

As for the problem, I was about to list it as bizarre when I ran your code successfully, then pasted my code at the end of it only to get the same error. After much fiddling around, I created a new text file with the same info and it worked. Looking back, my test file was a stripped down version of my real file that had been copied from Windows :P. Despite being a plain text file there must be something different about from Windows because it wouldn't work for anything ???

That being said, this one can be checked off as closed. Thanks for looking into it.

John
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Post by StefanPendl on Jan 17, 2009 6:22:22 GMT -5

Psycho Avatar
Looking back, my test file was a stripped down version of my real file that had been copied from Windows :P. Despite being a plain text file there must be something different about from Windows because it wouldn't work for anything ???

Plain text files are plain text files on any system, the problem is the EOL (End Of Line) character.
  • Windows ... CHR$(13) + CHR$(10)
  • Linux ... CHR$(10)
  • MAC ... CHR$(13)

More details at en.wikipedia.org/wiki/Newline
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
Psycho
Full Member
***

Psycho Avatar

Posts: 196

Post by Psycho on Jan 17, 2009 15:27:20 GMT -5

StefanPendl Avatar
Psycho Avatar
Looking back, my test file was a stripped down version of my real file that had been copied from Windows :P. Despite being a plain text file there must be something different about from Windows because it wouldn't work for anything ???

Plain text files are plain text files on any system, the problem is the EOL (End Of Line) character.
  • Windows ... CHR$(13) + CHR$(10)
  • Linux ... CHR$(10)
  • MAC ... CHR$(13)

More details at en.wikipedia.org/wiki/Newline


Well, that certainly explains it ::)

Thanks Stefan.