I tried a different approach in getting my program to pull words from an external list and now I am getting a different error. I have both the .txt and .dba in a folder together named hangman. Can anyone see if they can get my program to work please. I have been having a hell of a time with this. Thanks guys! I've attached my wordlist with this post for everyone. Here is my updated code.
Rem ***** Main Source File *****
`Hangman
startofprogram:
cls
title()
gallows()
x as integer
words as string
x = 0
y as integer = 260
rem open the file and count the number of words
open to read 1, "externalword.txt"
while file end(1) = 0
read string 1, words
x = x +1
endwhile
close file 1
rem text number of words to screen
center text 320,240,"You have " + str$(x) + " words in externalword.txt"
wait key
remstart
the value of x for the array has now been determined by the above loop so
the array must be dimensioned here not in the earlier definition area
remend
dim wordarray(x-1)as string
rem read words from file and loads them into an array
open to read 1, "externalword.txt"
for ctr = 0 to (x-1)
read string 1, words
wordarray(ctr) = words
next ctr
close file 1
rem text the words to the screen
for ctr = 0 to (x-1)
center text 320,y,wordarray(ctr)
y = y + 20
next ctr
rem variable declaration section
rem dim wordlist(12) as string
rem dim itemletters(5) as string
num as integer
gitem as string
li as integer
rem assignment of value section
remstart
wordlist(0) = "queen"
wordlist(1) = "sword"
wordlist(2) = "spear"
wordlist(3) = "noble"
wordlist(4) = "fire"
wordlist(5) = "fief"
wordlist(6) = "serf"
wordlist(7) = "moat"
wordlist(8) = "bows"
wordlist(9) = "sly"
wordlist(10) = "die"
wordlist(11) = "oat"
wordlist(12) = "spy"
remend
randomize timer()
num = rnd(x-1)
gitem$ = wordarray(num)
li = len(gitem)
if li = 3
threeSpace()
else
if li = 4
threeSpace()
fourSpace()
else
threeSpace()
fourSpace()
fiveSpace()
endif
endif
for c = 1 to li
itemletters(c) = mid$(gitem$, c)
`printc itemletters(c)
next c
guess as string
usedletters as integer
letterguess as integer
wrongletters as integer = 0
winner as string = "You Win!"
errors = 0
found as integer = 0
set text size 18
set text font "times new roman"
input "Guess a letter or press qq to quit: ", guess
guess$ = lower$(guess$)
letterguess = 1
while guess<> "qq"
found = 0
rem for words that are 5 letters
if li = 5
if guess = itemletters(1)
text 115,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(2)
text 170,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(3)
text 215,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(4)
text 265,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(5)
text 305, 380, guess
usedletters = usedletters + 1
found = 1
endif
if usedletters = 5
cls
loopc = 1
while loopc < 30
text rnd(500), rnd(350), winner
loopc = loopc + 1
endwhile
goto start
end
endif
endif
rem for words that are 3 letters
if li = 3
if guess = itemletters(1)
text 115,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(2)
text 170,380, guess
usedletters = usedletters + 1
found = 1
endif
if guess = itemletters(3)
text 215,380, guess
usedletters = usedletters + 1
found = 1
endif
if usedletters = 3
cls
loopc = 1
while loopc < 30
text rnd(500), rnd(350), winner
loopc = loopc + 1
endwhile
wait key
goto start
end
endif
endif
if found = 0 and error = 0
head()
error = error + 1
else
if found = 0 and error = 1
body()
error = error + 1
else
if found = 0 and error = 2
larm()
error = error + 1
else
if found = 0 and error = 3
rarm()
error = error + 1
else
if found = 0 and error = 4
lleg()
error = error + 1
else
if found = 0 and error = 5
rleg()
error = error + 1
endif
endif
endif
endif
endif
endif
if error = 6
cls
for c = 1 to 30
sleep 250
text rnd(580), rnd(400), "Out of guesses, you lose!"
next c
endif
if guess = "qq"
endprogram()
endif
letterguess = letterguess + 1
if letterguess < 100
input "Guess a letter or press QQ to quit: ", guess
else
endif
endwhile
cls
end
goto start
function title()
set text font "algerian"
set text size 32
ink rgb(255, 255, 255), 0
text 250, 80, "Welcome To Hang-Man!"
ink rgb(255, 0, 0), 0
text 252, 82, "Welcome To Hang-Man!"
set text size normal
ink rgb(255, 0, 0), 0
endfunction
function Winner()
set text font "algerian"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You win!!! You win!!!"
ink rgb (0,0,255),0
text 201,46, "You win!!! You win!!!"
endfunction
function Lose()
set text font "algerian"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You Lose!!!"
ink rgb (0,0,255),0
text 201,46, "You Lose!!!"
endfunction
function gallows()
line 225, 175, 225, 425
line 225, 175, 325, 175
line 325, 175, 325, 225
endfunction
function head()
circle 325, 240, 15
endfunction
function body()
line 325, 255, 325, 310
endfunction
function rleg()
line 325, 310, 300, 360
endfunction
function lleg()
line 325, 310, 350, 360
endfunction
function rarm()
line 325, 255, 300, 295
endfunction
function larm()
line 325, 255, 350, 245
endfunction
function threeSpace()
Line 125, 450, 150, 450
Line 175, 450, 200, 450
Line 225, 450, 250, 450
endfunction
function fourSpace()
Line 125, 450, 150, 450
Line 175, 450, 200, 450
Line 225, 450, 250, 450
Line 275, 450, 300, 450
endfunction
function fiveSpace()
Line 125, 450, 150, 450
Line 175, 450, 200, 450
Line 225, 450, 250, 450
Line 275, 450, 300, 450
Line 325, 450, 350, 450
endfunction
function LetterWrong(sLetter$)
bOutput as boolean = 1
for c = 1 to array count(itemletters(0))
if itemletters(c) = sLetter$
bOutput = 0
exit
endif
next c
endfunction bOutput
function HandleError(errors)
inc errors
select errors
case 1
head()
endcase
case 2
body()
endcase
case 3
rleg()
endcase
case 4
lleg()
endcase
case 5
rarm()
endcase
case 6
larm()
endcase
endselect
endfunction errors