Solved

Data cut off when using string builder with file stream

Posted on 2006-06-23
5
429 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
[X]
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
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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