I'm getting Overflow and Subscript out of range errors
I have scrollable picture boxes within a single picture box in which I'm getting two types of errors depending on the number of picture boxes I'm trying to scroll. I've been working on solutions to prevent these overflows, but one solution seems to lead to another occurring somewhere else. I could really use some help nailing this down. I have attached the VB6 files and included the line of code where the errors are occurring.
Errors that I'm getting:
Dim l%
Dim ClientArrayTop() As Integer
Dim CurrentListCount%
Private Sub cmdOK_Click()
'Get the current highest array number of picClient Picture Boxes
CurrentListCount = picClient.Count - 1
'Number in txtNumber must be > than 0
If txtNumber.Text < 1 Then
MsgBox ("You must enter in a number greater than 0!")
End If
'create new picture boxes according to txtNumber.Text
Dim i%
For i = 0 To txtNumber.Text - 1
If i > CurrentListCount Then
Load picClient(picClient.UBound + 1)
Set picClient(picClient.UBound).Container = _
picMain
With picClient(picClient.UBound)
.Left = picClient(0).Left
.Top = picClient(picClient.UBound - 1).Top + _
picClient(picClient.UBound - 1).Height + 120
.Visible = True
End With
'create new text boxes according to txtNumber.Text
Load txtClient(txtClient.UBound + 1)
Set txtClient(txtClient.UBound).Container = _
picClient(picClient.UBound)
With txtClient(txtClient.UBound)
.Left = txtClient(0).Left
.Top = txtClient(0).Top
.Text = "Text" & picClient.UBound + 1
.Visible = True
End With
End If
Next
ChangeClientSize
End Sub
Private Sub Form_Load()
ChangeClientSize
End Sub
Private Sub txtNumber_KeyPress(KeyAscii As Integer)
'character in txtNumber must be a number
If InStr("0123456789", Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub VScroll1_Change()
VertScroll
End Sub
Private Sub VScroll1_Scroll()
VertScroll
End Sub
Sub VertScroll()
l = VScroll1.Value
Dim i As Integer
For i = 0 To picClient.UBound
If ClientArrayTop(i) - l < -853 Then
picClient(i).Top = -853
ElseIf ClientArrayTop(i) - l > 1692 Then
picClient(i).Top = 1692
Else
picClient(i).Top = ClientArrayTop(i) - l
End If
Next
End Sub
Sub ChangeClientSize()
VScroll1.Max = -1524 + picClient(picClient.UBound).Top + picClient(picClient.UBound).Height
ReDim ClientArrayTop(0 To picClient.UBound) As Integer
Dim i As Integer
For i = 0 To picClient.UBound
ClientArrayTop(i) = picClient(i).Top
Next
End Sub
Re: I'm getting Overflow and Subscript out of range errors
The overflow problem occurs because for a scroll bar .Max is an integer and the height of your container can be greater than 32767 (the maximum for an integer). I would suggest you use some sort of scaling for your scroll bar.
Re: I'm getting Overflow and Subscript out of range errors
For your subscript out of range error, think you'll find that your UBound(ClientArrayTop) < picClient.UBound. Easy enough to check. If this is so, verify that changing VScroll1.Max doesn't cause a VScroll1_Change event to occur. If it does, this could be causing the problem
For your overflow error, think you'll find that the MaxValue is less/greater than the min/max integer range. Maybe using scalemode of pixels may correct that problem. A twip which is what I assume is the current scalemode is about 15x more than a pixel; therefore, your values are 15x larger than needed here
Insomnia is just a byproduct of, "It can't be done"
Re: I'm getting Overflow and Subscript out of range errors
Thanks for the input. I changed the scale mode to characters and adjusted all my numbers accordingly. That seems to have taken care of the overflow problem.