Posts: 99
Threads: 26
Joined: Dec 2004
When I execute the code below it tells me that it is expecting 'NEXT 'but instead finds '(' any ideas. I'm basically trying to get it to load each of the variable sin an arrray.
Code:
SUB AskQuestions
OPEN "UserOwnQuestionsAndAnswers" FOR INPUT AS #1
INPUT #1, NumberOfQuestions
FOR LoadQuestions = 1 TO NumberOfQuestions
INPUT #1, Questions$(LoadQuestions)
NEXT LoadQuestions
CLOSE #1
END SUB
Posts: 1,407
Threads: 117
Joined: Dec 2002
Have you DIMed Questions$ as a SHARED array?
Antoni
Posts: 99
Threads: 26
Joined: Dec 2004
I didn't know you had to do that, how do I do that?
I've changed it a bit and it now says expected 'END SUB' instead found '(', please compile it yourselves and see if you can figure it out.
Here is the whole program-
Code:
DECLARE SUB InputOwnQuestions
DECLARE SUB AskQuestions
PRINT "Welcome to MakeMeBilingual 1.0!"
PRINT
PRINT "1.Practise German Oral"
PRINT "2.Input Your Own Questions"
PRINT
INPUT "What would you like to do? ", UserDo
PRINT
SELECT CASE UserDo
CASE 1
'The sub AskQuestions is called here
AskQuestions
CASE 2
'The sub InputOwnQuestions is called here
InputOwnQuestions
END SELECT
SUB AskQuestions
OPEN "UserOwnQuestionsAndAnswers" FOR INPUT AS #1
INPUT #1, NumberOfQuestions
INPUT #1, Questions$(1)
CLOSE #1
END SUB
'Below is the InputOwnQuestion sub code
SUB InputOwnQuestions
INPUT "How many questions do you want to enter: ", NumberOfQuestions
PRINT
'Creates array which creates a number of variables based on the NumberOfQuestions answer
DIM Questions$(NumberOfQuestions)
'Creates seperate variables
FOR QuestionArray = 1 TO NumberOfQuestions
LET Questions$(QuestionArray) = "Question"
NEXT QuestionArray
'Cretaes array which hold answers
DIM Answers$(NumberOfQuestions)
'Creates seperate variables
FOR AnswerArray = 1 TO NumberOfQuestions
LET Answers$(AnswerArray) = "Answer"
NEXT AnswerArray
'Asks for questions and asnwers
FOR InputQuestions = 1 TO NumberOfQuestions
INPUT "Question: ", Questions$(InputQuestions)
INPUT "Answer: ", Answers$(InputQuestions)
PRINT
NEXT InputQuestions
'Opens file UserOwnQuestionsAndAnswers
OPEN "UserOwnQuestionsAndAnswers.txt" FOR OUTPUT AS #1
'Stores questionss variables in above file
FOR StoreQuestionsAndAnswers = 1 TO NumberOfQuestions
PRINT #1, Questions$(StoreQuestionsAndAnswers)
PRINT #1, Answers$(StoreQuestionsAndAnswers)
NEXT StoreQuestionsAndAnswers
PRINT #1, NumberOfQuestions
CLOSE #1
END SUB
SLEEP 1000
Posts: 1,688
Threads: 119
Joined: Jun 2003
I only took a quick glance, but it appears that the Dimming of Questions is local, not global. DIM SHARED it instead of just dimming it. i'm not sure if you can DIM SHARED it in a sub though... (in qb you can't) so you might have to REDIM SHARED it in the main code, then REDIM it in your routine.
Jumping Jahoolipers!