Results 1 to 14 of 14

Thread: [RESOLVED] vb6 - horizontal scrollbar not showing in listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    5

    Resolved [RESOLVED] vb6 - horizontal scrollbar not showing in listbox

    Hi all,

    I had include the API for the horizontal scroll bar but then it still not showing. below is the codes i included for the scrollbar. Can anyone please help me look at it and provide me some guidance?

    Vb Code Code:
    1. Public Sub getlistboxHScrollBar(str As String)
    2.     Dim x As Long
    3.    
    4.     If x < TextWidth(str & "  ") Then
    5.        x = TextWidth(str & "  ")
    6.         If ScaleMode = vbTwips Then
    7.             x = x / Screen.TwipsPerPixelX  ' if twips change to pixels
    8.             SendMessageByNum lstScript.hwnd, LB_SETHORIZONTALEXTENT, x, 0&
    9.         End If
    10.     End If
    11.  
    12. End Sub

    I called this function whenever i add an item into the listbox

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 - horizontal scrollbar not showing in listbox

    Welcome to the forums.

    Is your scalemode twips? If not, the SendMessage call is not even being triggered. Otherwise, what is the value of X, before & after the division, when you believe the scrollbar should have been displayed?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: vb6 - horizontal scrollbar not showing in listbox

    If I remember correctly it has to do with the order in which you add the data and when you add the scrollbar but I don't remember which is correct. In other words it's either...

    1. Add the scrollbar
    2. Populate the listbox

    or

    1. Populate the listbox
    2. Add the scrollbar

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    5

    Re: vb6 - horizontal scrollbar not showing in listbox

    Thanks all. I had remove the scalemode but still it doesn't appear.
    Does it work if my getscrollbar function is in formA, my listbox is in formA too but i call this function from formB?
    I had also try to change the sequence but no luck.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: vb6 - horizontal scrollbar not showing in listbox

    Quote Originally Posted by lynnooi View Post
    Thanks all. I had remove the scalemode but still it doesn't appear.
    Does it work if my getscrollbar function is in formA, my listbox is in formA too but i call this function from formB?
    I had also try to change the sequence but no luck.
    As long as it's a Public function then you do FormA.MyFunction

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    5

    Re: vb6 - horizontal scrollbar not showing in listbox

    Ok. it's already a public function and there is no problem in calling it. no errors occur but the scrollbar did not show. Is there anything else which might cause it not showing?

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: vb6 - horizontal scrollbar not showing in listbox

    This works for me.
    Code:
    Option Explicit
     
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const LB_SETHORIZONTALEXTENT = &H194
    
    
    
    Private Sub Form_Load()
        Dim lLength As Long
        
        List1.AddItem "1234567891011121314151617181920"
        lLength = 2 * (List1.Width / Screen.TwipsPerPixelX)
        Call SendMessage(List1.hWnd, LB_SETHORIZONTALEXTENT, lLength, 0&)
    
    End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    5

    Re: vb6 - horizontal scrollbar not showing in listbox

    Hi all,

    Thanks a lot for the guidance. I got the horizontal scrollbar appeared. However, I not sure what is going on. It just appear after i delete the old list box and replace with a newly created listbox.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] vb6 - horizontal scrollbar not showing in listbox

    If you are calling that routine for each item you add to your listbox, you can inadvertently reset it to where the scrollbar won't show. If the width of the text is less than client width of the listbox, the scrollbar will disappear. I think you'll want to keep track of the widest item and set the horizontal extent when a new widest item is added.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Member
    Join Date
    Mar 2024
    Posts
    46

    Re: vb6 - horizontal scrollbar not showing in listbox

    Quote Originally Posted by lynnooi View Post
    Hi all,

    Thanks a lot for the guidance. I got the horizontal scrollbar appeared. However, I not sure what is going on. It just appear after i delete the old list box and replace with a newly created listbox.
    Realize the issue is marked as "resolved" but I'll give an update.

    Working with VB6 under Windows 10

    The following works perfectly, however, I had to delete and replace the listbox for the scrollbar to appear.

    Declares:
    Code:
    'declare public function to add horizontal scroll bar to list box
        Public Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
                                                 wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Public Const LB_SETHORIZONTALEXTENT = &H194
    The subroutine to set the width:
    Code:
    Public Sub lstAddHScroll(argList As ListBox)
        'the purpose of this subroutine is to add a horizontal scrollbar to a listbox
        'call AFTER populating the listbox!
        
        Dim i&
        Dim lngBigWidth As Long
    
        lngBigWidth = 0
    
        For i& = 0 To argList.ListCount - 1
        'find the longest item
        'use "Me." preceding .TextWidth if working in a class module
            If frmMetadata.TextWidth(argList.List(i&)) > lngBigWidth Then 
                   lngBigWidth = frmMetadata.TextWidth(argList.List(i&))
            End If
        Next
     'call function
    'scale in twips - divide by 14
        i& = SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, lngBigWidth \ 14, 0)
    End Sub

  11. #11
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,022

    Lightbulb Re: vb6 - horizontal scrollbar not showing in listbox

    Quote Originally Posted by SwampeastMike View Post
    Code:
    'scale in twips - divide by 14
        i& = SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, lngBigWidth \ 14, 0)
    End Sub
    You should use the "ScaleX" method, divide by 14 is not a thing.

    Code:
    SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)

  12. #12
    Member
    Join Date
    Mar 2024
    Posts
    46

    Re: vb6 - horizontal scrollbar not showing in listbox

    Quote Originally Posted by VanGoghGaming View Post
    You should use the "ScaleX" method, divide by 14 is not a thing.

    Code:
    SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)
    Thank you! That didn't seem correct yet compared to the example I found (using a different divisor) at least it worked [with listboxes of the same width].

    Really strange the way I had to delete and replace (using exact same name/settings) the listbox before the scroll bar appeared for longer entries.

  13. #13
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    539

    Re: vb6 - horizontal scrollbar not showing in listbox

    Quote Originally Posted by VanGoghGaming View Post
    You should use the "ScaleX" method, divide by 14 is not a thing.

    Code:
    SendMessageByNum(argList.hwnd, LB_SETHORIZONTALEXTENT, frmMetadata.ScaleX(lngBigWidth, frmMetadata.ScaleMode, vbPixels), 0)
    I formatted the PC and installed Windows 11.
    Many times in projects that previously worked well, the error

    error 16 expression too complex
    Code:
    If Form1.TextWidth(argList.List(i&)) > lngBigWidth Then

  14. #14
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,022

    Re: [RESOLVED] vb6 - horizontal scrollbar not showing in listbox

    As far as I know, the expression too complex error comes after using the "Not Not Array" syntax to check whether an array is initialized or not.
    This syntax will destabilize the IDE and make it spit out the expression too complex nonsense.

    If you need to check for an initialized array then it's recommended to dereference the array pointer:

    Code:
    GetMem4 ByVal ArrPtr(Array), pSA
    If pSA = 0 Then ' Array is not yet initialized

Posting Permissions

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



Click Here to Expand Forum to Full Width