Sub drawBtnDice
Dim i, j, x, y, rndDice(9) As Int
Dim bufferIcon() As Byte
Dim bmpIcon As Bitmap
For i = 0 To 8
rndDice(i) = i
Next
storyClass.ShuffleArray(rndDice)
Dim dv(9) As DraggableView
For y = 0 To 2
For x = 0 To 2
Dim b As Button
b.Initialize("") 'No event name added because draggable views event will not be raised
Activity.AddView(b,offsetX + x * (btnWidth + 15dip), offsetY + y * (btnWidth + 1dip), btnWidth, btnWidth)
btnDice(x, y) = b 'store a reference to this view
'We have 9 dices and each dice can have one of the six possible icons
rndNumber2 = Rnd(0, 6)
cursorStory = sqlStory.ExecQuery("SELECT * FROM story WHERE rowid=" & iconID(rndDice(j), rndNumber2))
cursorStory.Position = 0
bufferIcon = cursorStory.GetBlob("icon")
cursorStory.Close
Dim iconIS As InputStream
iconIS.InitializeFromBytesArray(bufferIcon, 0, bufferIcon.Length)
bmpIcon.Initialize2(iconIS)
iconIS.Close
'Initialize draggable view
dv(j).Initialize(Activity, b, j, bmpIcon)
'Initialize animation scale center
diceAnim(x, y).InitializeScaleCenter("", 0, 0, 1, 1, b)
'Set animation length
diceAnim(x, y).Duration = 500
diceAnim(x, y).start(btnDice(x, y))
'btnDice(x, y).Visible = True
btnDice(x, y).SetBackgroundImage(bmpIcon)
'Play sound
sndPPop(j) = SP.Play(sndLPop(j), 1, 1, 1, 0, 1)
storyClass.Wait(j)
j = j + 1
Next
Next
End Sub