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:
Run-time error '9':
Subscript out of range
Code:If ClientArrayTop(i) - l < -853 Then
Run-time error '6':
Overflow
Code:VScroll1.Max = -1524 + picClient(picClient.UBound).Top + picClient(picClient.UBound).Height
Here is the Entire code:
Code: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




Reply With Quote