Subscript out of range Error when using Arrays 
Author Message
 Subscript out of range Error when using Arrays

Hi all,

I keep getting a Error "Subscript out of range" Runtime error 9?
please help??? I think it is related to one of the Arrays

Dim RsCSV As New ADODB.Recordset
Dim Lines() As String, fields() As String
Dim i As Long, j As Long
Dim path As String
Dim strToFind As String

  strToFind = """"

 strDelim = Chr$(cmbDelimiter.ItemData(cmbDelimiter.ListIndex))
Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.

    Open ComDial1.FileTitle For Input As #1
    'Read the contents of the file, and process each individual line.
    Lines() = Split(Input(LOF(1), 1), vbCrLf)
    Close #1

    'Process the first line, which contains the list of fields.
     fields() = Split(Lines(0), strDelim)
     For j = 0 To UBound(fields)
       RsCSV.fields.Append fields(j), adChar, 200
     Next
     RsCSV.Open

    ReDim FieldNames(0 To fieldMax) As Variant
    For j = 0 To fieldMax
       FieldNames(j) = fields(j)
    Next

   For i = 1 To UBound(Lines)
      'Modify Data as it is put in array,removed here because needed to
search entire file
      'fields() = Split((Replace(Lines(i), strToFind, "")), strDelim) '
Remove all "
      fields() = Split(Lines(i), strDelim)

      ReDim fieldValues(0 To fieldMax) As Variant
           For j = 0 To UBound(fields)
                fieldValues(j) = fields(j) 'Move values into the Variant
Array.
          Next
         RsCSV.AddNew FieldNames(), fieldValues()
   Next

    RsCSV.MoveFirst

      Set DataGrid1.DataSource = RsCSV

Screen.MousePointer = vbDefault ' Return mouse pointer to normal.



Tue, 18 Jan 2005 02:40:16 GMT  
 Subscript out of range Error when using Arrays
What line of code is causing the error??

--
Veign
www.veign.com
NEW ActiveX Control - Jeweled Style Buttons
www.veign.com/download_activex.html#jwldbutn
Code Samples & Sample Projects
http://www.veign.com/information/application/info_app.html
Submit Your Best Code (you keep the rights)
http://www.veign.com/information/application/code_submit.html
---------

Quote:
> Hi all,

> I keep getting a Error "Subscript out of range" Runtime error 9?
> please help??? I think it is related to one of the Arrays

> Dim RsCSV As New ADODB.Recordset
> Dim Lines() As String, fields() As String
> Dim i As Long, j As Long
> Dim path As String
> Dim strToFind As String

>   strToFind = """"

>  strDelim = Chr$(cmbDelimiter.ItemData(cmbDelimiter.ListIndex))
> Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.

>     Open ComDial1.FileTitle For Input As #1
>     'Read the contents of the file, and process each individual line.
>     Lines() = Split(Input(LOF(1), 1), vbCrLf)
>     Close #1

>     'Process the first line, which contains the list of fields.
>      fields() = Split(Lines(0), strDelim)
>      For j = 0 To UBound(fields)
>        RsCSV.fields.Append fields(j), adChar, 200
>      Next
>      RsCSV.Open

>     ReDim FieldNames(0 To fieldMax) As Variant
>     For j = 0 To fieldMax
>        FieldNames(j) = fields(j)
>     Next

>    For i = 1 To UBound(Lines)
>       'Modify Data as it is put in array,removed here because needed to
> search entire file
>       'fields() = Split((Replace(Lines(i), strToFind, "")), strDelim) '
> Remove all "
>       fields() = Split(Lines(i), strDelim)

>       ReDim fieldValues(0 To fieldMax) As Variant
>            For j = 0 To UBound(fields)
>                 fieldValues(j) = fields(j) 'Move values into the Variant
> Array.
>           Next
>          RsCSV.AddNew FieldNames(), fieldValues()
>    Next

>     RsCSV.MoveFirst

>       Set DataGrid1.DataSource = RsCSV

> Screen.MousePointer = vbDefault ' Return mouse pointer to normal.



Tue, 18 Jan 2005 02:55:09 GMT  
 Subscript out of range Error when using Arrays
 fieldValues(j) = fields(j) 'Move values into the Variant Array.

this is what is highlighted in yellow when I click Debug

thanks
GV


Quote:
> What line of code is causing the error??

> --
> Veign
> www.veign.com
> NEW ActiveX Control - Jeweled Style Buttons
> www.veign.com/download_activex.html#jwldbutn
> Code Samples & Sample Projects
> http://www.veign.com/information/application/info_app.html
> Submit Your Best Code (you keep the rights)
> http://www.veign.com/information/application/code_submit.html
> ---------


> > Hi all,

> > I keep getting a Error "Subscript out of range" Runtime error 9?
> > please help??? I think it is related to one of the Arrays

> > Dim RsCSV As New ADODB.Recordset
> > Dim Lines() As String, fields() As String
> > Dim i As Long, j As Long
> > Dim path As String
> > Dim strToFind As String

