Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to create a temporary storage list

Status
Not open for further replies.

edowling

Technical User
Nov 17, 2000
12
US
I have a, Access DB that has a bunch of records in it "flashcards" that display questions and answers. I have written a VBA sting that will randomly select a new record each time I click the next button. However, I don't want the program to repeatedly select the same record.

I need to write a VBA string that pushes a chosen ID number onto a temporary list when the record with that ID number is pulled up. Then, I'll need an if...then statement to check that list each time the random number is chosen and if the record has come up, re-run the random generator. Is this possible? How do I create that temporary list that is delected at the end of each session?

Thanks,

Lis
 
Any way you can think of it. I would probably build an array with the random number and questions, sort by the random number. Then, when a random number between two values was generated, display the question and delete the item from the array.

Type MyFlashCards
ID As Integer
Question As String
End Type
Dim mFlashCards() As MyFlashCards

Public Sub CreateFlashCards(ID As Integer, Question As String)

Dim intUBound As Integer
intUBound = UBound(mFlashCards)
intUBound = intUBound + 1
ReDim Preserve mFlashCards(intUBound)
mFlashCards(intUBound).ID = ID
mFlashCards(intUBound)..Question = Question

End Sub

Public Function GetQuestion(ID As Integer) As String

Dim intPtr As Integer
For intPtr = 0 To UBound(mFlashCards)
If ID = mFlashCards(intPtr).ID Then
'Remove the question from the list by
'creating an ID outside the bounds of the
'valid ID number so it will never be
'found in a search.
mFlashCards(intPtr).ID = -1
GetQuestion = mFlashCards(intPtr).Question
Exit For
End If
Next intPtr

End Function



----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Use the random number generator in VB and normalize on
the function now() which is never the same even seconds later.

Rollie
 
Use the random number generator in VB and normalize on
the function now() which is never the same even seconds later. use emai for more specifics - rollie@bwsys.net

Rollie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top