Solved

Data cut off when using string builder with file stream

Posted on 2006-06-23
5
396 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 62

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 62

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 62

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now