基本上,我需要将此Visual Basic代码转换为Basic4Android代码。我想要做的是随机分配给16个按钮,值从1到15,一个为空。每一次它们都是不同的。我已经用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我只知道将"Integer“改为"Int”并删除所有“Form1”。我不能使用Randomize()、CInt或Int语句,因为它们会给我错误。
发布于 2014-06-24 12:25:46
希望这能有所帮助。它的代码是在不重复的情况下获得随机数。您可以根据您的要求更改i。
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 Subhttps://stackoverflow.com/questions/24340265
复制相似问题