Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 13 Feb 2011, 13:31
I get a runtime error (File Error -1) using this code - why?
Code: Select all
char LCDline[]={56,48,40,32,24,16,8,0};
task main()
{
int i=1, j=1;
ListFilesType args;
args.Pattern = "*.rxe";
SysListFiles(args);
while (args.Result == NO_ERR && ArrayLen(args.FileList) > 0)
{
TextOut(0, LCDline[i], args.FileList[j]);
if(i<7) i++;
j++;
}
while(true);
}
spillerrec
Posts: 358 Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:
Post
by spillerrec » 13 Feb 2011, 16:48
You have a never ending loop, yet you increment the array position for each time so it will obviously end in an access violation error.
Changing the "0" to "j" in the following line seems to have fixed it:
Code: Select all
while (args.Result == NO_ERR && ArrayLen(args.FileList) > 0)
HaWe
Posts: 2500 Joined: 04 Nov 2014, 19:00
Post
by HaWe » 13 Feb 2011, 17:21
thank you very much, now I finally understand the sence of the 2nd while argument!
I changed the code, now it's fine :)
Code: Select all
char LCDline[]={56,48,40,32,24,16,8,0};
task main()
{
int i=0, j=0;
ListFilesType args;
args.Pattern = "*.*";
SysListFiles(args);
while (args.Result == NO_ERR && j < ArrayLen(args.FileList))
{
TextOut(0, LCDline[i], args.FileList[j]);
if(i==7) {
i=0;
Wait(500);
ClearScreen();
}
i++;
j++;
}
while(true);
}
Users browsing this forum: No registered users and 3 guests