PDA

View Full Version : Scrollbar for list of Labels



Emoncada
09-01-2011, 11:16 AM
I am trying to create a List of Labels in a box.
I created one using a framebox with Labels inside.

My issue is I want to have about 25 Labels within this framebox.
So since it's many Labels I would like to have a scrollbar on the side.

Now the purpose for this is it's going to be a receipt of items/Prices.

What would be the best way to accomplish this?

mikerickson
09-01-2011, 11:59 AM
UserForm1.Frame1.ScrollBars = fmScrollBarsVertical

Emoncada
09-01-2011, 12:10 PM
That does add the scrollbar, but let me try to explain what my goal is.

I want to have a frame with labels going down.
I have the following code.


Private Sub BtnAdd_Click()

If TxtDisplay.Value = "" Then
Exit Sub

ElseIf LblWeight1.Caption = "" Then
LblWeight1.Caption = " " & TxtDisplay.Value & " oz" & " X " & TxtCupPrice.Value & "¢"
LblPrice1.Caption = Format((TxtDisplay.Value * TxtCupPrice.Value), "$#,##0.00")
LblWeight1.BackColor = RGB(188, 188, 188)
LblPrice1.BackColor = RGB(188, 188, 188)
ImgWeight1.Visible = True
TxtDisplay.Value = ""

ElseIf LblWeight2.Caption = "" Then
LblWeight2.Caption = " " & TxtDisplay.Value & " oz" & " X " & TxtCupPrice.Value & "¢"
LblPrice2.Caption = Format((TxtDisplay.Value * TxtCupPrice.Value), "$#,##0.00")
ImgWeight2.Visible = True
TxtDisplay.Value = ""

ElseIf LblWeight3.Caption = "" Then
LblWeight3.Caption = " " & TxtDisplay.Value & " oz" & " X " & TxtCupPrice.Value & "¢"
LblPrice3.Caption = Format((TxtDisplay.Value * TxtCupPrice.Value), "$#,##0.00")
LblWeight3.BackColor = RGB(188, 188, 188)
LblPrice3.BackColor = RGB(188, 188, 188)
ImgWeight3.Visible = True
TxtDisplay.Value = ""

ElseIf LblWeight4.Caption = "" Then
LblWeight4.Caption = " " & TxtDisplay.Value & " oz" & " X " & TxtCupPrice.Value & "¢"
LblPrice4.Caption = Format((TxtDisplay.Value * TxtCupPrice.Value), "$#,##0.00")
ImgWeight4.Visible = True
TxtDisplay.Value = ""

End If
LblPrice.Caption = Format(CDbl(IIf(Len(LblPrice1.Caption) = 0, 0, LblPrice1.Caption)) + CDbl(IIf(Len(LblPrice2.Caption) = 0, 0, LblPrice2.Caption)) + CDbl(IIf(Len(LblPrice3.Caption) = 0, 0, LblPrice3.Caption)) + CDbl(IIf(Len(LblPrice4.Caption) = 0, 0, LblPrice4.Caption)) + CDbl(IIf(Len(LblPrice5.Caption) = 0, 0, LblPrice5.Caption)), "$#,##0.00")
LblTax.Caption = Format(CDbl(LblPrice.Caption) * 0.07, "$#,##0.00")
LblTotalPrice.Caption = Format(CDbl(LblPrice.Caption) + CDbl(LblTax.Caption), "$#,##0.00")

End Sub

Now that is just for 4 rows of Labels within the Frame.
But I want to have about 25 rows.

How can I set this up so when BtnAdd is clicked to add row 5, it will make the Frame scoll down so now you can only see row2 - row5.
Then if BtnAdd is clicked again you will see row3 - row6.

How that helps explain what i need.

Thanks

mikerickson
09-01-2011, 12:51 PM
Rather than using Lables, why not use a ListBox. It looks like a 3 column list box will do what you want.

But if you go with the Frame/Label option, you should look at the ScrollHeight, ScrollTop, ScrollLeft and ScrollWidth properties.

Emoncada
09-01-2011, 01:20 PM
can you give me an example of how I can add text to the Listbox and make it work similiar to my code?

Emoncada
09-01-2011, 02:39 PM
Ok i added it and works good, but limit's me to what I can do with it.
For Example with the Labels I created an X button next to each label row and if clicked it would remove item from the label and any labels with data following the label removed label would move up.

Example.
Line 1 X................3.75 oz................35cents...........$1.31
Line 2 X................7.50 oz................35cents...........$2.63
Line 3 X................5.75 oz................35cents...........$2.01

If X in Line 2 is clicked you would get
Line 1 X................3.75 oz................35cents...........$1.31
Line 2 X................5.75 oz................35cents...........$2.01

can anything like that be done using ListBox?

mikerickson
09-01-2011, 03:15 PM
You could put code like this in the ListBox1_Click event

With ListBox1
If .ListIndex <> -1 Then
.RemoveItem .ListIndex
End If
End With

It seems that a lot of these questions could be answered by browsing in the ObjectBrowser which give all the properties and methods that one has available to control userform Controls.

mikerickson
09-01-2011, 06:41 PM
I was playing around with the Lable/Frame/ScrollBar idea and came up with this.
The ScrollBar control works smother on my Mac than the Frame's scroll bar.

I hope it helps.