I have three files that are no more than text files with lists of names. Male names, female names and last names. I am trying to make a random name generator where the program first reads the number of names in each file (from a small text file) which works fine. The number of names always comes up great. Those are stored in GLOBAL variables.
Then I made who functions, one to get a first name based on the preferred sex of the name and then the second to simply grab a last name out of the last names file. However, whenever I try to access these functions, the program crashes. Only once did it ever read and then never again.
Here is the code I'm using which seems pretty simple.
Is this code correct or is there a more efficient way to do this?
FUNCTION GetFirstName(iSex as Integer)
iRand = 0
SELECT iSex
CASE 0
sFile$ = ".\Data\malenames.txt"
iRand = RND(iNumMaleNames - 1)+1
ENDCASE
CASE DEFAULT
sFile$ = ".\Data\femalenames.txt"
iRand = RND(iNumFemaleNames - 1)+1
ENDCASE
ENDSELECT
OPEN TO READ 1, sFile$
FOR Z = 1 to iRand
READ STRING 1, sRead$
NEXT Z
CLOSE FILE 1
sName$ = sRead$
ENDFUNCTION sName$
REM ==============================================================================
REM ==============================================================================
FUNCTION GetLastName()
iRand = 0
iRand = RND(iNumLastNames - 1) + 1
sFile$ = ".\Data\lastnames.txt"
OPEN TO READ 1, sFile$
FOR Z = 1 to iRand
READ STRING 1, sRead$
NEXT Z
CLOSE FILE 1
sName$ = sRead$
ENDFUNCTION sName$
-Grim