Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21863

Creating Multiple Rows of Command Buttons at runtime

$
0
0
Okay, now I need some help.....I have been working on this for a full day...tried dozens of loops and ifs. Just CAN'T get the logic down.

What I want is rows of command buttons on a form....maybe 25 or so (for a game similar to Jeopardy).

I determine how many buttons go in a row by using form and button widths
I decide in advance how many buttons I want so determining number of rows is easy.

Now, what I can't seem to do is move down each set of buttons into rows.
Should look similar to this:

CMD1 CMD2 CMD3 CMD4 CMD5
CMD6 CMD7 CMD8 CMD9 CMD10
CMD11 CMD12 CMD13 CMD14 CMD15...well, you get the idea.

Here is my last/final failure----and I tried many...can anyone assist here?

Code:

Option Explicit

Private Sub Command2_Click()
Dim numCmdBtnsWanted As Integer
Dim numCmdBtnsAllowedInRow As Integer
Dim numRows As Integer
Dim z As Integer
numCmdBtnsAllowedInRow = Form1.Width / Command1(0).Width
numCmdBtnsWanted = 25
numRows = numCmdBtnsWanted / numCmdBtnsAllowedInRow
Dim x As Integer
Dim y As Integer
Dim wd As Integer
wd = Command1(0).Width
Dim ht As Integer
ht = Command1(0).Height
For x = 1 To numCmdBtnsWanted
  Load Command1(x)
  Command1(x).Caption = "CMD" & Str(x)
  Command1(x).Visible = True
Next x
For x = 1 To numCmdBtnsAllowedInRow
    Command1(x).Top = Command1(0).Top
    Command1(x).Left = Command1(x - 1).Left + wd
Next x

End Sub


Viewing all articles
Browse latest Browse all 21863

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>