Re: Writing to file



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




.



Relevant Pages

  • Re: Writing to file
    ... Sub AppendToCsvFile2(ByVal CommaDelimLine As String, ... Obviously I don't know what some of these classes yare are using that are app specific. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Writing to file
    ... sorry for top posting...switching from groups that prefre one or the ... Sub AppendToCsvFile2(ByVal CommaDelimLine As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Function call problem
    ... I'm writing this simple function call from a sub, but for some reason ... when I click the file to open, it freezes, can anybody tell me what's ... String, ByVal BaseName As String) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Writing to file
    ... Sub AppendToCsvFile2(ByVal CommaDelimLine As String, ByVal oCSVFile As ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Convert string to object
    ... When calling the sub the form's object description is passed through ... Public Sub ColourMeIn(callingform As Object, Reason As String) ...
    (microsoft.public.access.forms)