Valhalla Legends Forums Archive | Battle.net Bot Development | Queue Sorting

AuthorMessageTime
LockesRabb
This is what I have so far:

[code]Private Type Queue
    DataToSend As String
    Priority As Integer
End Type

Dim BotQueue(200) As Queue

Private Sub Command1_Click()
    Dim HighPriorityQueue() As Queue
    Dim MediumPriorityQueue() As Queue
    Dim LowPriorityQueue() As Queue
   
    tmpArray = Split(Text1, vbCrLf)
    For i = 0 To UBound(tmpArray) Step 2
        BotQueue(i).DataToSend = tmpArray(i)
        BotQueue(i).Priority = tmpArray(i + 1)
    Next
   
    HighPriorityQueue = GetPriorityQueue(BotQueue, 2)
    MediumPriorityQueue = GetPriorityQueue(BotQueue, 1)
    LowPriorityQueue = GetPriorityQueue(BotQueue, 0)
   
    Text2 = Text2 & "Processing High Priority Queue... " & vbCrLf
    For i = 0 To UBound(HighPriorityQueue)
        Text2 = Text2 & vbCrLf & HighPriorityQueue(i).DataToSend
    Next
   
    Text2 = Text2 & "Processing Medium Priority Queue... " & vbCrLf
    For i = 0 To UBound(MediumPriorityQueue)
        Text2 = Text2 & vbCrLf & MediumPriorityQueue(i).DataToSend
    Next
   
    Text2 = Text2 & "Processing Low Priority Queue... " & vbCrLf
    For i = 0 To UBound(LowPriorityQueue)
        Text2 = Text2 & vbCrLf & LowPriorityQueue(i).DataToSend
    Next
   
    Text2 = Text2 & vbCrLf & "Done processing queues."
End Sub

Private Function GetPriorityQueue(tmpArray() As Queue, PriorityLevel As Integer)
    Dim tmpPriorityQueue() As Queue
    Dim l As Integer
    l = 0
    For i = 0 To UBound(tmpArray)
        If tmpArray(i).Priority = PriorityLevel Then
            tmpPriorityQueue(l).DataToSend = tmpArray(i).DataToSend
            tmpPriorityQueue(l).Priority = tmpArray(i).Priority
            l = l + 1
        End If
    Next
    GetPriorityQueue = tmpPriorityQueue
End Function[/code]

The form had two textboxes (Text1 and Text2), and a command button. In Text1, I had the following text:

[pre]hey whats up
0
nothing much
0
/ban somebody
3
,dsl
2
,rank
2
heh yeah
0
/kick somebody
3[/pre]

I ran the program to test it, inputted the above data, clicked the command button. I got this error:

[pre]Compile Error:

Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions[/pre]

So I switched the user-defined Queue type to a module, made it public, and tried again. Same error.

It was at this point my mind pretty much fizzled. Basically I'm trying to sort the BotQueue array which is of a custom type into three separate queues which correspond to their level of priorities...

Any idea what I'm doing wrong?
July 27, 2006, 5:48 AM
Stealth
I'd suggest couple easy options, both of which require creating a basic queue-item class object and then storing a bunch of those objects in a Collection. You could:

- Add high-priority items at the front of the queue (or closer to the front of the queue, anyways) than lower-priority items. You can accomplish this with a Collection, as rearranging the elements of a dynamic array is a pain in the ass. With this method, you would simply always send the front item of the queue because you arranged things the way you wanted them to come out with each addition to the queue;

- Look through your queue ahead of time, storing the index of the highest-priority item, something like this:

[code](pseudo)
the highest-priority-item so far's index is 1 (send the item at the front of the queue by default)
the highest priority seen so far is 0 (no higher-priority items exist so far)

for each queue item
    if its priority exceeds (> comparison) the highest priority seen so far
        the highest priority seen so far is this item's priority
        the highest-priority-item so far's index is this index
[/code]

The result here is that the work is done each time your queue "ticks". With this method, you remove and dispatch the message you determine to have the highest-priority on the fly.

Good luck - HTH, and people with more knowledge of these things and I -- feel free to comment! I'm always interested in better ways to do this sort of thing as well.
July 27, 2006, 10:05 PM
LockesRabb
Are there any collections tutorials? I tried googling them, but the results were mostly irrelevant...
July 27, 2006, 10:14 PM
HeRo
http://people.revoledu.com/kardi/tutorial/VB/lesson06/Collection.htm

^Thats one of many from googling:
visual basic collection tutorials
July 27, 2006, 10:27 PM
LockesRabb
I was using vb6 collections as the keywords. that's probably why i had bad results.
July 27, 2006, 10:49 PM
Arta
See: Priority Queues
July 28, 2006, 10:16 AM

Search