Select a level - search txt file for corresponding string
Posted: Wed Jun 17, 2015 2:35 pm
Hi!
I'm designing a program to help people practice speaking in other languages. I'm stuck on the second card, where they select which level they want to play. I was planning to have all the levels in a single text file (see below).
1. I want the user to enter which level they want to play,
2. then for the app to find the line in levels.txt with the corresponding level code (e.g. FrB201)
3. for the line number to be stored for future reference,
4. and finally, for the items on that line to be copied to a data grid.
However, I'm getting errors "chunk: no such object" and "Function: error in function handler" on the bolded lines below, respectively. I've tried about a dozen different variations and have read these three lessons repeatedly (can't refer you to them with proper links because my account on this forum is still pretty new, I guess):
44093-reading-and-writing-to-file
44092-Working-with-text
9849-how-can-i-search-delimited-data-for-a-matching-string
However, I haven't had any success to date. Any suggestions or other resources? Thanks!
levels.txt currently looks like this:
FrB201,177,Le voyage d'affaires,5
Did you have a nice trip?
How was your flight?
Where are you staying?
Is your hotel alright?
How long are you staying in London?
FrB202,178,S'excuser,5
I'm sorry for being late.
Please accept my apologies.
I was detained by a meeting.
There's a lot of traffic today.
Have you been waiting long?
EnA101,1,Say your nationality,5
Je suis français.
Etes-vous américaine ?
Non, je ne suis pas américaine.
Je suis français.
Je m'appelle François.
EnA101,2,Say your country/city,5
Je suis de la France.
Etes-vous de l'Irelande ?
Oui, je suis d'Irelande.
Comment allez-vous ?
Bien, merci, et vous ?
I'm designing a program to help people practice speaking in other languages. I'm stuck on the second card, where they select which level they want to play. I was planning to have all the levels in a single text file (see below).
1. I want the user to enter which level they want to play,
2. then for the app to find the line in levels.txt with the corresponding level code (e.g. FrB201)
3. for the line number to be stored for future reference,
4. and finally, for the items on that line to be copied to a data grid.
However, I'm getting errors "chunk: no such object" and "Function: error in function handler" on the bolded lines below, respectively. I've tried about a dozen different variations and have read these three lessons repeatedly (can't refer you to them with proper links because my account on this forum is still pretty new, I guess):
44093-reading-and-writing-to-file
44092-Working-with-text
9849-how-can-i-search-delimited-data-for-a-matching-string
However, I haven't had any success to date. Any suggestions or other resources? Thanks!
Code: Select all
on loadlevels
global gLevel, gStartLine
put empty into field fld.leveldata
if there is a file "levels.txt"
read from file ("levels.txt") until EOF
put it into field fld.leveldata
else
beep
end if
ask "Which level do you want to try? e.g. FrB201"
put it into gLevel
[b] put lineoffset (gLevel, field fld.leveldata,0) into gStartLine
put line gStartline of field fld.leveldata into field grid.userdata[/b]
end loadlevels
FrB201,177,Le voyage d'affaires,5
Did you have a nice trip?
How was your flight?
Where are you staying?
Is your hotel alright?
How long are you staying in London?
FrB202,178,S'excuser,5
I'm sorry for being late.
Please accept my apologies.
I was detained by a meeting.
There's a lot of traffic today.
Have you been waiting long?
EnA101,1,Say your nationality,5
Je suis français.
Etes-vous américaine ?
Non, je ne suis pas américaine.
Je suis français.
Je m'appelle François.
EnA101,2,Say your country/city,5
Je suis de la France.
Etes-vous de l'Irelande ?
Oui, je suis d'Irelande.
Comment allez-vous ?
Bien, merci, et vous ?