> >   strToFind = """"

> >  strDelim = Chr$(cmbDelimiter.ItemData(cmbDelimiter.ListIndex))
> > Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.

> >     Open ComDial1.FileTitle For Input As #1
> >     'Read the contents of the file, and process each individual line.
> >     Lines() = Split(Input(LOF(1), 1), vbCrLf)
> >     Close #1

> >     'Process the first line, which contains the list of fields.
> >      fields() = Split(Lines(0), strDelim)
> >      For j = 0 To UBound(fields)
> >        RsCSV.fields.Append fields(j), adChar, 200
> >      Next
> >      RsCSV.Open

> >     ReDim FieldNames(0 To fieldMax) As Variant
> >     For j = 0 To fieldMax
> >        FieldNames(j) = fields(j)
> >     Next

> >    For i = 1 To UBound(Lines)
> >       'Modify Data as it is put in array,removed here because needed to
> > search entire file
> >       'fields() = Split((Replace(Lines(i), strToFind, "")), strDelim) '
> > Remove all "
> >       fields() = Split(Lines(i), strDelim)

> >       ReDim fieldValues(0 To fieldMax) As Variant
> >            For j = 0 To UBound(fields)
> >                 fieldValues(j) = fields(j) 'Move values into the Variant
> > Array.
> >           Next
> >          RsCSV.AddNew FieldNames(), fieldValues()
> >    Next

> >     RsCSV.MoveFirst

> >       Set DataGrid1.DataSource = RsCSV

> > Screen.MousePointer = vbDefault ' Return mouse pointer to normal.



Tue, 18 Jan 2005 03:02:20 GMT  
 Subscript out of range Error when using Arrays
Thanks for your help

I figured it out!!!!!!!!!!

I forgot to include this

    Dim fieldmax As Long
     fieldmax = UBound(fields)

thanks again
Gerry


Quote:
> fieldValues(j) = fields(j) 'Move values into the Variant Array.

> this is what is highlighted in yellow when I click Debug

> thanks
> GV



> > What line of code is causing the error??

> > --
> > Veign
> > www.veign.com
> > NEW ActiveX Control - Jeweled Style Buttons
> > www.veign.com/download_activex.html#jwldbutn
> > Code Samples & Sample Projects
> > http://www.veign.com/information/application/info_app.html
> > Submit Your Best Code (you keep the rights)
> > http://www.veign.com/information/application/code_submit.html
> > ---------


> > > Hi all,

> > > I keep getting a Error "Subscript out of range" Runtime error 9?
> > > please help??? I think it is related to one of the Arrays

> > > Dim RsCSV As New ADODB.Recordset
> > > Dim Lines() As String, fields() As String
> > > Dim i As Long, j As Long
> > > Dim path As String
> > > Dim strToFind As String

> > >   strToFind = """"

> > >  strDelim = Chr$(cmbDelimiter.ItemData(cmbDelimiter.ListIndex))
> > > Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.

> > >     Open ComDial1.FileTitle For Input As #1
> > >     'Read the contents of the file, and process each individual line.
> > >     Lines() = Split(Input(LOF(1), 1), vbCrLf)
> > >     Close #1

> > >     'Process the first line, which contains the list of fields.
> > >      fields() = Split(Lines(0), strDelim)
> > >      For j = 0 To UBound(fields)
> > >        RsCSV.fields.Append fields(j), adChar, 200
> > >      Next
> > >      RsCSV.Open

> > >     ReDim FieldNames(0 To fieldMax) As Variant
> > >     For j = 0 To fieldMax
> > >        FieldNames(j) = fields(j)
> > >     Next

> > >    For i = 1 To UBound(Lines)
> > >       'Modify Data as it is put in array,removed here because needed
to
> > > search entire file
> > >       'fields() = Split((Replace(Lines(i), strToFind, "")), strDelim)
'
> > > Remove all "
> > >       fields() = Split(Lines(i), strDelim)

> > >       ReDim fieldValues(0 To fieldMax) As Variant
> > >            For j = 0 To UBound(fields)
> > >                 fieldValues(j) = fields(j) 'Move values into the
Variant
> > > Array.
> > >           Next
> > >          RsCSV.AddNew FieldNames(), fieldValues()
> > >    Next

> > >     RsCSV.MoveFirst

> > >       Set DataGrid1.DataSource = RsCSV

> > > Screen.MousePointer = vbDefault ' Return mouse pointer to normal.



Tue, 18 Jan 2005 03:08:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Defining an array and getting Subscript Out of Range Error

2. HELP! Subscript Out Of Range error referencing array

3. array subscript out of range

4. subscript out of range? (floating array problem)

5. Array Subscript out of range:

6. Passing Arrays to Functions - Subscript Out of Range Problem

7. Arrays Problem SUBSCRIPT OUT OF RANGE

8. Subscript out of range error

9. Subscript out of range error

10. Subscript out of range error

11. AddShapeRecordDetected Error: Subscript out of range

12. help with subscript out of range error

 

 
Powered by phpBB® Forum Software