Home All Groups Group Topic Archive Search About
Author
18 Oct 2005 12:18 PM
George Bashore
With a form and a commandbutton with index set to 0.
Using this modified code by LFS, how would I get the commandbuttons
to alien themselves on the form in 5 rows instead of running straight down
the form?

Option Explicit

Private Sub Form_Load()
    Dim ID As Long
        For ID = 0 To 29
        If ID Then
        Load Command1(ID)
        Command1(ID).Visible = True
        End If
        Command1(ID).Move 300, ID * 450 + 600, 1000, 350
    Next ID
End Sub

Author
18 Oct 2005 1:16 PM
Norm Cook
Swap the Left & Top arguments
        Command1(ID).Move ID * 450 + 600, 300, 1000, 350
but, of course, you will need to adjust your numbers

Show quoteHide quote
"George Bashore" <gbash***@bcpl.net> wrote in message
news:OZUyE490FHA.700@TK2MSFTNGP10.phx.gbl...
> With a form and a commandbutton with index set to 0.
> Using this modified code by LFS, how would I get the commandbuttons
> to alien themselves on the form in 5 rows instead of running straight down
> the form?
>
> Option Explicit
>
> Private Sub Form_Load()
>     Dim ID As Long
>         For ID = 0 To 29
>         If ID Then
>         Load Command1(ID)
>         Command1(ID).Visible = True
>         End If
>         Command1(ID).Move 300, ID * 450 + 600, 1000, 350
>     Next ID
> End Sub
>
>
Author
18 Oct 2005 2:09 PM
George Bashore
Thanks Norm
That code moves them across the form.

What I am trying to do is make the commandbuttons line up in rows and
columns. like 3 across and 3 down when using 9 commandbuttons.
I can align them with this code but there must be a better way to do it.


Option Explicit

Private Sub Form_Load()
    Dim ID As Long
        For ID = 0 To 8
        If ID Then
        Load Command1(ID)
        Command1(ID).Visible = True
        End If
        Command1(ID).Move 300, ID * 450 + 600, 1000, 350
   Next ID

   For ID = 3 To 5
      Command1(ID).Move 1400, ID * 450 - 750, 1000, 350
  Next ID


For ID = 6 To 8
      Command1(ID).Move 2500, ID * 450 - 2100, 1000, 350
  Next ID

End Sub






Show quoteHide quote
"Norm Cook" <normcookNOSPAM@cableone.net> wrote in message
news:11l9tcih75bu2c6@corp.supernews.com...
> Swap the Left & Top arguments
>        Command1(ID).Move ID * 450 + 600, 300, 1000, 350
> but, of course, you will need to adjust your numbers
>
> "George Bashore" <gbash***@bcpl.net> wrote in message
> news:OZUyE490FHA.700@TK2MSFTNGP10.phx.gbl...
>> With a form and a commandbutton with index set to 0.
>> Using this modified code by LFS, how would I get the commandbuttons
>> to alien themselves on the form in 5 rows instead of running straight
>> down
>> the form?
>>
>> Option Explicit
>>
>> Private Sub Form_Load()
>>     Dim ID As Long
>>         For ID = 0 To 29
>>         If ID Then
>>         Load Command1(ID)
>>         Command1(ID).Visible = True
>>         End If
>>         Command1(ID).Move 300, ID * 450 + 600, 1000, 350
>>     Next ID
>> End Sub
>>
>>
>
>
Author
18 Oct 2005 2:31 PM
Mike Williams
"George Bashore" <gbash***@bcpl.net> wrote in message
news:%23Ugta2%230FHA.3892@TK2MSFTNGP12.phx.gbl...

> I can align them with this code but there must be a better way
> to do it.

Is this the sort of thing you want? (I've put a Sleep and a Show in there so
that you can see what is going on):

Mike

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
Dim ID As Long, row As Long, z As Long
Me.Show
For ID = 0 To 8
  If ID Mod (3) = 0 Then
    row = row + 1
    z = 0
  End If
  If ID Then
    Load Command1(ID)
    Command1(ID).Visible = True
  End If
  z = z + 1
  Command1(ID).Move 300 + 1100 * row, z * 450 + 600, 1000, 350
  DoEvents: Sleep 500
Next ID
End Sub
Author
18 Oct 2005 3:15 PM
George Bashore
Thanks Mike
That's exactly what I was trying to do.
I thought there had to be a better way but couldn't figure it out.
Thanks again,
George

PS I'll have to save this code.


Show quoteHide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:dj310r$rrh$1@news7.svr.pol.co.uk...
> "George Bashore" <gbash***@bcpl.net> wrote in message
> news:%23Ugta2%230FHA.3892@TK2MSFTNGP12.phx.gbl...
>
>> I can align them with this code but there must be a better way
>> to do it.
>
> Is this the sort of thing you want? (I've put a Sleep and a Show in there
> so that you can see what is going on):
>
> Mike
>
> Option Explicit
> Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
>
> Private Sub Form_Load()
> Dim ID As Long, row As Long, z As Long
> Me.Show
> For ID = 0 To 8
>  If ID Mod (3) = 0 Then
>    row = row + 1
>    z = 0
>  End If
>  If ID Then
>    Load Command1(ID)
>    Command1(ID).Visible = True
>  End If
>  z = z + 1
>  Command1(ID).Move 300 + 1100 * row, z * 450 + 600, 1000, 350
>  DoEvents: Sleep 500
> Next ID
> End Sub
>
Author
18 Oct 2005 1:48 PM
Jeff Johnson [MVP: VB]
"George Bashore" <gbash***@bcpl.net> wrote in message
news:OZUyE490FHA.700@TK2MSFTNGP10.phx.gbl...

