-
May 24th, 2010, 11:16 PM
#1
Thread Starter
New Member
Writing from lstbox to HTML file.
Hi guys,
New here and also fairly new to VB
Was just wondering how you can write multiple values from a list box to a html file.
I have 6 list boxes. 1 - 2 - 3 - 4 - 5 - 6
and would like the date to go like this:
1 - 2 - 3 - 4 - 5 - 6
1 - 2 - 3 - 4 - 5 - 6
1 - 2 - 3 - 4 - 5 - 6
1 - 2 - 3 - 4 - 5 - 6 etc.
Any help would be appreciated guys,
Rob.
Currently Have:
Code:
Dim sw_HTMLwrite As StreamWriter
Dim sHtmlReport As String
Dim sOfficeId As String
Dim sb As New System.Text.StringBuilder
Dim sline As String
Dim sConsNumber As String
Dim sShipMethod As String
Dim sExpDepature As String
Dim sExpArrival As String
Dim sShipCost As String
Dim sShipDuration As String
For i As Integer = 0 To Me.lbxShippingConsignmentNumber.Items.Count - 1
sConsNumber = lbxShippingConsignmentNumber.Items(i)
sShipMethod = lbxShipmentMethod.Items(i)
sExpDepature = lbxExpectedDepartureDate.Items(i)
sExpArrival = lbxExpectedArrivalTime.Items(i)
sShipCost = lbxShipmentCost.Items(i)
sShipDuration = lbxShipmentDuration.Items(i)
sline = "<TR><TD>" & sConsNumber & "</TD><TD>" & sShipMethod & "</TD></TR>" & sExpDepature & "</TD></TR>" & sExpArrival & "</TD></TR>" & sShipCost & "</TD></TR>" & sShipDuration & "</TD></TR>"
sOfficeId = lblOfficeIDOutput.Text
sHtmlReport = ("C:\Users\Rob\University\Semester 1 - 2010\Business Information Systems\TPECRS SAMPLE\Office Consignment File -" + sOfficeId + ".html")
sw_HTMLwrite = New StreamWriter(sHtmlReport)
sw_HTMLwrite.WriteLine("<HTML>")
sw_HTMLwrite.WriteLine("<HEAD>")
sw_HTMLwrite.WriteLine("<TITLE>Consignment Report - Office " + sOfficeId + "</TITLE>")
sw_HTMLwrite.WriteLine("</HEAD>")
sw_HTMLwrite.WriteLine("<BODY>")
sw_HTMLwrite.WriteLine("<BODY bgcolor=Blue>")
sw_HTMLwrite.WriteLine("<h1>Consignment Report - Office " + sOfficeId + "</h1>")
sw_HTMLwrite.WriteLine("<TABLE BORDER=1>")
sw_HTMLwrite.WriteLine("<TR><TH> Consignment Number </TH><TH> Shipment Method </TH><TH> Exp Deptature Date </TH><TH> Exp Arrival Date </TH><TH> Shipment Cost </TH><TH> Shipment Duration </TH></TR>")
sw_HTMLwrite.WriteLine(sline)
sw_HTMLwrite.WriteLine("</TABLE>")
sw_HTMLwrite.WriteLine("</BODY>")
sw_HTMLwrite.WriteLine("</HTML>")
sw_HTMLwrite.Close()
Next
but is only saving one line (the last data of the list box)
Last edited by Rmckenna; May 24th, 2010 at 11:46 PM.
Reason: To display code/not double post.
-
May 25th, 2010, 12:44 AM
#2
Re: Writing from lstbox to HTML file.
You're writing <HTML>...<BODY> (your data1) </HTML> then again <HTML> ... your data2 </HTML> etc.
As soon as browser hits </HTML> tag it stops reading.
You only need putting in a cycle the table cells, nothing more. Everything else should be outside FOR...NEXT
vb Code:
Dim sw_HTMLwrite As StreamWriter
Dim sHtmlReport As String
Dim sOfficeId As String
Dim sb As New System.Text.StringBuilder
Dim sline As String
Dim sConsNumber As String
Dim sShipMethod As String
Dim sExpDepature As String
Dim sExpArrival As String
Dim sShipCost As String
Dim sShipDuration As String
sHtmlReport = ("C:\Users\Rob\University\Semester 1 - 2010\Business Information Systems\TPECRS SAMPLE\Office Consignment File -" + sOfficeId + ".html")
sw_HTMLwrite = New StreamWriter(sHtmlReport)
sw_HTMLwrite.WriteLine("<HTML>")
sw_HTMLwrite.WriteLine("<HEAD>")
sw_HTMLwrite.WriteLine("<TITLE>Consignment Report - Office " + sOfficeId + "</TITLE>")
sw_HTMLwrite.WriteLine("</HEAD>")
sw_HTMLwrite.WriteLine("<BODY>")
sw_HTMLwrite.WriteLine("<BODY bgcolor=Blue>")
sw_HTMLwrite.WriteLine("<h1>Consignment Report - Office " + sOfficeId + "</h1>")
sw_HTMLwrite.WriteLine("<TABLE BORDER=1>")
sw_HTMLwrite.WriteLine("<TR><TH> Consignment Number </TH><TH> Shipment Method </TH><TH> Exp Deptature Date </TH><TH> Exp Arrival Date </TH><TH> Shipment Cost </TH><TH> Shipment Duration </TH></TR>")
' Only this part requires a loop. The rest (see above and below the loop)
' should be called only once.
For i As Integer = 0 To Me.lbxShippingConsignmentNumber.Items.Count - 1
sConsNumber = lbxShippingConsignmentNumber.Items(i)
sShipMethod = lbxShipmentMethod.Items(i)
sExpDepature = lbxExpectedDepartureDate.Items(i)
sExpArrival = lbxExpectedArrivalTime.Items(i)
sShipCost = lbxShipmentCost.Items(i)
sShipDuration = lbxShipmentDuration.Items(i)
sline = "<TR><TD>" & sConsNumber & "</TD><TD>" & sShipMethod & "</TD></TR>" & sExpDepature & "</TD></TR>" & sExpArrival & "</TD></TR>" & sShipCost & "</TD></TR>" & sShipDuration & "</TD></TR>"
sOfficeId = lblOfficeIDOutput.Text
sw_HTMLwrite.WriteLine(sline)
Next
sw_HTMLwrite.WriteLine("</TABLE>")
sw_HTMLwrite.WriteLine("</BODY>")
sw_HTMLwrite.WriteLine("</HTML>")
sw_HTMLwrite.Close()
Last edited by cicatrix; May 25th, 2010 at 12:49 AM.
-
May 25th, 2010, 01:12 AM
#3
Thread Starter
New Member
Re: Writing from lstbox to HTML file.
-
May 25th, 2010, 01:12 AM
#4
Addicted Member
Re: Writing from lstbox to HTML file.
< off-topic question removed by moderator >
Last edited by si_the_geek; May 25th, 2010 at 05:29 AM.
-
May 25th, 2010, 01:17 AM
#5
Thread Starter
New Member
Re: Writing from lstbox to HTML file.
One last thing actually, how can I make it so if the file path already exists, it ADDS to that file, rather than overwriting? Cheers.
-
May 25th, 2010, 01:26 AM
#6
Re: Writing from lstbox to HTML file.
Originally Posted by Rmckenna
One last thing actually, how can I make it so if the file path already exists, it ADDS to that file, rather than overwriting? Cheers.
Generally, you can, but this won't help you in this particular case.
To open file in append mode you should use this overload:
Code:
Dim sw_HTMLwrite As New IO.StreamWriter(New IO.FileStream(sHtmlReport, IO.FileMode.Append))
Note IO.FileMode.Append
But in this case merely adding something below a html file which has structure will repeat the problem you had in the very beginning.
The only valid portion of a HTML file is the one that resides between <HTML>...</HTML> tags. Anything that is past </HTML> will be ignored.
In your case you already have a closing </HTML> tag at the end of the file so writing past it is futile because no browser will recognize it.
@coccoster: Make a new thread with your question.
-
May 25th, 2010, 01:29 AM
#7
Thread Starter
New Member
Re: Writing from lstbox to HTML file.
Thank you for your help, cicatrix, truly appreciate it.
-
May 25th, 2010, 01:34 AM
#8
Addicted Member
Re: Writing from lstbox to HTML file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|