cofneverlivetotell
asked on
VB .Net text output help needed
Visual Basic 2005 Express Edition, Windows 2000 Pro.
I'm having some problems with a file output, I need to generate a file of HTML from a loop, with non-loop HTML before and after.
I'm using this code to create the file with looped HTMl and after, but the problem comes with getting some before the loop output.
~~~~~~~~~~~~~~~~~~~~
Dim strOutputFilePath As String
Dim strImagePath As String
Dim intPosition As Integer
Dim intEnd As Integer
strOutputFilePath = "C:\Output.html"
strImagePath = "C:\img\"
intEnd = lstQuestionList.Items.Coun t - 1
intPosition = 0
Dim OutputArray(intEnd) As String
While intPosition <= intEnd
OutputArray(intPosition) = "<p><img src=""" + strImagePath + lstList.Items.Item(intPosi tion) + ".jpg""></p>"
intPosition = intPosition + 1
End While
System.IO.File.WriteAllLin es(strOutp utFilePath , OutputArray)
System.IO.File.AppendAllTe xt(strOutp utFilePath , "End of page")
~~~~~~~~~~~~~~~~~
The WriteAllLines function needed to output the array causes anything in the file to be overwritten, and so I can't add any text before this.
Any ideas, experts?
Thanks :D
I'm having some problems with a file output, I need to generate a file of HTML from a loop, with non-loop HTML before and after.
I'm using this code to create the file with looped HTMl and after, but the problem comes with getting some before the loop output.
~~~~~~~~~~~~~~~~~~~~
Dim strOutputFilePath As String
Dim strImagePath As String
Dim intPosition As Integer
Dim intEnd As Integer
strOutputFilePath = "C:\Output.html"
strImagePath = "C:\img\"
intEnd = lstQuestionList.Items.Coun
intPosition = 0
Dim OutputArray(intEnd) As String
While intPosition <= intEnd
OutputArray(intPosition) = "<p><img src=""" + strImagePath + lstList.Items.Item(intPosi
intPosition = intPosition + 1
End While
System.IO.File.WriteAllLin
System.IO.File.AppendAllTe
~~~~~~~~~~~~~~~~~
The WriteAllLines function needed to output the array causes anything in the file to be overwritten, and so I can't add any text before this.
Any ideas, experts?
Thanks :D
Perhaps a StreamWriter will work for you:
Dim sw As New System.IO.StreamWriter(str OutputFile Path)
While intPosition <= intEnd
sw.WriteLine("<p><img src=""" + strImagePath + lstList.Items.Item(intPosi tion) + ".jpg""></p>")
intPosition = intPosition + 1
sw.WriteLine()
End While
sw.Close()
sw.Dispose()
Dim sw As New System.IO.StreamWriter(str
While intPosition <= intEnd
sw.WriteLine("<p><img src=""" + strImagePath + lstList.Items.Item(intPosi
intPosition = intPosition + 1
sw.WriteLine()
End While
sw.Close()
sw.Dispose()
Perhaps a StreamWriter will work for you:
Dim sw As New System.IO.StreamWriter(str OutputFile Path)
While intPosition <= intEnd
sw.WriteLine("<p><img src=""" + strImagePath + lstList.Items.Item(intPosi tion) + ".jpg""></p>")
intPosition = intPosition + 1
'sw.WriteLine() <My mistake, remove this line.
End While
sw.Close()
sw.Dispose()
Dim sw As New System.IO.StreamWriter(str
While intPosition <= intEnd
sw.WriteLine("<p><img src=""" + strImagePath + lstList.Items.Item(intPosi
intPosition = intPosition + 1
'sw.WriteLine() <My mistake, remove this line.
End While
sw.Close()
sw.Dispose()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, VBRocks - The StringBuilder solution worked best, though it formats better for notepad to use Chr(13)'s instead of vbCrLf.
Points awarded, Cheers.
Points awarded, Cheers.
ASKER
<p><img src="C:\img\1.jpg"></p>
<p><img src="C:\img\2.jpg"></p>
<p><img src="C:\img\3.jpg"></p>
<p><img src="C:\img\4.jpg"></p>
<p><img src="C:\img\5.jpg"></p>
<p><img src="C:\img\6.jpg"></p>
End of page