Select to view content in your preferred language

Why does WriteLine() add quotes to the string it is writing (to file) - VBA.Net

1847
2
11-25-2010 10:56 AM
TomGiles
Deactivated User
Hello,

I'm on Arcgis10 with VS2008Express with VBA.Net.

I have a parser setup to read a csv file. However when I write the file using code (WRiteLine() ) the parser can no longer read it as separate 'parts'.


My issue: WriteLine() insists on putting quotes around each string, so what the parser could read as:

aField, aValue

has now turned into

"aField, aValue"

My parser can no longer read it (aParsedString.First and .Last both return the entire string between the quotes. I cannot add " as a delimeter as the code won't accept 'aDelim = """ '


Any ideas how I can either fix the parser or get WriteLine to write the string without the quotes? I tried PrintLine based on a suggestion from another post but that writes with quotes, and NOT to individual lines - seemed weird, considering PrintLINE.

Thanks in advance.
Cheers,
Tom
0 Kudos
2 Replies
RuchiraWelikala
Regular Contributor
Can you post the code you have?  Are you getting the values from an attribute table?
I recommend you use a Streamwriter.writeline to write to a file.  A lot better than the method you're using. Google Stream.writer for VB.NET and you'll get a lot of help.  Also, make sure you use VB.NET in google.  There's no such thing as VBA.NET.
0 Kudos
TomGiles
Deactivated User
Thanks for your suggestion - I will look at Stream.Writeline. And... Definitely vb.net 🙂

The code I have reads from csv file using a parser:

Dim filename As String = "c:\log.txt"
Dim fields As String()
Dim delimiter As String = ","

Using parser As New textFileParser(filename)
  parser.SetDelimiter(delimiter)
  While Not parser.EndOfData
    fields = parser.Readfields()

'this parser works using fields.First and fields.Last to read in the two parts (the log.txt file is just 'aField, aValue)
'however this only works when the log.txt file starts with no quotes.


'To Write, I use:

Dim aFile as Long
Dim aFileName as String

aFileName = "c:\log.txt"

FileOpen(aFile, aFileName, OpenMode.Output ... and defaults...)

Writeline(aFile, StringToWrite)
FileClose(aFile)


'end code

I actually got around the issue by going through what the parser was returning char by char looking for the comma - but that is the parser's job in the first place!

I really want to clean it up...
Thanks again for your help.  Going to look at stream.writeline right now.

Cheers mate!
0 Kudos