Consulting

Results 1 to 8 of 8

Thread: Scrollbar for list of Labels

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Scrollbar for list of Labels

    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?

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    [VBA]UserForm1.Frame1.ScrollBars = fmScrollBarsVertical[/VBA]

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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.

    [vba]
    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
    [/vba]
    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

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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.

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    can you give me an example of how I can add text to the Listbox and make it work similiar to my code?

  6. #6
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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?

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You could put code like this in the ListBox1_Click event

    [VBA]With ListBox1
    If .ListIndex <> -1 Then
    .RemoveItem .ListIndex
    End If
    End With[/VBA]

    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.

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •