GPF error 
Author Message
 GPF error

Hello,

I'm hoping somebody can help me with this problem -- it seems like it
should be easy but I can't figure it out.  I have a little piece of code
for opening and processing a batch of .CSV files.  The problem is that,
after about 7 or so, I get a "General Protection Fault" error, which I
assume means I'm running out of memory.  This happens even if I close
each file after I'm done reading it in.

Help!  Here's the code:

FileNum = FreeFile
Close #FileNum                                'close previously opened
file
Open DataFiles(FileNum) For Input As #FileNum
CountIn = 0
Do While CountIn < SizeOfFile
     CountIn = CountIn + 1
     Input #FileNum, Data1(CountIn)  'read data into array, so I can
transpose it
Loop

Thanks very much in advance to whoever can solve this,

John



Fri, 20 Aug 2004 21:49:21 GMT  
 GPF error
John,

It seems you have a bit of a logic problem, in at least two places.

Quote:
> FileNum = FreeFile
> Close #FileNum                                'close previously opened

I think you have these two lines reversed.  You want to Close FileNum before
getting a new FileNum.  As written, suppose you have a file open with FileNum =
1.  You then get the next FreeFile number, probably 2, and then try to Close 2.
I assume that you really want to close 1, not 2.   Reverse the order of these
two lines.

Quote:
> Open DataFiles(FileNum) For Input As #FileNum

I assume that DataFiles is either a collection or an array of file names.  You
shouldn't be using FileNum as the index into the array, because you shouldn't
rely on FileNum to be any particular number.  Instead, use another variable as
your index into the array.  E.g.,

Dim FileNdx As Long
For FileNdx = LBound(DataFiles) To UBound(DataFiles)
    FileNum = FreeFile
    Open DataFiles(FileNdx) For Input As #FileNum
    CountIn = 0
    Do While CountIn < SizeOfFile
         CountIn = CountIn + 1
         Input #FileNum, Data1(CountIn)
    Loop
    Close #FileNum
Next FileNdx

If DataFiles is a collection rather than an array, change the For FileNdx line
to

For FileNdx = 1 To DataFiles.Count

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC


Quote:
> Hello,

> I'm hoping somebody can help me with this problem -- it seems like it
> should be easy but I can't figure it out.  I have a little piece of code
> for opening and processing a batch of .CSV files.  The problem is that,
> after about 7 or so, I get a "General Protection Fault" error, which I
> assume means I'm running out of memory.  This happens even if I close
> each file after I'm done reading it in.

> Help!  Here's the code:

> FileNum = FreeFile
> Close #FileNum                                'close previously opened
> file
> Open DataFiles(FileNum) For Input As #FileNum
> CountIn = 0
> Do While CountIn < SizeOfFile
>      CountIn = CountIn + 1
>      Input #FileNum, Data1(CountIn)  'read data into array, so I can
> transpose it
> Loop

> Thanks very much in advance to whoever can solve this,

> John



Sun, 22 Aug 2004 23:59:28 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Outlook 2ooo gpf errors

2. XL97: GPF error changing codenames by VBA (LONG)

3. GPF Error cannot be determined

4. Help!! GPF error with combobox

5. GPF Error

6. GPF error in module HPBXLB.DRV

7. Help GPF error on report

8. GPF error in GDI.EXE module

9. PowerPoint and GPF errors

10. Access GPF error Driving me Nuts!!!!


 
Powered by phpBB® Forum Software © phpBB Group