Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: subscript out of range

    For some reason the value in a variable in a function is not passed to a subprocedure.
    Can anyone tell me why

    Option Compare Database
    Option Explicit
    Dim field_list() As String, field_list_length As Integer
    Dim display_fields() As String


    Public Sub Form_Open(Cancel As Integer)

    Screen.MousePointer = 11
    Call load_const
    Me!shipping_sched_list_subform.SourceObject = "shipping_sched_list"

    field_list_length = 24
    ReDim display_fields(field_list_length)
    ReDim field_list(field_list_length)
    Call intialize_field_list
    Call prep_sched_input
    …
    …..
    End Sub

    Sub prep_sched_input()
    Call initialize_display_fields
    ….
    ….
    End Sub


    Sub initialize_display_fields()
    Dim i As Integer

    For i = 0 To field_list_length
    ‘’’’***Error: “Subscript out of range”
    ‘’’’The problem lies here in the field_list_length
    ‘’’It should store the value 24 instead it has 0 when I did a debug.

    display_fields(i) = ""
    Next
    End Sub

    Thank you

  2. #2
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820

    Re: subscript out of range

    i'm not sure why the variable resets and causes the problem but you arn't passing it to the subs you've declared it as a local global try passing it the proper way ie

    Code:
    Option Compare Database
    Option Explicit
    Dim field_list() As String, 
    Dim display_fields() As String
    
    
    Public Sub Form_Open(Cancel As Integer)
        dim field_list_length As Integer
        Screen.MousePointer = 11
        Call load_const
        Me!shipping_sched_list_subform.SourceObject = "shipping_sched_list"
    
        field_list_length = 24 
        ReDim display_fields(field_list_length)
        ReDim field_list(field_list_length)
        Call intialize_field_list
        call prep_sched_input(field_list_length)
    …
    …..
    End Sub
    
    Sub prep_sched_input(field_list_length As Integer)
    Call initialize_display_fields(field_list_length)
    ….
    ….
    End Sub
    
    
    Sub initialize_display_fields(field_list_length As Integer)
    Dim i As Integer
    
        For i = 0 To field_list_length
    		
            display_fields(i) = ""
        Next
    End Sub
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

Posting Permissions

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