VB阵列重置问题 [英] VB array reset problem

查看:125
本文介绍了VB阵列重置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我正在构建的程序中使用下面的代码。



如何重置 numberlist.count 为0?

程序一直告诉我 numberlist.count 是一个只读变量。除了无法重置之外,代码100%工作。



任何建议都会受到欢迎!

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

推荐答案

你不能重置计数,这正是名称所暗示的。 Count获取List中的对象数。如果要重置计数,则必须重置列表。要做到这一点,只需在列表中调用清除。



http://msdn.microsoft.com/en-us/library/dwb5h52a.aspx [ ^ ]
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[^]


这篇关于VB阵列重置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