469,925 Members | 1,542 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

COnverting CSV to XLS file

Hi,

I was wondering if one the smart people that frequent this group could
give me a hand with a small program I am attempting to debug.

I am not a highly experienced developer, but can create small
programs.

I was asked to write a small application that would look in a folder,
and convert all the CSV files to XLS.

I thought about using a macro, but they did not want that. Fine.

I wrote a small program in VB .NET (2003, I do nto have 2005 yet).

The program does the following:

For each select file in a list box
delete the existing XLS file, if there
Create a new Excel.Application

The source I used is as follows:
Private myExcelFile As Excel.Application (at the top of the file)

myExcelFile = New Excel.Application
xlConvert(oldFileName, newFilename)
The function called (xConvert) has the following:

******* begin source
Try

tFileNameCSV = MySrcPath + "\" + oldFileName
tFileNameXLS = MySrcPath + "\" + newFileName

' Open the CSV file
'myExcelFile = New Excel.Application
myExcelFile.Visible = False

myExcelFile.Workbooks.Open(MySrcPath + "\" + oldFileName)

'Turn off message box so that we do not get any messages
myExcelFile.DisplayAlerts = False

'Save the file as XLS file
myExcelFile.ActiveWorkbook.SaveAs(Filename:=MySrcP ath +
"\" + newFileName, FileFormat:=Excel.XlFileFormat.xlExcel9795,
CreateBackup:=False)

'Close the workbook
myExcelFile.ActiveWorkbook.Close(SaveChanges:=Fals e)

'Turn the messages back on
myExcelFile.DisplayAlerts = True

'Quit from Excel
myExcelFile.Quit()

'Kill the variable
myExcelFile = Nothing

******* end source

The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

André
Mar 20 '06 #1
5 10108
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin
Mar 20 '06 #2
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin


Mar 20 '06 #3
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin


Mar 20 '06 #4
Hi Brian,

Okay. Blows chunks is a bit of an exageration.:-)

The try ... Catch takes care of that.

The message it generates is as follows (typos are mine):
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Runtime.InteropServices.Marshal.ReleaseComO bject(Object o)
at SelectFolder.Form1.xlConvert(String oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Form1.brnConmverttoXLS_Click(object sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime.InteropServices.Marshal.ReleaseComO bject(myExcelFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Application (a global variable)

The way I understand thing, I am told that the object or whatever that
I am releasing is not an object.

The following lines are what I got from the "Call stack" window:
SelectFolder.exe!SelectFolder.Form1.xlConvert(Stri ng oldFileName =
"1000ES_fieldlengths.csv", String newFileName =
"1000ES_fieldlengths.xls") Line 193 Basic
SelectFolder.exe!SelectFolder.Form1.btnConverttoXL S_Click(Object
sender = {System.Windows.Forms.Button}, System.EventArgs e =
{System.EventArgs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.exe!SelectFolder.Form1.Main() Line 4 + 0x1d bytes Basic
Not sure how to get Trace information. Sorry.

André

On 20 Mar 2006 12:48:33 -0800, "Brian Gideon" <br*********@yahoo.com>
wrote:
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
>"Testguy" <te*****@magma.ca> schrieb
>> The problem is that, as the files get converted, more an more memory
>> is being used (I am converting about 116 files right now).
>>
>> Even after I close the executable, there is still a bunch of memory
>> being used.
>>
>> Looking in the task manager, I could see at one time about 20 copies
>> of Excel.exe in memory.
>>
>> After a while, it settles down to 11 copies in memory.
>>
>> But I thought that, after quitting Excel and setting the variable to
>> "nothing", that this would free up my memory.
>>
>> Any ideas as to what I am doing wrong?
>>
>> Thank you in advance.
>
>
>You must explicitly release COM objects:
>
>http://support.microsoft.com/kb/317109/en-us
>
>
>
>
>Armin


Mar 20 '06 #5
Hi again,

I was playing with the program and, just for the hell, of it decided
to move my statements around.

my declaration for the "excel.application" variable is still a global.

But I moved the "myExcelFile = New Excel.Application" statement in the
subroutine "Form1_Load", and moved the statement "myExcelFile =
Nothing" in the subroutine "Form1_Closing" .

When running the application, Excel is opening once, and the problem
disappears.

Maybe the program was starting and stop the excel process so fast that
it could not deal with the memory issue.

I am confused. It now works properly, but I do not understand why I
previously had all these copy in Excel in memory.

Thanks for all the help.

André

On Mon, 20 Mar 2006 16:31:03 -0500, Testguy <te*****@magma.ca> wrote:
Hi Brian,

Okay. Blows chunks is a bit of an exageration.:-)

The try ... Catch takes care of that.

The message it generates is as follows (typos are mine):
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Runtime.InteropServices.Marshal.ReleaseComO bject(Object o)
at SelectFolder.Form1.xlConvert(String oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Form1.brnConmverttoXLS_Click(object sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime.InteropServices.Marshal.ReleaseCom Object(myExcelFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Application (a global variable)

The way I understand thing, I am told that the object or whatever that
I am releasing is not an object.

The following lines are what I got from the "Call stack" window:
SelectFolder.exe!SelectFolder.Form1.xlConvert(Str ing oldFileName =
"1000ES_fieldlengths.csv", String newFileName =
"1000ES_fieldlengths.xls") Line 193 Basic
SelectFolder.exe!SelectFolder.Form1.btnConverttoX LS_Click(Object
sender = {System.Windows.Forms.Button}, System.EventArgs e =
{System.EventArgs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.exe!SelectFolder.Form1.Main() Line 4 + 0x1d bytes Basic
Not sure how to get Trace information. Sorry.

André

On 20 Mar 2006 12:48:33 -0800, "Brian Gideon" <br*********@yahoo.com>
wrote:
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:

>"Testguy" <te*****@magma.ca> schrieb
>> The problem is that, as the files get converted, more an more memory
>> is being used (I am converting about 116 files right now).
>>
>> Even after I close the executable, there is still a bunch of memory
>> being used.
>>
>> Looking in the task manager, I could see at one time about 20 copies
>> of Excel.exe in memory.
>>
>> After a while, it settles down to 11 copies in memory.
>>
>> But I thought that, after quitting Excel and setting the variable to
>> "nothing", that this would free up my memory.
>>
>> Any ideas as to what I am doing wrong?
>>
>> Thank you in advance.
>
>
>You must explicitly release COM objects:
>
>http://support.microsoft.com/kb/317109/en-us
>
>
>
>
>Armin


Mar 21 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by david | last post: by
4 posts views Thread by mustafa | last post: by
3 posts views Thread by Tim Marsden | last post: by
11 posts views Thread by Gaurav Agarwal | last post: by
11 posts views Thread by juyi520 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.