Link to home
Start Free TrialLog in
Avatar of Feyo
Feyo

asked on

Data cut off when using string builder with file stream

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?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Can we see the code?
Avatar of Feyo
Feyo

ASKER

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)
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Feyo

ASKER

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.
No problem, glad I was able to help.