Basic4Android shuffle代码

时间:2014-06-21 09:30:36

标签: basic basic4android

基本上我需要将这个Visual Basic代码翻译成Basic4Android代码。 我想要做的是随机分配从1-15和一个空的16个按钮值。每次他们都会有所不同。我已经在VB中完成了它并且它可以工作,但我知道我想在Android上制作它。

Sub Shuffle()
    Dim a(15), i, j, RN As Integer
    Dim flag As Boolean

    flag = False
    i = 1
    a(j) = 1

    Do While i <= 15
        Randomize()
        RN = CInt(Int((15 * Rnd()) + 1))

        For j = 1 To i
            If (a(j) = RN) Then
                flag = True
                Exit For
            End If
        Next

        If flag = True Then
            flag = False
        Else
            a(i) = RN
            i = i + 1
        End If

    Loop

    Form1.Button1.Text = a(1)
    Form1.Button2.Text = a(2)
    Form1.Button3.Text = a(3)
    Form1.Button4.Text = a(4)
    Form1.Button5.Text = a(5)
    Form1.Button6.Text = a(6)
    Form1.Button7.Text = a(7)
    Form1.Button8.Text = a(8)
    Form1.Button9.Text = a(9)
    Form1.Button10.Text = a(10)
    Form1.Button11.Text = a(11)
    Form1.Button12.Text = a(12)
    Form1.Button13.Text = a(13)
    Form1.Button14.Text = a(14)
    Form1.Button15.Text = a(15)
    Form1.Button16.Text = ""
End Sub

我知道只有改变&#34;整数&#34;到&#34; Int&#34;并删除所有&#34; Form1&#39; s&#34;。我不能使用Randomize(),也不能使用CInt和Int语句,因为它们会给我错误。

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助。它的代码用于获取随机数而不重复。 你可以根据你的要求改变我。

Sub Activity_Create(FirstTime As Boolean)
dim l as list
    l.Initialize
Dim i As Int = 1

Do While i < 17
    Dim x As Int
    x = Rnd(1,17) 
    If l.IndexOf(x) = -1 Then
        l.Add(x)
        i = i + 1
    Else
        Log("DUPLICATE:" & x)
    End If
Loop
For i = 0 To l.Size -1 
    Log(l.Get(i))
Next

End Sub