Click here to Skip to main content
15,886,825 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
I am using the code below inside a program I am building.

How can I reset the numberlist.count to 0 when I need to call the routine again?
The program keeps telling me that the numberlist.count is a read only variable. Other than not being able to reset it, the code works 100%.

Any suggestions would be greatly welcomed!
VB
Public Sub Gamepeicepick()

        Dim gametile As Integer = 0

        Do
            Randomize()

            gametile = tilerand.Next(1, 62) ' NUmber of images to pick from

            If Numberlist.Contains(gametile) = True Then Continue Do

            Numberlist.Add(gametile)

        Loop Until Numberlist.Count = 31

        Numberlist.Sort()

        Dim sb As New System.Text.StringBuilder
        For index As Integer = 0 To Numberlist.Count - 1
            sb.Append(Numberlist.Item(index).ToString & ",")
        Next

        Tile01 = (Numberlist.Item(0))
        Tile02 = (Numberlist.Item(1))
        Tile03 = (Numberlist.Item(2))
        Tile04 = (Numberlist.Item(3))
        Tile05 = (Numberlist.Item(4))
        Tile06 = (Numberlist.Item(5))
        Tile07 = (Numberlist.Item(6))
        Tile08 = (Numberlist.Item(7))
        Tile09 = (Numberlist.Item(8))
        Tile10 = (Numberlist.Item(9))

        Tile11 = (Numberlist.Item(10))
        Tile12 = (Numberlist.Item(11))
        Tile13 = (Numberlist.Item(12))
        Tile14 = (Numberlist.Item(13))
        Tile15 = (Numberlist.Item(14))
        Tile16 = (Numberlist.Item(15))
        Tile17 = (Numberlist.Item(16))
        Tile18 = (Numberlist.Item(17))
        Tile19 = (Numberlist.Item(18))
        Tile20 = (Numberlist.Item(19))

        Tile21 = (Numberlist.Item(20))
        Tile22 = (Numberlist.Item(21))
        Tile23 = (Numberlist.Item(22))
        Tile24 = (Numberlist.Item(23))
        Tile25 = (Numberlist.Item(24))
        Tile26 = (Numberlist.Item(25))
        Tile27 = (Numberlist.Item(26))
        Tile28 = (Numberlist.Item(27))
        Tile29 = (Numberlist.Item(28))
        Tile30 = (Numberlist.Item(29))
        Tile31 = (Numberlist.Item(30))


    End Sub
Posted
Updated 25-Jan-13 10:22am
v3

1 solution

You can't reset the count, it is exactly what the name implies. Count gets the number of objects in the List. If you want to reset the count you have to reset the list. To do that just call Clear on the list.

http://msdn.microsoft.com/en-us/library/dwb5h52a.aspx[^]
 
Share this answer
 
Comments
DinoRondelly 25-Jan-13 16:41pm    
Fact .. +5
Sergey Alexandrovich Kryukov 25-Jan-13 16:59pm    
Captain Obvious at work, a 5!
(Do you have any ideas why those guys use VB6? :-)
—SA
Dr David Johnson PhD 27-Jan-13 14:28pm    
Thanks for the quick help....

I was not fully aware of the Count function when I used it.
Now that I understand, I was able to store the list in a second
file, clear the first and re-generate the new number.

Thanks again...
Adam R Harris 27-Jan-13 15:03pm    
Glad I could help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900