Results 1 to 19 of 19

Thread: VB6 Scrollbar for multiple textboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    VB6 Scrollbar for multiple textboxes

    Hy,

    i can't find it anywhere on the internet, so i hope some of you guys have a solution for me.

    I have like 5 textboxes on my form, and i want to put 1 scollbar (Vscroll) on my form. When i scroll down on my vscroll, i want al the textboxes to scroll down with the same interval. Anyone has an idea how to do this. What code do i have to put behind my vscroll_change??

    thx a lot for the one who helps me!

    greetzz
    hephie

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 Scrollbar for multiple textboxes

    Moved from the CodeBank

  3. #3
    Member
    Join Date
    Mar 2006
    Posts
    45

    Re: VB6 Scrollbar for multiple textboxes

    The attachment has the vscroll bar you are after

    cheers
    Paul V
    Attached Files Attached Files

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB6 Scrollbar for multiple textboxes

    in your scroll_change, write code to increase/decrease the top of the textboxes...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5
    Member
    Join Date
    Mar 2006
    Posts
    45

    Re: VB6 Scrollbar for multiple textboxes

    how do you mean?

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB6 Scrollbar for multiple textboxes

    say for example
    VB Code:
    1. Text1.Top = Text1.Top + 50
    2. Or
    3. Text1.Top = Text1.Top - 50
    in your vscroll_change event
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7
    Member
    Join Date
    Mar 2006
    Posts
    45

    Re: VB6 Scrollbar for multiple textboxes

    ahh I C thanks for that

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    Re: VB6 Scrollbar for multiple textboxes

    if i do that, my textbox just moves down on the screen... this is not what i want...
    i have like 5 textboxes on my form. Every textbox receives the values of a column in my sql database.

    for examle
    NR NAme .........
    1 thomas
    2 jef
    3 maarten
    4 romina
    5 biatch
    ... ...

    so suppose you only see the first 3 lines, then i want 1 scrollbar (vscroll), and that when i use that scrollbar, my 2 textboxes scrolls down. so you can see the numbers and names (4, romina and 5,biatch).

  9. #9
    Member
    Join Date
    Mar 2006
    Posts
    45

    Re: VB6 Scrollbar for multiple textboxes

    um Hephie did you download the above file? that does what you need

    the one I use has 38 textboxes and 2 comboboxes

    I use the scrollbar and it move every textbox to the next item in the database...

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB6 Scrollbar for multiple textboxes

    so suppose you only see the first 3 lines, then i want 1 scrollbar (vscroll), and that when i use that scrollbar, my 2 textboxes scrolls down. so you can see the numbers and names (4, romina and 5,biatch).
    i dont understand, have you placed 5 text boxed one by one...is that not fitting into your screen...or are you using same text box to display all five lines....please clarify
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


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

    Re: VB6 Scrollbar for multiple textboxes

    While coordinating the scrolling of several textboxes can be done, are you sure you want to use textboxes? Unless the user is expected to write in those textboxes then you probably should use another control like a single listview or grid, or even several listboxes.

  12. #12
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: VB6 Scrollbar for multiple textboxes

    I have sample code on my website that does something along the lines of what you are looking for. On this page:
    http://www.thevbprogrammer.com/tutorials.html
    See the "Scroll Bars" link under "9. Forms and More Controls"
    "It's cold gin time again ..."

    Check out my website here.

  13. #13

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    Re: VB6 Scrollbar for multiple textboxes

    yes i downloaded the file frametech, but it was not wat i was looking for. I'll try to explain again what i'm looking for.
    I have several textboxes on my form. (they all fit in my form, i'll post a screenshot later in this post, so you can see something more).

    When i press a button on the right (for example "objecteigenschappen"), all the data from that table ("objecteigeschappen is a table in my sql server database). in the database is filled into my textboxes. if the table has 3 columns, the first 3 textboxes are filled with all data in those columns.

    Now when the table has many data in it, you only see the first 10 lines i shall say. Now i don't want 3 seperated scrollbars (one for every textbox), i want JUST ONE scrollbar (vsroll, somewhere on the screen) en that when i press that one, we move down in all the 3 textboxes to the next data.

    I hope now you all know what i'm trying to do. Here's the screenie:

    SCREEN1:

    SCREEN2:

  14. #14
    Junior Member
    Join Date
    Apr 2006
    Location
    Vancouver, WA
    Posts
    31

    Re: VB6 Scrollbar for multiple textboxes

    Use a list view. You can dynamically change the column headers and the data that is viewed in it. It would probably be alot easier to figure out than vscroll... Heres a code snippet

    Dim adoSearchResults As New ADODB.Recordset
    Dim itmListView As ListItem
    Dim strSearchResultsQuery As String

    lstSearchResults.ListItems.Clear
    '|----------------------------------------------------------------------------------
    '| Set Up SQL Query Based On User Input.
    '|----------------------------------------------------------------------------------
    strSearchResultsQuery = "Select [Panel Tag],[IO Type],[Drop],[Rack],[Slot],[Channel],[PLC Register],[Terminal Number],[PLC Tag],[PLC Description],[Comments],[Status],[RowID] From v_PLC_DATA Where " & strNewSearchCriteria & strTextBoxCriteria & " Order By [Drop],[Rack],[Slot],[Channel]"
    '|----------------------------------------------------------------------------------
    '| Open Recordset and Populate ListView with Results.
    '|----------------------------------------------------------------------------------
    With adoSearchResults
    If .State = adStateOpen Then .Close
    .ActiveConnection = strConnectionString
    .CursorLocation = adUseClient
    .Open (strSearchResultsQuery)
    If Not .EOF Then
    lblRecordCount.Caption = .RecordCount & " Records Retrieved."
    Else
    lblRecordCount.Caption = "No Records Retrieved."
    End If
    While Not .EOF
    Set itmListView = lstSearchResults.ListItems.Add()
    itmListView.Text = ![Object Name]
    itmListView.Tag = ![RowID]
    For i = 1 To .Fields.Count
    If IsNull(.Fields(i).Value) Then
    itmListView.SubItems(i) = ""
    Else
    itmListView.SubItems(i) = .Fields(i).Value
    End If
    Next i
    .MoveNext
    Wend
    .Close
    End With

  15. #15

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    Re: VB6 Scrollbar for multiple textboxes

    After changing some of your code and debugging, it still gives an error on this:

    itmListView.SubItems(i) = .Fields(i).Value

    error: invalid property value...

    don't know what to do, please help
    Last edited by Hephie; Apr 10th, 2006 at 07:38 AM.

  16. #16
    Junior Member
    Join Date
    Apr 2006
    Location
    Vancouver, WA
    Posts
    31

    Re: VB6 Scrollbar for multiple textboxes

    Do a watch window on the recordset and loop through the fields.count loop. I think you might have to do For i = 1 to Fields.count -1 since ado starts at 0, while the listview starts at 1. Let me know...

  17. #17
    New Member
    Join Date
    Apr 2006
    Location
    Oregon
    Posts
    2

    Re: VB6 Scrollbar for multiple textboxes

    This code is ugly, and quirky, and slow, but I think it does basically what you are wanting to do. The quirkiness comes from the fact that I don't know of a way to set the top line displayed in a text box -- so I used the "SelStart" to set the Selection bar location. Since SelStart defines a character position instead of a line position, I had to process through the text to translate that into lines, which makes the function slow.

    Also, if you change the scroll bar, and calculate a new character position that is already displayed within the text box, the text box doesn't scroll at all. This makes it look like the scroll bars aren't working, when in fact, the SelStart value has changed. There may be ways to code around this, but I didn't take the time to figure it out. Does anybody know an easy way to tell if the scroll bar has been moved up or down? The only thing I could think of was to keep current value versus last value and compare them. Yuck.

    Vscroll1 is the scroll bar object. The Max property is set to the number of lines in the text boxes. This, combined with a SmallChange property of 1, means that clicking on the scroll bar arrows will scroll the text by one line up or down. The LargeChange property is set to the number of lines displayed in the text boxes, so that clicking on the scroll bar itself results in "page up" and "page down" functionality.

    The two text boxes are named txtSource and txtResults. They show 13 lines of text each.

    I used the "Vscroll1.Value + 13" in the loop so that when the user first tries to scroll down using the arrows, the text starts moving right away -- they don't have to click on the arrows 13 times first. I tried setting the initial value of Vscroll1.Value to 13, which has the same sort of effect, but that led to a whole different set of quirks.

    Needless to say, this looks like it is possible, but not pretty or easy.

    Good luck!


    VB Code:
    1. Private Sub VScroll1_Change()
    2.  
    3.   CharIndx = 1
    4.   CurLine = 1
    5.  
    6.   If VScroll1.Value <> 1 Then
    7.     Do
    8.       NextChar = Mid(txtSource.Text, CharIndx, 1)
    9.       If NextChar = Chr(13) Then
    10.         CurLine = CurLine + 1
    11.       End If
    12.       CharIndx = CharIndx + 1
    13.     Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
    14.   End If
    15.   txtSource.SelStart = CharIndx
    16.  
    17.   If txtResults.Enabled = True Then
    18.     CharIndx = 1
    19.     CurLine = 1
    20.  
    21.     If VScroll1.Value <> 1 Then
    22.       Do
    23.         NextChar = Mid(txtResults.Text, CharIndx, 1)
    24.         If NextChar = Chr(13) Then
    25.           CurLine = CurLine + 1
    26.         End If
    27.         CharIndx = CharIndx + 1
    28.       Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
    29.     End If
    30.     txtResults.SelStart = CharIndx
    31.   End If
    32.  
    33. End Sub

  18. #18

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    Re: VB6 Scrollbar for multiple textboxes

    that's exactly what i was looking for!
    GREAT man!!

    thx a LOT!

    sorry i respond so late, but i was "taking a break", went outta the country for a few days.

    thanks!

    it's kinda slow indeed... but it works

  19. #19
    New Member
    Join Date
    Apr 2006
    Location
    Oregon
    Posts
    2

    Re: VB6 Scrollbar for multiple textboxes

    I've attached a sample app that shows how this works. This code works better than the code in my previous post -- I've handled all of quirkiness (I think). In particular, the problem of the current Value changing without changing the display is fixed. Now you always get an appropriate action when the scroll bar control changes.

    Note that this is just a sample app with fixed line contents. It doesnt' take into account lines in the text with different lengths. My previous code snippet handled that, and I didn't want to reproduce that here, so that I could focus on the problems related to the actual scrolling.


    VB Code:
    1. Dim Value As Integer
    2. Dim OldValue As Integer
    3.  
    4. Dim TopLine As Integer
    5. Dim BottomLine As Integer
    6.  
    7. Dim TotalLines As Integer
    8. Public Sub ProcessNewValue()
    9.  
    10.   Value = VScroll1.Value
    11.   If (Value > OldValue) Then
    12.  
    13.     ' User is going DOWN
    14.  
    15.     If (Value = OldValue + 1) Then
    16.    
    17.       ' Line down; jump to the bottom first, then process the change.
    18.      
    19.       If BottomLine < TotalLines Then
    20.         Value = BottomLine + 1
    21.         BottomLine = BottomLine + 1
    22.         TopLine = TopLine + 1
    23.       End If
    24.     Else
    25.      
    26.       ' Page down; jump to the bottom first, then process the change.
    27.      
    28.       If (Value = OldValue + 13) Then
    29.         Value = BottomLine + 13
    30.         TopLine = TopLine + 13
    31.         BottomLine = TopLine + 12
    32.       Else
    33.         TopLine = Value - 12
    34.         BottomLine = Value
    35.       End If
    36.     End If
    37.   Else
    38.     If (Value < OldValue) Then
    39.    
    40.       ' User is going UP
    41.      
    42.       If (Value = OldValue - 1) Then
    43.      
    44.         ' Line Up; jump to the top first, then process the change.
    45.        
    46.         Value = TopLine - 1
    47.         TopLine = TopLine - 1
    48.         BottomLine = TopLine + 12
    49.       Else
    50.         If (Value = OldValue - 13) Then
    51.          
    52.           ' Page Up; jump to the bottom first, then process the change.
    53.          
    54.           If (TopLine - 13) >= 1 Then
    55.             Value = TopLine - 13
    56.             BottomLine = BottomLine - 13
    57.             TopLine = BottomLine - 12
    58.           Else
    59.             Value = 1
    60.             TopLine = 1
    61.             BottomLine = TopLine + 12
    62.           End If
    63.         Else
    64.           TopLine = Value
    65.           BottomLine = TopLine + 12
    66.         End If
    67.       End If
    68.     End If
    69.   End If
    70.  
    71.   Text1.SelStart = (Value - 1) * 9
    72.   Text5.SelStart = (Value - 1) * 9
    73.  
    74.   Text2.Text = Value
    75.   Text3.Text = TopLine
    76.   Text4.Text = BottomLine
    77.   OldValue = Value
    78.   VScroll1.Value = Value
    79.  
    80. End Sub
    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
  •  



Click Here to Expand Forum to Full Width