PDA

View Full Version : Compare GameIDs in list to add to arraylist VB.NET



khaos64
03-08-2012, 11:06 PM
I'd suggest grouping each gameid structure into it's own array, then shuffle those arrays, then output. That seems like the simplest way IMO

@./m
Thanks for the suggestion - I have been able to get all games into their own individual array, but haven't figured out a way to compare one to the next to see if they match to put them in array list together. I did at one point try and delete the "GameID: " portion so the array started right at the ID number, but still didn't know where to go from there. Any suggestions, Thanks.

j03
03-09-2012, 12:02 AM
Err like you said, but instead of removing "GameID:", why not extract the game ID value and the index of the array (to know where you're at) and then compare that way?

khaos64
03-09-2012, 01:30 AM
Err like you said, but instead of removing "GameID:", why not extract the game ID value and the index of the array (to know where you're at) and then compare that way?
Thanks for the reply Joe,

That was my original idea.

I was trying something like this to extract the ID's, Worked outside the loop but inside gave me an error and wasn't sure how to fix it/going about it a different way .



Dim arl As New ArrayList


For Each Itm As String In ListBox.Items
arl.Add(Itm)

Next

Dim stg(arl.Count) As String

For i As Integer = 0 To arl.Count - 1
Dim startTPos As Integer = stg(i).IndexOf("GameID: ") + 8
Dim endTPos As Integer = stg(i).IndexOf(" S")
Dim result = stg(i).Substring(startTPos, endTPos - startTPos)
MessageBox.Show(result)


Next



Fiddled a little more and found something that works at extracting the IDs, now just need to figure out the hard part.


For i As Integer = 0 To arl.Count - 1
Dim var As String = arl(i)
Dim arl2() As String

arl2 = var.Split(" ")
Dim result As String = arl2(1)
MessageBox.Show(result)


Next

Miguel
03-09-2012, 01:56 AM
I'm assuming you have lists somewhat like this:

+-------+-----+-----+------+------+---+
|gameID|time1|time2|score1|score2|mod|
+-------+-----+-----+------+------+---+
|1 |10
+-------+-----+-----+------+------+---+
|1 |13
+-------+-----+-----+------+------+---+
|2 |44
+-------+-----+-----+------+------+---+

etc...

Basically what I was suggesting was looping through your list, putting each one with a certain gameID into an array of sorts, then sorting THAT array

I.E. (php-esque psudocode)



games_array = array()
foreach(gamelist){
games_array[gameslist['id']] => gamelist
}


You'd end up with an array of multiple list items. Sort this however you see fit. Custom data structures might be useful for it as well, depending on your language

khaos64
03-09-2012, 02:29 AM
I'm assuming you have lists somewhat like this:

+-------+-----+-----+------+------+---+
|gameID|time1|time2|score1|score2|mod|
+-------+-----+-----+------+------+---+
|1 |10
+-------+-----+-----+------+------+---+
|1 |13
+-------+-----+-----+------+------+---+
|2 |44
+-------+-----+-----+------+------+---+

etc...

Basically what I was suggesting was looping through your list, putting each one with a certain gameID into an array of sorts, then sorting THAT array

I.E. (php-esque psudocode)



games_array = array()
foreach(gamelist){
games_array[gameslist['id']] => gamelist
}


You'd end up with an array of multiple list items. Sort this however you see fit. Custom data structures might be useful for it as well, depending on your language


Kinda went over my head with that one a little, I don't see how in VB.NET I could do it that way. Since the gameid's could always be changing from 3-4 characters and I don't know of a way to tell the program to recognize that the numbers after "GameID: " is to take identical IDs and make their own array. Not unless it is done someway as Joe had said by extracting the IDs and index to make an array.

Miguel
03-09-2012, 04:33 AM
Not sure if VB.NET has associative arrays or maps, maybe Joe can explain it better

khaos64
03-10-2012, 12:26 AM
Yea, I don't know.

But I think I may have found a way to do it, with something called a Bubble Sort, I just cant figure out what kind of IF will allow me to add each matching ID to an array and then start a new array once there isn't a match and start adding the IDs of matching to it until a nonmatching and and etc etc




Dim arl As New ArrayList
Dim arr As New ArrayList



For Each Itm As String In ListBox.Items
arl.Add(Itm)
Next

For k As Integer = 0 To arl.Count - 1
Dim var As String = arl(k)
Dim arl2() As String
arl2 = var.Split(" ")
arr.Add(arl2(1))


Next
Dim i, j As Integer
For i = 0 To arl.Count - 2
For j = i + 1 To arl.Count - 1
'' If arr(i) = arr(j) Then
''
''If Not arr(i) = arr(j) Then

''End If

'' End If


Next j
Next i


Do you think this maybe be able to do it or am I wasting my time?

Zachafer
03-11-2012, 12:30 PM
If you elaborated on your question and included example before and after data, I could help you.