Help with control array positioning

I want these labels to be laid out 'as close together' as would appear pleasing to the eye.
I also don't want them to extend off the side of the form.

Having a bit of trouble with the logic on the second line of labels...
Here's the relevant code

Load lblData(x)
With lblData(x)
 If x = 7 Then 'This is the 'first' of these labels (there are obviously 7 others, but they're static)
  intTop = 2665  'The first label's top
  intLeft = 280  'The first label's left
Else
  intLeft = lblData(x - 1).Left + lblData(x - 1).Width + 100  'Otherwise - add the left & width to 100 to get the 'new' left (this could use some tweaking, I'd wager)
  If intLeft > 6500 Then  'If left is 'dangerously' close to the form's edge, then change the 'top' and reset the 'left'  (obviously the left would be okay, but though it's 'unlikely' to have more than 2 rows, I want to give the option for at least 3...
  intTop = 3065
  intLeft = 280
 Else
  intTop = 2665
  intLeft = lblData(x - 1).Left + lblData(x - 1).Width + 100
 End If
End If
 .Caption = txtData(1).Text
 .Width = 1000
 .Height = 255
 .Top = intTop
 .Left = intLeft
 .Visible = True
End With
LVL 67
sirbountyAsked:
Who is Participating?
 
Leo EikelmanConnect With a Mentor Director, IT and Business DevelopmentCommented:
I think the problem you are having is this line

 If intLeft > 6500 Then  
  intTop = 3065
  intLeft = 280
 Else
  intTop = 2665
  intLeft = lblData(x - 1).Left + lblData(x - 1).Width + 100

You first item on the second row will get printed correctly but then every other control will be printer up on the first line again because you have intTop being set to 2665 again.  Get rid of the intTop = 2665 line here and set intTop = 2665 outside of your loop.  So the default value for intTop is 2665.  

You should only have to change the intTop value when you move onto a new line.  You don't have to change or specify the value every time you display a control on the same line.


Leo
0
 
Leo EikelmanDirector, IT and Business DevelopmentCommented:
Also,

At this line

 If intLeft > 6500 Then  
  intTop = 3065
  intLeft = 280
 Else
 

change intTop to something like

intTop = intTop + 400


Leo
0
 
sirbountyAuthor Commented:
Works up until item 2 on line 2...
0
 
sirbountyAuthor Commented:
Ok - made intTop a form variable and it's working.
Thanx.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.