Results 1 to 6 of 6

Thread: CommandButton Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    CommandButton Array

    I create a command button array using the following code, but currently the code is preset to 24 buttons. I'm trying to expand the code so that I can create a grid with x amount of buttons, specified by the user in the format 5x2, 4x6 etc.

    Yet for the life of me I can't figure out how to do it, could someone please have a look at the code and advise - cheers!

    -adehh

    m_CurrScore.lSize = 23
    VB Code:
    1. For l = 0 To m_CurrScore.lSize
    2.     If l > cmdBlock.UBound Then Call Load(cmdBlock(l))
    3.  
    4.     cmdBlock(l).Caption = m_sChrs(l)
    5.     cmdBlock(l).Visible = True
    6.  
    7.     cmdBlock(l).Top = (((cmdBlock(l).Height + 10) * Int(l Mod 4)) + 8)
    8.     cmdBlock(l).Left = (((cmdBlock(l).Width + 10) * Int(l / 4)) + 8)
    9.   Next l

  2. #2
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    This is a function I wrote some time ago.
    You'll have to adjust it a bit, perhaps..

    VB Code:
    1. Public Sub CreateArray(totalcount As Integer, rowmax As Integer)
    2. Dim cmdBtn As Control
    3. Dim ctrRow As Long
    4. Dim ctrCol As Long
    5. Dim InitialLeft As Long
    6. Dim InitialTop As Long
    7. Dim OffsetV As Long
    8. Dim OffsetH As Long
    9. ctrRow = 0
    10. ctrCol = 0
    11. InitialLeft = 1920
    12. InitialTop = 3000
    13. OffsetV = 695
    14. OffsetH = 2475
    15.  
    16.  
    17.  
    18. For i = 1 To totalcount
    19.    Load cmdDesktop(i)
    20.    
    21.     cmdDesktop(i).Height = 450
    22.     cmdDesktop(i).Width = 2175
    23.     cmdDesktop(i).Visible = True
    24.     cmdDesktop(i).Top = InitialTop + (OffsetV * ctrRow)
    25.     cmdDesktop(it).Left = InitialLeft + (OffsetH * ctrCol)
    26.  
    27.     If ctrRow < rowmax Then
    28.         ctrRow = ctrRow + 1
    29.     Else
    30.         ctrRow = 0
    31.        
    32.         ctrCol = ctrCol + 1
    33.     End If
    34.  
    35.  
    36. Next
    37. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Ahh, I grew attached to my mod\divide method, looks like I'm gonna have to drop it.

    Cheers all the same.

    -adehh

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    I'm getting closer and closer to solving this. Modified my code as below and half of the grid is displayed correctly, but it just places the second half of the grid in the same place as the first half. I kind of understand why it does this but can't think of a workaround.

    Anyone?

    VB Code:
    1. cmdBlock(l).Top = (((cmdBlock(l).Height + 10) * Int(l Mod 4)) + 8)
    2.     cmdBlock(l).Left = (((cmdBlock(l).Width + 10) * Int(l Mod 6)) + 8)
    -adehh

  5. #5
    Lively Member
    Join Date
    Oct 2003
    Posts
    127
    Could you please post all of the code, or put it up as a zip file? It's hard to determine what the problem is when you only give that.

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    VB Code:
    1. Dim DefaultTop As Integer
    2. Dim Rows As Integer, Cols As Integer
    3. DefaultTop = cmdBlock(0).Top
    4.  
    5. Rows = 4
    6. Cols = 5
    7.  
    8. For l = 1 To (Rows * Cols) - 1
    9.     If l > cmdBlock.UBound Then Call Load(cmdBlock(l))
    10.  
    11.     cmdBlock(l).Caption = "Some Title " & l
    12.     cmdBlock(l).Visible = True
    13.  
    14.     cmdBlock(l).Top = (cmdBlock(l - 1).Top + cmdBlock(l - 1).Height + 18)
    15.     cmdBlock(l).Left = cmdBlock(l - 1).Left
    16.     If (l Mod Rows) = 0 Then
    17.         cmdBlock(l).Top = DefaultTop
    18.         cmdBlock(l).Left = Int(l / 4) * (cmdBlock(l).Width + 10) + 8
    19.     End If
    20. Next l

    non ?

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