Click here to Skip to main content
Rate this: bad
good
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
 
        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 25-Jan-13 11:20am
Edited 25-Jan-13 11:22am
v3

1 solution

Rate this: bad
good
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.
 
http://msdn.microsoft.com/en-us/library/dwb5h52a.aspx[^]
  Permalink  
Comments
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? :-)
—SA
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 7,130
1 DamithSL 5,089
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,647
4 Kornfeld Eliyahu Peter 4,409


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
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