Click here to Skip to main content
11,706,455 members (37,607 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB
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!
Public Sub Gamepeicepick()
        Dim gametile As Integer = 0
            gametile = tilerand.Next(1, 62) ' NUmber of images to pick from

            If Numberlist.Contains(gametile) = True Then Continue Do
        Loop Until Numberlist.Count = 31
        Dim sb As New System.Text.StringBuilder
        For index As Integer = 0 To Numberlist.Count - 1
            sb.Append(Numberlist.Item(index).ToString & ",")
        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 25-Jan-13 10:20am
Edited 25-Jan-13 10:22am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.[^]
DinoRondelly at 25-Jan-13 16:41pm
Fact .. +5
Sergey Alexandrovich Kryukov at 25-Jan-13 16:59pm
Captain Obvious at work, a 5!
(Do you have any ideas why those guys use VB6? :-)
Dr David Johnson PhD at 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 at 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)

  Print Answers RSS
0 OriginalGriff 197
1 Sergey Alexandrovich Kryukov 141
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,070
1 Sergey Alexandrovich Kryukov 8,413
2 CPallini 5,189
3 Maciej Los 4,746
4 Mika Wendelius 3,676

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100