Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# dll reading .txt file problem...

Status
Not open for further replies.

Glutus

Programmer
Jul 13, 2001
27
0
0
SE
Hi,

I've created a dll that reads a textfile. The dll compiles fine, but when I try to use it in Excel - by reference to the .tlb file - I get an error "The filename, directory name, or volume label syntax is incorrect". It works nicely when I try something simple like if the dll takes an integer and adds 2, but not when reading the file. The code looks like this:

C#
using System;
using System.IO;

public class TestExcelDLL
{
public string test()
{
TextReader myStream=new StreamReader("c:\testdata.txt");
return myStream.ReadLine();
}
}


VBA
Sub test()
Dim x As ExcelDLL.TestExcelDLL
Set x = New ExcelDLL.TestExcelDLL
Range("b2").Value = x.test
Set x = Nothing
End Sub


I know that there are variable limitations - like that you cannot have array because they're varArrays in Excel etc - but I haven't heard anything about reading a textfile. I need to go this way because I want a large chunk of data in my dll and it doesn't take varArrays to my knowledge. Thx in advance.
 
did you double-up your backslash? It should be:
Code:
TextReader myStream=new StreamReader("c:\\testdata.txt");
because the backslash is an escape character in c#.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Well, I knew that it was simple and that I was an idiot. Thanks, now it works perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top