Link to home
Start Free TrialLog in
Avatar of gonzal13
gonzal13Flag for United States of America

asked on

SsVertical Sxroll bar for a form

I would like to minimize the number of forms. Can I put a vertical scroll bar for the whole form. I tried to use the scroll bar, but I think I did not apply it correctly.

Gonzal13(Joe)
Avatar of JR2003
JR2003

Have you tried using a Tab control instead?
These are very useful if you want to fit a lot on one form.
The best one to use is the SSTab control.
Avatar of gonzal13

ASKER

Here are some more Details: I have for example a list of lbl boxes with their associated txt boxs. I then through a msgbox have the commands tosave the data and then read the data. Latar the files will be open for access to calculations. I was hoping for something like MS Windows with its vertical scroll bars. Of the three books that I have none explain how to add data beyond the maximum size of the template. Templates take memory.

gonzal13(joe)
Here's a first cut that works:

You need to place a vertical scrollbar on a form
Place a frame control on the form
Place a textbox INSIDE the frame so the frame contains the textbox
Set the index property of the textbox to 0 (zero)

Paste the following code into your form:

Option Explicit

Private bLoaded As Boolean
Private Sub Form_Load()
   
    With Form1
        .WindowState = vbMaximized
    End With
   
End Sub

Private Sub Form_Resize()

    With VScroll1
        .Max = 100
        .Min = 0
        .Top = 0
        .Left = Me.ScaleWidth - .Width
        .Height = Me.ScaleHeight
    End With
    With Frame1
        .BorderStyle = 0
        .Top = 0
        .Height = Me.ScaleHeight * 2
        .Width = VScroll1.Left
    End With
    If Not bLoaded Then
        Text1(0).Top = 20
        Dim i As Long
        For i = 1 To 100
            Load Text1(i)
            With Text1(i)
                .Visible = True
                .Text = "Text Box " & i
            End With
            With Text1(i - 1)
                Text1(i).Top = .Top + .Height + 50
                If .Top + .Height + 100 > Screen.Height * 2 Then
                    Exit For
                End If
            End With
        Next i
    End If
    bLoaded = True
End Sub

Private Sub VScroll1_Change()

    With Frame1
        .Top = -VScroll1.Value * .Height / (2 * VScroll1.Max)
    End With

End Sub
JR2003

Your reply is more than I expected. I did not realize that there would be any easy way to accomplish my goal.

I increased the points for the work that you did. I will test it out by cutting and pasting to avoid any typos.

Thanks again. Great work.
Jr2003:

I basically did a cut an past action.

I ran it and got an error message 'object required'

Private Sub Form_Load()
   
    With Form1
        .WindowState = vbMaximized  'OBJECT REQUIRED
    End With
   
End Sub


Your form must be called form1.
It's probably called something different so just change this line to:

    Me.WindowState = vbMaximized  'OBJECT REQUIRED
ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jr2003:

Well thank yiou very much. You are very explicit in your programming and do not assume that the questioner actually knows allot about VB6.

gonzal13(joe)