Skip to content

Reply To: PALTRIVIA Problem :!:


Looks kool loco, but one thing how are you gonna have teams? would have to be a certain thing they would have to type perhaps to choose?

to randomize the questions you will have to give each one a number to identify it properly.

this code isnt mine but maybe it will help you for randomizing it another way,

' ### Just paste everything below into VB under a command button or ###
' ### something, then you'll see which bits are comments. ###

' One way to randomize a list of items. For this you'll need three
' listboxes, named 'Openlist', 'Donelist' and 'Templist' (minus
' quotes. There's probably a better way to do this, but this is just what
' I came up with. It's simple really, but hopefully it should help someone.
' Comments or suggestions, contact me via the contact form on PSC. If you
' want to use this with an array, just modify the adding, deleting and
' counting actions for whatever you need. You'll need a bit of Rediming in
' there too.

' No warranty is provided for this script or its actions, neither expressed
' nor implied. No liability is assumed for the use, misuse, or inability to
' use this script, or the consequences thus.

Dim fromline As Double
Dim thisixloc As Double
' Names used here:
' Openlist - this is a listbox containing all the items you want to
' randomize. Where I've used it, it's contained lines opened
' from a text file, hence 'Openlist' - Just replace all if
' you really must change it
' Donelist - This is the listbox which will contain the finished product
' when it's all been randomized
' Templist - The temporary store for the latter part of the Donelist (more
' later)
' thisixloc - The current index number a new item should take (more later)
' fromline - The current line index we're dealing with

' Clear the Donelist. Start with a clean slate
' Add the first item to the donelist.
' It doesn't matter what item is added first, since by the end it could be
' anywhere in the list
Donelist.AddItem (Openlist.List(0))
' We're going to do this process for every item in the Openlist, otherwise
' we'd be leaving things out. Common sense really
For Item = 1 To Openlist.ListCount - 1
' Generate a new random seed. Make all this randomness a little more
' random
' This generated an index location number, i.e. after this process has
' finished, this is the index number we want it to end up as. Bear in
' mind we're working in Base 0 here, so we start from 0. Also, the new
' item could go at the end of the list. So that would be the highest
' index value plus 1, which is the same as the ListCount, so we'll use
' that instead. The formula here is:
' Int((Highest - Lowest + 1) * Rnd + Lowest)
' Just generates us a number between our upper and lower bounds. Note
' that because we have 0 as a lower bound, adding or subtracting it does
' nothing, so the -0 and +0 just disappear to leave us with the
' following:
thisixloc = Int((Donelist.ListCount + 1) * Rnd)
' If the generated index number is 0, it means the current item is gonna
' be put at the start of the list.
If thisixloc = 0 Then
' So, we clear the temp store (here Templist) just in case, for whatever
' reason, there's something left over in there...
' ...move everything in Donelist over to the temporary store...
For fromline = 0 To Donelist.ListCount - 1
Templist.AddItem (Donelist.List(fromline))
Next fromline
' ...clear the donelist...
' ...add the item...
Donelist.AddItem (Openlist.List(Item))
' ...move all the items back after the new item...
For fromline = 0 To Templist.ListCount - 1
Donelist.AddItem (Templist.List(fromline))
Next fromline
' ...and finally clear the temp store so it's fresh for next time
' it's used
' If our index number is one higher than the highest index in the
' donelist, this means we want to put the item on the end of the list
ElseIf thisixloc = Donelist.ListCount Then
' So of course, we just add it straight on there
Donelist.AddItem (Openlist.List(Item))
' Any other index number means we're gonna have to slip it into the
' list, in between what's already there. So, we'll split the list
' in two. The first part will be everything up to where we want the
' item to go, and the second part will be everything after it. So,
' we'll move the second part to the temporary store, remove the items
' that we just transferred, add the new item to the end of the first
' part of the list, then transferring everything back from the temp
' store, sticking it back on the end of our list.
' EDIT: Originally what I did was move the first part to one store,
' then the second to another store. Re-add the first one, then
' the item, then the second one. However, this meant that in the
' computer memory, the list had to be duplicated, taking up both
' memory itself and time. Especially for long lists, duplicating
' a large portion of the list when it's not required was a silly
' thing to be doing. So now, hopefully, if we just delete things
' off the end, the first part can stay exactly where it was in
' the memory, and we just add to it.
' Clear the temporary store, again in case there's something left
' there for whatever reason
' Now, we'll take the second part of the list (from the index
' location right to the end) and put it in the temp store.
' If I type 'story' instead of 'store' one more time I'll go nuts
For fromline = thisixloc To Donelist.ListCount - 1
Templist.AddItem (Donelist.List(fromline))
Next fromline
' Now, we'll remove exactly the same items. We couldn't really
' remove them in the For Next loop above or we'd end up messing
' up our index numbers and making the process one helluva lot more
' complex than it really needs to be. Note that as the number of
' items in the list decreases as we delete them, we can just keep
' deleting whatever's in the current index location. If we do this
' the number of times there are things to delete, then all of them
' will go
For fromline = thisixloc To Donelist.ListCount - 1
Donelist.RemoveItem (thisixloc)
Next fromline
' Here comes our new item
Donelist.AddItem (Openlist.List(Item))
' Then move everything back onto the end of that list...
For fromline = 0 To Templist.ListCount - 1
Donelist.AddItem (Templist.List(fromline))
Next fromline
' ...and clear the temp store again
End If
Next Item