I'm making a trivia program in visual basic 6. Each question is on a frame, like a card. The cards come up randomly and I'd like to make it so that the same question will not come up twice. I've tried to use tags (fraQuestion.tag) and set the value = 0 at the beginning of the program and then to 1 once the frame is displayed. This seems like it should work, but it doesn't. It just freezes my program.
How do you use tags in visual basic?
check out http://www.pscode.com for some great examples
Reply:are you certain that that specific line is that freezes up the comp? did you go into debug and in that line it just freezes up? any chance of you putting up some code? The tag property is just a string you can set for your additional information on keeping tabs on your forms, very useful when creating forms dynamically out. Let us know. Cheers
Reply:I agree with the first poster.
However, I would just use an 2-dimensional array with the 2nd element being the flag (1 or 0). I see no need to traverse 2 arrays, unless of course for fun and practice!
Good luck!
Reply:go to Google guru and find out
Reply:I have used tags to do the following:
Pass a value back from a dialog form to the calling form without having to use a global or public variable.
Use the Tag property to hold a code value of the type of data validation I wished the texbox to perform. A for alpha, N for numeric ect... Then call a validation routine passing the code letter which uses a select case to determine the type of keyascii modification to perform.
As to asking questions once...
Load an array with your question and answer string. Have the question and answer delimited with a character like '#'.
This way you can use one array to keep Questions and answers.
It will be just a matter of splitting the string and extracting the question for display.
Load the array from a text file and increment a counter (count) as each question is loaded into the array.
Generate a random number from 0 to count .
Use this random number as an index to extract a question.
Next Shift all records above the currently selected question down one position and decrement the record count by 1
So as you use questions from your stack of questions you are moving the count to a lower position (shrinking the stack of available questions which remain)
To move the data above the selected question down 1 position
just use a FOR/NEXT loop to generate an index value (X) which cycles from the current random number to the last valid index value which is (count-1)
for x = currentRandom to (count-1)
myArray(x) = myArray(x-1)
next
count = count - 1 'decrement the record count
Reply:Make two synchronized arrays. One representing the question strings, the other representing a boolean flag of whether it was asked or not. When you choose a random question, pick again while the flag is true. Then assign that string to your question label and set that flag to true.
That's a basic programming concept.
UPDATE: Wow, first of all, get rid of those goto, they're extremely tasteless. Use a loop, instead.
myspace
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment