locked
How do I overcome this limit? RRS feed

  • Question

  • This is some code I got from Microsoft's support page 

    https://support.microsoft.com/en-us/kb/109741

    I modified it a little and I hit a wall when i give i's value larger than 30

    Sub Form_Load()
        
        Image1.Picture = LoadResPicture(101, 1)
        ' Make the picture box bigger than the form:
        'Picture1.Move 0, 0, 2 * ScaleWidth, 2 * ScaleHeight
        ' Position and size the first TextBox:
        Text1(0).Move 0, 0 ', Picture1.Width / 2, Picture1.Height / 20
        ' Place some sample controls in the picture box:
        Dim i As Integer
    //Error Here
        For i = 1 To 31
            Load Text1(i)
            Text1(i).Visible = True
            'Text1(i).Left = Text1(i - 1).Left + 2000
            Text1(i).Top = Text1(i - 1).Top + 1000
            Text1(i).Text = i
        Next
        'Assign the Positions of the endMost objects
        maxTop = Text1(Text1.UBound).Top
        maxLeft = Text1(Text1.UBound).Left
        Picture1.Move 0, 0, maxLeft + 2000, maxTop + 2000
    End Sub
    
    Private Sub Form_Resize()
    'PictureBox's Minimum Size is Always the Size of the Form
    If Picture1.Width < Form1.Width Then
        Picture1.Width = Form1.Width
    End If
    If Picture1.Height < Form1.Height Then
        Picture1.Height = Form1.Height
    End If
        On Error Resume Next
        ' Position the scroll bars:
        HScroll1.Left = 0
        VScroll1.Top = 0
        If Picture1.Width > ScaleWidth Then
            HScroll1.Top = ScaleHeight - HScroll1.Height
        Else
            HScroll1.Top = ScaleHeight
        End If
        If Picture1.Height > HScroll1.Top Then
            VScroll1.Left = ScaleWidth - VScroll1.Width
            If Picture1.Width > VScroll1.Left Then
                HScroll1.Top = ScaleHeight - HScroll1.Height
            End If
        Else
            VScroll1.Left = ScaleWidth
        End If
        HScroll1.Width = ScaleWidth
        If HScroll1.Top > 0 Then VScroll1.Height = HScroll1.Top
        ' Set the scroll bar ranges
        HScroll1.Max = Picture1.Width - VScroll1.Left
        VScroll1.Max = Picture1.Height - HScroll1.Top
        HScroll1.SmallChange = Abs(HScroll1.Max \ 16) + 1
        HScroll1.LargeChange = Abs(HScroll1.Max \ 4) + 1
        VScroll1.SmallChange = Abs(VScroll1.Max \ 16) + 1
        VScroll1.LargeChange = Abs(VScroll1.Max \ 4) + 1
        HScroll1.ZOrder 0
        VScroll1.ZOrder 0
    End Sub
    
    Private Sub HScroll1_Scroll()
    Picture1.Left = -HScroll1.Value
    End Sub
    
    
    Private Sub VScroll1_Scroll()
    Picture1.Top = -VScroll1.Value
    End Sub
    
    How do I overcome this limit?

    • Moved by Youjun Tang Wednesday, September 16, 2015 9:56 AM
    Wednesday, September 9, 2015 6:45 PM

Answers

  • That sounds like a VB 6 or VBA error message. Are you using VB 6? If so, you would be better off posting if VBForums VB6 and earlier forum. This forum support vb.net.
    • Proposed as answer by Frank L. Smith Wednesday, September 9, 2015 7:22 PM
    • Marked as answer by Just Karl Wednesday, September 23, 2015 10:52 PM
    Wednesday, September 9, 2015 7:19 PM

All replies

  • What is the error message that you see?

    How is Text1 declared? If it is an array or collection with 31 elements, the elements will be numbered 0 through 30 and Text1(i) will get an out of range error if I=31.

    Wednesday, September 9, 2015 6:54 PM
  • I'm creating a control array for text1... 

    Maybe the limit lies in the size of the Form or the Picture box...

    When I try to debug the code... The Compiler Highlights the

    Picture1.Move 0, 0, maxLeft + 2000, maxTop + 2000

    Part

    Wednesday, September 9, 2015 6:59 PM
  • What is the error message that you see?

    How is Text1 declared (please post the code that declares it)?

    Wednesday, September 9, 2015 7:07 PM
  • The code above works if i's value is lesser than 31

    I use the load text1(i) to load as shown above

    The error message I get is 

    Runtime error '6':

    Overflow

    It points me to 

    Picture1.Move 0, 0, maxLeft + 2000, maxTop + 2000

    when I click on Debug


    • Edited by Monster4869 Wednesday, September 9, 2015 7:16 PM
    Wednesday, September 9, 2015 7:14 PM
  • That sounds like a VB 6 or VBA error message. Are you using VB 6? If so, you would be better off posting if VBForums VB6 and earlier forum. This forum support vb.net.
    • Proposed as answer by Frank L. Smith Wednesday, September 9, 2015 7:22 PM
    • Marked as answer by Just Karl Wednesday, September 23, 2015 10:52 PM
    Wednesday, September 9, 2015 7:19 PM
  • Sorry..... 
    Wednesday, September 9, 2015 7:20 PM