Results 1 to 2 of 2

Thread: Control Arrays

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Somerset,England
    Posts
    1

    Exclamation Control Arrays

    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.

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    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.:
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width