> With a form and a commandbutton with index set to 0.
> Using this modified code by LFS, how would I get the commandbuttons
> to alien themselves on the form in 5 rows instead of running straight down
> the form?

A) Do the math to figure out how much room you have horizontally and how
many buttons will fit on a row.

B) Either use that number as a Step value in the outer For loop or simply
use a Do While loop and add that step each time.

C) Use the number in the inner For loop to determine which chunk of buttons
you'll be positioning on that row.
Author
18 Oct 2005 4:08 PM
Larry Serflaten
"George Bashore" <gbash***@bcpl.net> wrote
> With a form and a commandbutton with index set to 0.
> Using this modified code by LFS, how would I get the commandbuttons
> to alien themselves on the form in 5 rows instead of running straight down
> the form?

What?!?  You modified MY code???

(Good job!  :-)

What goes around, comes around!  (I'll MODify your code...)

<g>
LFS

Private Sub Form_Load()
    Dim ID As Long
    For ID = 0 To 29
        If ID Then
        Load Command1(ID)
        Command1(ID).Visible = True
        End If
        Command1(ID).Move 300 + (ID Mod 10) * 1200, (ID \ 10) * 400 + 300, 1000, 350
        Command1(ID).Caption = "Button " & CStr(ID)
    Next ID
End Sub
Author
18 Oct 2005 5:39 PM
George Bashore
Thanks Larry
I'm saving this code also.  : )
Works great.
George


Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:%23MIfV1$0FHA.3756@tk2msftngp13.phx.gbl...
>
> "George Bashore" <gbash***@bcpl.net> wrote
>> With a form and a commandbutton with index set to 0.
>> Using this modified code by LFS, how would I get the commandbuttons
>> to alien themselves on the form in 5 rows instead of running straight
>> down
>> the form?
>
> What?!?  You modified MY code???
>
> (Good job!  :-)
>
> What goes around, comes around!  (I'll MODify your code...)
>
> <g>
> LFS
>
> Private Sub Form_Load()
>    Dim ID As Long
>    For ID = 0 To 29
>        If ID Then
>        Load Command1(ID)
>        Command1(ID).Visible = True
>        End If
>        Command1(ID).Move 300 + (ID Mod 10) * 1200, (ID \ 10) * 400 + 300,
> 1000, 350
>        Command1(ID).Caption = "Button " & CStr(ID)
>    Next ID
> End Sub
>
>
Author
18 Oct 2005 5:45 PM
Rick Rothstein [MVP - Visual Basic]
> With a form and a commandbutton with index set to 0.
> Using this modified code by LFS, how would I get the
commandbuttons
> to alien themselves on the form in 5 rows instead of running
straight down
> the form?

Below is a generalized subroutine that will place a control array
of controls into a gridded ordering. Simply pass it the name of
the control array, the left value location for the first control,
the top value location for the first control, the minimum
horizontal separation distance between controls, the minimum
vertical separation distance between controls and how many columns
of controls there should be. Note that the controls do not have to
have their Index values numbered sequentially (gaps between Index
values is fine) and the controls do not all have to be the same
size.

Rick

Sub Arrange(CntrlArray As Object, StartLeft As Long, _
            StartTop As Long, MinHorzSeparation As Long, _
            MinVertSeparation As Long, BreakPointCount As Long)
  Dim X As Long
  Dim Y As Long
  Dim MaxWidth As Long
  Dim MaxHeight As Long
  Dim Index As Long
  Dim HowMany As Long
  Dim NumberOfCols As Long
  Dim NumberOfRows As Long
  Dim XBound As Long
  Dim YBound As Long
  Dim Cntrl As Control
  HowMany = CntrlArray.Count
  For Each Cntrl In CntrlArray
    If Cntrl.Width > MaxWidth Then MaxWidth = Cntrl.Width
    If Cntrl.Height > MaxHeight Then MaxHeight = Cntrl.Height
  Next
  YBound = BreakPointCount - 1
  XBound = HowMany \ BreakPointCount - _
          (HowMany Mod BreakPointCount > 0) - 1
  For X = 0 To XBound
    For Y = 0 To YBound
      If VarType(CntrlArray(Index)) = vbBoolean Then
        With CntrlArray(Index)
          .Move StartLeft + Y * (MaxWidth + MinHorzSeparation), _
                StartTop + X * (MaxHeight + MinVertSeparation)
        End With
      End If
      Do
        Index = Index + 1
        If Index > CntrlArray.UBound Then Exit For
      Loop While VarType(CntrlArray(Index)) = vbObject
    Next
  Next
End Sub