Ok,I'm back with some code. I made a little program,it doesn't require media so I'll just post it(But I'm disecting it first
). First,I always use a sub to setup stuff that has anything to do with arrays. Here is the sub:
Setup_Keywords:
type tKeyword
kword as string
numLetters as integer
endtype
Global Dim gKeyword(0) as tKeyword
Global NumKeywords as integer
return
That sets up a udt called tKeyword, it declares the global array gKeyword as the udt,and it declares a variable that will store the total number of keywords at the moment. Then we move onto a function. Its called AddKeyword. It will be needed for the reading function. Here is the code to that:
Function AddKeyword(kword as string)
array insert at bottom gKeyword(0)
inc NumKeywords
w = NumKeywords
gKeyword(w).kword = lower$(kword)
gKeyword(w).numLetters = len(kword)
endfunction
What that does is it injects the array,increases the total amount of keywords. The total number of keywords,say like 10,would be the id for this single keyword. Thats what the w is,and thats why we use it as the array index. We simply just assign the gKeyword(w).kword as the string parameter. That means that you now have the keywords actual word assigned. Then it stores the number of letters in the keyword.
Next is the ReadKeywords function. Its quite simple,you just give the filename and it reads the lines of the file and stores them as keywords. Here is the code for that:
Function ReadKeywords(filename as string)
if file exist(filename)
file = FreeFile()
open to read file,filename
repeat
read string file,tmpword$
AddKeyword(tmpword$)
until file end(file)
close file file
endif
endfunction
The first line is just checking if the file exist,then it uses one of my functions to get a free file. it then opens to read. I told it to repeat the reading of the file until the file ends,so it will add each word on each line as a keyword(if you have two words on a line,they will be considered one word...). It uses the AddKeyword function to assign the words read to a keyword index in the gKeyword array. Here is the code for the freeFile thingy:
Function FreeFile()
repeat
inc i
until file open(i) = 0
endfunction i
Now here is an example used with the above code snippets:
Gosub Setup_Keywords
ReadKeywords("Keywords.txt")
Gosub Main
Setup_Keywords:
type tKeyword
kword as string
numLetters as integer
endtype
Global Dim gKeyword(0) as tKeyword
Global NumKeywords as integer
return
Main:
input "Guess the word ",in$
i = rnd(7)
if i = 0 then i = 1
if i = 8 then i = 7
kword$ = gKeyword(i).kword
if in$ = kword$ then print "YOU WIN!!!"
wait key
Gosub Main
return
Function AddKeyword(kword as string)
array insert at bottom gKeyword(0)
inc NumKeywords
w = NumKeywords
gKeyword(w).kword = lower$(kword)
gKeyword(w).numLetters = len(kword)
endfunction
Function ReadKeywords(filename as string)
if file exist(filename)
file = FreeFile()
open to read file,filename
repeat
read string file,tmpword$
AddKeyword(tmpword$)
until file end(file)
close file file
endif
endfunction
Function FreeFile()
repeat
inc i
until file open(i)=0
endfunction i
The keywords .txt is attatched. Hope this helped
all ben needs is his band,his guitar,and his computer