Results 1 to 3 of 3

Thread: [RESOLVED] Error that says : Subscript out of range...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Resolved [RESOLVED] Error that says : Subscript out of range...

    Hi,

    I am getting an error: "Subscript out of range" and highlights the following line:
    VB Code:
    1. dbgAutomobiles.Columns(i).Width = 0

    I have 47 fields in total.

    The following is the code:

    VB Code:
    1. Private Sub Datagridcolumns()
    2. Dim i As Integer
    3. dbgAutomobiles.Columns(0).Width = 0
    4. dbgAutomobiles.Columns(1).Width = 3025
    5. dbgAutomobiles.Columns(2).Width = 1000
    6. dbgAutomobiles.Columns(3).Width = 900
    7.  
    8. For i = 4 To dbgAutomobiles.Columns.Count
    9.         dbgAutomobiles.Columns(i).Width = 0
    10. Next
    11. End Sub

    Regards.

    Seema_s
    Last edited by seema_s; May 13th, 2006 at 09:59 AM.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Error that says : Subscript out of range...

    The columns have a 0-based index so you need:
    VB Code:
    1. For i = 4 To dbgAutomobiles.Columns.Count - 1

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: Error that says : Subscript out of range...

    Quote Originally Posted by bushmobile
    The columns have a 0-based index so you need:
    VB Code:
    1. For i = 4 To dbgAutomobiles.Columns.Count - 1
    Thanks it works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width