Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Listbox Height Question

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Height Question

The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:

ListBox1.Height = 150

sets the height to 150 points. Same syntax for width.

With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.

"Norm Lundquist" wrote:

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Listbox Height Question

I wish it was doing that! When I step thru the code, it works fine. But
when I run it, the height is set to 49.2 and never changes!! The only times
it works is: 1) when I step thru the code and debug ListBox1.Height; or 2)
when I use the MsgBox statement. Only under those two cases does it work
correctly. All other times the height is set to 49.2.

Norm

"JLGWhiz" wrote:

The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:

ListBox1.Height = 150

sets the height to 150 points. Same syntax for width.

With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.

"Norm Lundquist" wrote:

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Height Question

Can you post the entire initialize code? Maybe the problem lies in another
part that I can't see. For instance, where does Count get its value?
ListIndex?

"Norm Lundquist" wrote:

I wish it was doing that! When I step thru the code, it works fine. But
when I run it, the height is set to 49.2 and never changes!! The only times
it works is: 1) when I step thru the code and debug ListBox1.Height; or 2)
when I use the MsgBox statement. Only under those two cases does it work
correctly. All other times the height is set to 49.2.

Norm

"JLGWhiz" wrote:

The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:

ListBox1.Height = 150

sets the height to 150 points. Same syntax for width.

With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.

"Norm Lundquist" wrote:

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Listbox Height Question

The listbox top is 96, ColumnCount=2, height=50, left=30,
locked=false,MultiSelect=2, width=224.

The two buttons under it are height=24, locked=false, top=162.

Here's the entire code:

Option Explicit


Private Sub UserForm_Initialize()
Dim i As Integer
Dim Count As Integer
Dim t As Double

On Error GoTo 0

' Load the listbox with 6 test values.
ListBox1.Clear
Count = 0
For i = 1 To 6
ListBox1.AddItem
ListBox1.Column(0, Count) = i
ListBox1.Column(1, Count) = "Test case #" & i
Count = Count + 1
Next i

' Following is the line that I can't figure out what's going on!
' In debug mode, the height gets set to 74.
' But when run normally, it remains 49.2.

' By using debug or the MsgBox line that follows, then AND ONLY THEN
does it work!

ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
' MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"

cmdPrint.Top = 96 + ListBox1.Height + 16
cmdClose.Top = 96 + ListBox1.Height + 16
ufJanelPrintRange.Height = 96 + ListBox1.Height + 16 + cmdClose.Height +
16 + 20
ufJanelPrintRange.StartUpPosition = 2

'MsgBox "Form.Height = " & ufJanelPrintRange.Height & vbNewLine & _
' "Listbox.Height = " & ListBox1.Height & vbNewLine & _
' "Button.Top = " & cmdPrint.Top & vbNewLine & _
' "Count = " & Count, vbInformation, "Form Height"
End Sub


Private Sub cmdPrint_Click()
MsgBox "Form.Height = " & ufJanelPrintRange.Height & vbNewLine & _
"Listbox.Height = " & ListBox1.Height & vbNewLine & _
"Button.Top = " & cmdPrint.Top, vbInformation, "Form Height"
End Sub


Private Sub cmdClose_Click()
Unload Me
End Sub




"JLGWhiz" wrote:

Can you post the entire initialize code? Maybe the problem lies in another
part that I can't see. For instance, where does Count get its value?
ListIndex?

"Norm Lundquist" wrote:

I wish it was doing that! When I step thru the code, it works fine. But
when I run it, the height is set to 49.2 and never changes!! The only times
it works is: 1) when I step thru the code and debug ListBox1.Height; or 2)
when I use the MsgBox statement. Only under those two cases does it work
correctly. All other times the height is set to 49.2.

Norm

"JLGWhiz" wrote:

The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:

ListBox1.Height = 150

sets the height to 150 points. Same syntax for width.

With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.

"Norm Lundquist" wrote:

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Height Question

Try modifying the line to this:

ListBox1.Height = (Count * 12) + 2

If that does not work, maybe adding a short delay will. Try this and then
repost if it still won't set to 74. It has to be a timing problem.


"Norm Lundquist" wrote:

The listbox top is 96, ColumnCount=2, height=50, left=30,
locked=false,MultiSelect=2, width=224.

The two buttons under it are height=24, locked=false, top=162.

Here's the entire code:

Option Explicit


Private Sub UserForm_Initialize()
Dim i As Integer
Dim Count As Integer
Dim t As Double

On Error GoTo 0

' Load the listbox with 6 test values.
ListBox1.Clear
Count = 0
For i = 1 To 6
ListBox1.AddItem
ListBox1.Column(0, Count) = i
ListBox1.Column(1, Count) = "Test case #" & i
Count = Count + 1
Next i

' Following is the line that I can't figure out what's going on!
' In debug mode, the height gets set to 74.
' But when run normally, it remains 49.2.

' By using debug or the MsgBox line that follows, then AND ONLY THEN
does it work!

ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
' MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"

cmdPrint.Top = 96 + ListBox1.Height + 16
cmdClose.Top = 96 + ListBox1.Height + 16
ufJanelPrintRange.Height = 96 + ListBox1.Height + 16 + cmdClose.Height +
16 + 20
ufJanelPrintRange.StartUpPosition = 2

'MsgBox "Form.Height = " & ufJanelPrintRange.Height & vbNewLine & _
' "Listbox.Height = " & ListBox1.Height & vbNewLine & _
' "Button.Top = " & cmdPrint.Top & vbNewLine & _
' "Count = " & Count, vbInformation, "Form Height"
End Sub


Private Sub cmdPrint_Click()
MsgBox "Form.Height = " & ufJanelPrintRange.Height & vbNewLine & _
"Listbox.Height = " & ListBox1.Height & vbNewLine & _
"Button.Top = " & cmdPrint.Top, vbInformation, "Form Height"
End Sub


Private Sub cmdClose_Click()
Unload Me
End Sub




"JLGWhiz" wrote:

Can you post the entire initialize code? Maybe the problem lies in another
part that I can't see. For instance, where does Count get its value?
ListIndex?

"Norm Lundquist" wrote:

I wish it was doing that! When I step thru the code, it works fine. But
when I run it, the height is set to 49.2 and never changes!! The only times
it works is: 1) when I step thru the code and debug ListBox1.Height; or 2)
when I use the MsgBox statement. Only under those two cases does it work
correctly. All other times the height is set to 49.2.

Norm

"JLGWhiz" wrote:

The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:

ListBox1.Height = 150

sets the height to 150 points. Same syntax for width.

With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.

"Norm Lundquist" wrote:

This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)

The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height

"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.

The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.

Any ideas on what's happening???

THANK YOU!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Listbox Height Question

I found the problem. The "IntegralHeight" was set to True!! For some
reason, the height cannot be changed "right away". It wants to show full
rows, so that's why it was changing the height from 50 down to 49.2. Then it
would let VBA change it until a MsgBox statement was issued or some other
code! (I still don't know why and under what conditions it would change.)

But after changing the IntegralHeight to False, then I could change it just
fine. I should say that it wasn't being changed!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Row Height question Eagle Excel Discussion (Misc queries) 3 December 2nd 08 08:31 PM
Cell Height question [email protected] Excel Discussion (Misc queries) 3 November 5th 07 05:26 PM
Row Height Question Dave Excel Discussion (Misc queries) 0 February 7th 07 02:06 AM
Row Height Question Dave Excel Discussion (Misc queries) 2 February 6th 07 01:36 AM
Wanted func to determine height of ListBox row count Excel Programming 2 May 24th 04 06:38 PM


All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"