1

Basically I need this Visual Basic code translated to Basic4Android code. What I want to do is to randomly assign to 16 buttons values from 1-15 and one empty. Each time they will be different. I've done it in VB and it works but know I want to make this on 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

I know only to change "Integer" to "Int" and delete all "Form1's". I can't use Randomize() nor CInt nor Int statements because they give me errors.

user3478487
  • 1,165
  • 2
  • 8
  • 10

1 Answers1

0

Hope this helps. its code for getting random number without repeating. you can change i as per your requirement.

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