Solved

vb6 scrollbar overflow error

Posted on 2010-08-25
8
922 Views
Last Modified: 2012-06-27
I am making modifications to another developer's project that has a form with a scrollbar.  I don't really get the jist of the cde, but on the form resize event, I am getting an overflow error on this line:
                 .Max = iFullFormHeigth - Me.Height

The value of (iFullFormHeigth - Me.Height) is 63435 at this point.

        With VScroll1
            .Height = Me.ScaleHeight - HScroll1.Height
            .Min = 0
            'MsgBox iFullFormHeigth - Me.Height
            .Max = iFullFormHeigth - Me.Height
            .SmallChange = Screen.TwipsPerPixelY * 10
            .LargeChange = Me.ScaleHeight - HScroll1.Height
        End With

Dim iFullFormHeigth As Long 'integer
Dim iFullFormWidth As Long 'integer

Private Sub Form_Resize()

VScroll1.Left = Me.Width - (1.45 * VScroll1.Width)
HScroll1.Top = Me.Height - (2.45 * HScroll1.Height)

Picture1.Left = VScroll1.Left
Picture1.Top = HScroll1.Top

'If the full screen is already showing,
'then disable the scrollbar
VScroll1.Enabled = (iFullFormHeigth - Me.Height) >= 0

'First, make sure we aren't minimized
If Me.ScaleHeight > HScroll1.Height And Me.Width > VScroll1.Width Then
    
    'If there is any more screen to see,
    'modify the scrollbar
    If VScroll1.Enabled Then
        With VScroll1
            .Height = Me.ScaleHeight - HScroll1.Height
            .Min = 0
            .Max = iFullFormHeigth - Me.Height
            .SmallChange = Screen.TwipsPerPixelY * 10
            .LargeChange = Me.ScaleHeight - HScroll1.Height
        End With

    'Otherwise, just resize the scrollbar for neatness
    Else: VScroll1.Height = Me.ScaleHeight - HScroll1.Height
    End If

    HScroll1.Enabled = (iFullFormWidth - Me.Width) >= 0
    If HScroll1.Enabled Then
        With HScroll1
            .Width = Me.ScaleWidth - VScroll1.Width
            .Min = 0
            .Max = iFullFormWidth - Me.Width
            .SmallChange = Screen.TwipsPerPixelX * 10
            .LargeChange = Me.ScaleWidth - VScroll1.Width
        End With

    Else: HScroll1.Width = Me.ScaleWidth - VScroll1.Width
    End If
End If
End Sub

Open in new window

0
Comment
Question by:Delta7428
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33521030
i don't see where you initialize the iFullFormHeigth variable.is ti possible you forgot?
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 100 total points
ID: 33521035
where do u initially set iFullFormHeigth?it doesn;t appear in the Form_Resize() function...
0
 
LVL 13

Expert Comment

by:Surone1
ID: 33521055
it's probably trying to set a negative value..
if you uncomment the
MsgBox iFullFormHeigth - Me.Height
it will tell you the value before trying to set it..
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:Delta7428
ID: 33521098
Surone1, See original post.  I did ucomment the line and check it.  Actually, I added the line to check it.  The value is 63435.

Here is the rest of the code.  iFullFormHeigth is set in the form load event in GetFullSize proc.
Private Sub Form_Load()
    GetFullSize
End Sub

Private Sub GetFullSize()
Dim ctl As Control
Dim fullhtemp As Long
Dim fullvtemp As Long

fullhtemp = 0
fullvtemp = 0
If Me.WindowState = vbMinimized Then Exit Sub
For Each ctl In Me.Controls
        'If ctl.Name <> "timer1" Then
            If ctl.Top + ctl.Height > fullvtemp Then fullvtemp = ctl.Top + ctl.Height
            If ctl.Left + ctl.Width > fullhtemp Then fullhtemp = ctl.Left + ctl.Width
        'End If
Next
iFullFormHeigth = fullvtemp + HScroll1.Height
iFullFormWidth = fullhtemp + VScroll1.Width
End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:Surone1
ID: 33521105
sorry, not paying attention..
i believe the width property is an integer. the value is too high
0
 
LVL 13

Expert Comment

by:Surone1
ID: 33521142
should not be higher than 32767
0
 
LVL 13

Expert Comment

by:Surone1
ID: 33521170
the following sub proves the theory

Sub showverflow()
Dim i As Integer
Do While True
i = i + 1
Loop
End Sub
0
 
LVL 13

Accepted Solution

by:
Surone1 earned 400 total points
ID: 33521263
dim myvar as integer

if  iFullFormHeigth - Me.Height > 32767 then
myvar = 32767
else
myvar =  iFullFormHeigth - Me.Heigh
end if

'MsgBox iFullFormHeigth - Me.Height
 .Max = myvar
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 11 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question