Re: Writing to file
- From: "amdrit" <amdrit@xxxxxxxxxxx>
- Date: Thu, 18 Mar 2010 11:32:19 -0500
I am sure there is no reason to abandon the writeall method, as you say, it
works for you.
I do question why you are thinking you need to create an array of strings
though. The end result is to simply write the data to a files and
WriteLine() simply takes your text and appends a line terminator at the end
so it doesn't matter how many line breaks are in the string itself.
dim myString as string = "test1" & vbcrlf & _
"test2" & vbcrlf & _
"test3" & vbcrlf & _
"test4" & vbcrlf & _
"test5"
return myString
I see it as an advantage to always understand why code doesn't behave as you
expect. Call it lessons learned, but building your undestanding on such
topics serves to expedite future approaches and implementations.
"mp" <nospam@xxxxxxxxxx> wrote in message
news:%23p5z%23WrxKHA.1548@xxxxxxxxxxxxxxxxxxxxxxx
"amdrit" <amdrit@xxxxxxxxxxx> wrote in message
news:OIxm8PrxKHA.2012@xxxxxxxxxxxxxxxxxxxxxxx
You can also add some debugging information in your code to see what is
going on as it is happening.
option explicit
option strict
imports system
imports system.io
imports system.diagnostics
dim debuglevel as integer
public sub ExportData()
dim comadelimline as string = string.empty
debuglevel = 4
try
using sw as new streamwriter(file.combine(rootpath, filename))
sw.autoflush = true
For Each blockref As Object In m_ssetProfiles
commadelimline = GetFormCutListFromProfileBlock(blockref)
sw.writeline(commadelimline);
Trace.WriteLineIf(DebugLevel = 4, string.format("file postion is
currently at {0}", sw.posistion )
'sw.posistion might be sw.basestream.posistion
next blockref
end using
end try
catch (ex as Exception)
'Report and Clean-Up
Trace.WriteLineIf(DebugLevel > 1 , string.format("An error occured
exporting the data. {0} The exception reported is: {1}",
environment.newline, ex.tostring() )
Throw new ApplicationException("Unable to export data",ex)
end catch
end sub
private function GetFormCutListFromProfileBlock(ByVal blockref As
AcadBlockReference) as string
''calculate stuff then write to file
Dim CommaDelimLine As String = string.empty
CommaDelimLine = sQty & ","& _
sMoldPartName & ","& _
sWidthLiner & ","& _
sLengthLiner & ","& _
m_sMatlLinername & ","& _
m_ssheetwidth & ","& _
m_ssheetthick & ","& _
m_shasgrain & ","& _
sLabeltest
Trace.WriteLineIf(DebugLevel = 4, commadelimline)
return CommaDelimLine
end function
well, that's a thought to revise GetFormCutListFromProfileBlock from sub
to function and return the string
in this case it would be a string() since it writes several lines, not
just one.
and i'm thinking for some reason that is the problem that i'm trying to
write in an inside one sub but the streamwriter was created and closed in
an enclosing sub
since File.AppendAllText works, i don't know if there's compelling reason
to get the StreamWriter working, but I'd still like to know what i'm doing
wrong.
guess i'll have to do a small test prog to isolate this problem and make
sure something else in my code isn't hosing it...
i'll stick a try catch in there to to see what's up
Thanks for the ideas
mark
.
- Follow-Ups:
- Re: Writing to file
- From: mp
- Re: Writing to file
- References:
- Writing to file
- From: mp
- Re: Writing to file
- From: Family Tree Mike
- Re: Writing to file
- From: mp
- Re: Writing to file
- From: mp
- Re: Writing to file
- From: Armin Zingler
- Re: Writing to file
- From: mp
- Re: Writing to file
- From: Armin Zingler
- Re: Writing to file
- From: amdrit
- Re: Writing to file
- From: mp
- Writing to file
- Prev by Date: Re: Where is WriteProfileString data stored?
- Next by Date: Re: U/LBound & copying arrays
- Previous by thread: Re: Writing to file
- Next by thread: Re: Writing to file
- Index(es):
Relevant Pages
|