Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

How do you use tags in visual basic?

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.

Update:

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

6 Answers

Relevance
  • 1 decade ago
    Favorite Answer

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

  • MarkG
    Lv 7
    1 decade ago

    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

  • 1 decade ago

    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!

  • Anonymous
    1 decade ago

    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.

  • How do you think about the answers? You can sign in to vote the answer.
  • 1 decade ago

    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

  • 1 decade ago

    go to Google guru and find out

    Source(s): follow my instruction
Still have questions? Get your answers by asking now.