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?
Can we see the code?
ASKER
Dim fs As New FileStream("W:\WORKING\A&T _TECH\WebT est 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)
Dim sw As New StreamWriter(fs)
Dim i As Integer
Dim j As Integer
Dim strSyntax As New System.Text.StringBuilder(
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.