English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2006-12-22 01:39:53 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

When I started the program, I did it without the tags and it worked wonderfully. I then added the lines for the tags and it stopped working.

Private Sub lblHistory_Click()
Dim PickRand As Single
Pick: PickRand = Int((Rnd * 3) + 1)
If PickRand = 1 And fraHistory1.Tag = 0 Then
fraHistory1.Visible = True
Else: GoTo Pick
End If
If PickRand = 2 And fraHistory2.Tag = 0 Then
fraHistory2.Visible = True
Else: GoTo Pick
End If
If PickRand = 3 And fraHistory3.Tag = 0 Then
fraHistory3.Visible = True
Else: GoTo Pick
End If
End Sub

2006-12-22 01:55:11 · update #1

6 answers

check out http://www.pscode.com for some great examples

2006-12-22 14:07:58 · answer #1 · answered by Richard H 7 · 0 0

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

2006-12-22 13:59:26 · answer #2 · answered by MarkG 7 · 0 0

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!

2006-12-22 11:33:48 · answer #3 · answered by Special Ed 5 · 0 0

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.

2006-12-22 09:43:33 · answer #4 · answered by Anonymous · 2 0

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

2006-12-22 09:44:17 · answer #5 · answered by Julio M 3 · 0 0

go to Google guru and find out

2006-12-22 09:50:21 · answer #6 · answered by sharma ji 1 · 0 0

fedest.com, questions and answers