Re: Using split function for a csv file with blank line in between

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Test your arrstring to see if it is a valid array before attempting to work with its elements:

arrstring = Split(strline,",")
If LBound(arrstring) <= UBound(arrstring) Then
' do you thing
Else
' empty line read
End If

Note that this method won't work with arrays in general. It will work only with arrays that are set properly by the Split and a few other functions.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"kfng" <kfng@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:DC009C5A-D80F-4B11-A076-F0CF0DCAA007@xxxxxxxxxxxxxxxx
I used split to convert a csv file into a string array. Everything works
fine until I've a file with empty lines in between and when I run the split
function, my program will give an error "Script out of range" as long as it
hits the blank line. How can I overcome this? Is the empty line causing the
problem ? My script is as below

Open filename For Input As #1
x = 0
m = 1
z = a + b
w = 0
For n = 1 To w
Line Input #1, strline
arrstring = Split(strline, ",")
Worksheets("384-template").Range("B1").Offset(x + z, 0).Value =
arrstring(1){Debug stops here}
Worksheets("384-template").Range("C1").Offset(x + z, 0).Value =
arrstring(2)
Worksheets("384-template").Range("D1").Offset(x + z, 0).Value =
arrstring(0)
x = x + 48
m = m + 1
If m > 8 Then
m = 1
x = 0
z = z + 2
End If
'Debug.Print n, x, z, x + z, m
Next n
Close #1


Thanks!

.



Relevant Pages

  • Re: Using split function for a csv file with blank line in between
    ... "Chip Pearson" wrote: ... fine until I've a file with empty lines in between and when I run the ... My script is as below ... arrstring = Split ...
    (microsoft.public.excel.programming)
  • Re: Emptying several arrays at once
    ... Have question if that is possible to empty a few arrays with one simple command? ... The desire to empty arrays is a bad sign. ... or the more comprehensive (but dangerous if other keys are being used) ... %addr if simply went out of scope. ...
    (perl.beginners)
  • Re: Null Range in Unconstrasined Array
    ... Well, arrays don't "point". ... no. Randy gave a reason why a compiler might want to ... has to allocate any space for My_Array above. ... Usually, empty arrays are not statically known to be empty, ...
    (comp.lang.ada)
  • Re: Empty constants
    ... EMPTY_ITERATOR, empty Object arrays, and a few things like empty ... as it plays more nicely with generics. ... For empty arrays, just new them up as needed. ...
    (comp.lang.java.programmer)
  • Re: Emptying several arrays at once
    ... Have question if that is possible to empty a few arrays with one simple command? ... The desire to empty arrays is a bad sign. ... I think the straight forward way is more readable since I ... or the more comprehensive (but dangerous if other keys are being used) ...
    (perl.beginners)