Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Data cut off when using string builder with file stream

Posted on 2006-06-23
5
409 Views
Last Modified: 2010-04-23
After I'm through building my string with a string builder, I have check to see what is contained in the string in debug mode. Everything is there. However, when I write the string to a text file, it is chopped off. Any idea why?
0
Comment
Question by:Feyo
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16972168
Can we see the code?
0
 
LVL 4

Author Comment

by:Feyo
ID: 16972179
Dim fs As New FileStream("W:\WORKING\A&T_TECH\WebTest Data\Initial_Extracts\" & strDB & "_" & strSS & "_syntax.sps", FileMode.Create)
        Dim sw As New StreamWriter(fs)
        Dim i As Integer
        Dim j As Integer
        Dim strSyntax As New System.Text.StringBuilder(25000)
        Dim nl = Environment.NewLine

        intPrevId = dt.Rows(0)("cde_question")
        strSyntax.Append("RECODE Q" & dt.Rows(0)("cde_question") & " ")
        For i = 0 To dt.Rows.Count - 1
            intCurId = dt.Rows(i)("cde_question")
            If intCurId = intPrevId Then
                j = j + 1
                strSyntax.Append("(" & dt.Rows(i)("cde_Choice") & "=" & j & ") ")
                intPrevId = dt.Rows(i)("cde_question")
            Else
                strSyntax.Append("." & nl)
                strSyntax.Append("RECODE Q" & dt.Rows(i)("cde_question") & " ")
                j = 0
                strSyntax.Append("(" & dt.Rows(i)("cde_Choice") & "=" & j & ") ")
                intPrevId = dt.Rows(i)("cde_question")
            End If
        Next

        strSyntax.Append("." & nl & nl)
        sw.Write(strSyntax)
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 16972333
From the code you posted I do not see a sw.Close(). If the file is not closed correctly that will cause the type of problem you are seeing. Are you closing the file?
0
 
LVL 4

Author Comment

by:Feyo
ID: 16972375
It's funny, I do have a sw.close(), but I was breaking on there an then checking the file. After I ran that, everything was fine. Thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16972401
No problem, glad I was able to help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question