PDA

Click to See Complete Forum and Search --> : Control Arrays


steve fordon
Aug 6th, 2001, 11:20 AM
I have to design a game of battleships using control arrays. The main grid is a panel of command buttons 15 x 15= 225.
I have used the tag feature to attach a "grid reference" to each button within the array.
I need to be able to identify which button within the array was clicked, record the reference within an array of textboxes and limit the user to 5 different buttons at any time. For eg
if user presses cmd(34) then text(0)="34"
if user presses cmd(65)then text(1)="65" etc etc
When 5 buttons have been selected I can then send this info to a scoring procedure, wipe the counter and start counting with the next 5 clicks.

Arcom
Aug 6th, 2001, 01:02 PM
You can have a public variable that will count the number of pressed buttons, and the Index value in the Click event is the button's index.

e.g.:

Dim lCnt As Long
Dim bOK As Boolean

Private Sub Command1_Click(Index As Integer)
' If the user clicked more than 5 buttons, exit the sub
If Not bOK Then Exit Sub

' Record the reference
Text1(lCnt).Text = Index
' Increase the counter
lCnt = lCnt + 1
' Make sure the user can't click more than 5 buttons
If lCnt = 5 Then bOK = False
End Sub