Solved

Data cut off when using string builder with file stream

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

14 Experts available now in Live!

Get 1:1 Help Now