6 Replies - 2437 Views - Last Post: 23 May 2010 - 05:24 AM Rate Topic: -----

#1 hass10452  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 10

View HTML page in form

Posted 20 May 2010 - 05:13 PM

hey people, i have a button that grabs a text file depending on what the user types in a text box.
And then it loads the text file and makes an HTML report on an external browser. Thats all good.
But i want another button under that button that does exatly the same thing but it displays the html in a form using Web Browser for vb.net. 2008 version by the way.
so i have two buttons, depending on what the user pushes. same html is produced, but one is in external browser while the other is in form.

Here is code i used for first button

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sFilename As String

        sFilename = ("E:\RMIT WORK\Testing\" & txtOfficeID.Text & ".txt")
        If Not File.Exists(sFilename) Then
            MsgBox("IDIOT'")
        Else
            Call LoadHTML()
            Call makeHTMLReport()
        End If

    End Sub
    Private Sub LoadHTML()


        Dim sFileName As String
        Dim sFields(iMax) As String          ' store each field stored in a record
        Dim iNumRecords As Integer        ' number of records read from the file
        Dim sLine As String
        sFileName = ("E:\RMIT WORK\Testing\" & txtOfficeID.Text & ".txt")

        Dim sr_RepFile As StreamReader
        sr_RepFile = File.OpenText(sFileName)
        iNumRecords = 0
        'read the file line by line
        sLine = sr_RepFile.ReadLine
        While sLine <> Nothing And iNumRecords < iMaxConsignments
            sFields = Split(sLine, "|")

            sDutyManagerIDs(iNumRecords) = sFields(0)
            sConsignmentNumbers(iNumRecords) = sFields(1)
            sShipmentMethods(iNumRecords) = sFields(2)
            sExpectedDepartureDates(iNumRecords) = CDate(sFields(3))
            sExpectedArrivalDates(iNumRecords) = CDate(sFields(4))
            sShipmentDurations(iNumRecords) = CInt(sFields(5))
            sShipmentCosts(iNumRecords) = CInt(sFields(6))

            iNumRecords = iNumRecords + 1

            sLine = sr_RepFile.ReadLine
        End While
    End Sub
    Private Sub makeHTMLReport()
        'Variables
        Dim sFilename As String
        Dim sw_RepFile As StreamWriter 'Need a Streamriter to write HTML code into a textfile
        sFilename = ("E:\RMIT WORK\Testing\" & txtOfficeID.Text & ".htm")
        Dim sLine As String
        Dim iFoundIndexPosition As Integer = 0

        Dim sDutyManagerID As String
        Dim sConsignmentNumber As String
        Dim sShipmentMethod As String
        Dim sDepartureDate As String
        Dim sArrivalDate As String
        Dim sShipmentDuration As String
        Dim sShipmentCost As String

        sw_RepFile = New StreamWriter(sFilename)

        sw_RepFile.WriteLine("<HTML>")
        sw_RepFile.WriteLine("<HEAD>")
        sw_RepFile.WriteLine("<TITLE>Office Consignment File: IT99</TITLE>")
        sw_RepFile.WriteLine("</HEAD>")
        sw_RepFile.WriteLine("<BODY>")
        sw_RepFile.WriteLine("<h1> Consignment File for Office IT99 </h1>")
        sw_RepFile.WriteLine("<IMG SRC=E:\TPXELogo.png HEIGHT=100 WIDTH=200><P>")
        sw_RepFile.WriteLine("<TABLE BORDER=1>")
        sw_RepFile.WriteLine("<TR><TH>Duty Manager ID</TH><TH>Consignment Number</TH><TH>Shipment Method</TH><TH>Expected Departure Date</TH><TH>Expected Arrival Date</TH><TH>Shipment Duration</TH><TH>Shipment Cost</TH></TR>")

        'Looping through Office Consignment file and pick up data
        Do While sConsignmentNumbers(iFoundIndexPosition) <> ""
            sDutyManagerID = sDutyManagerIDs(iFoundIndexPosition)
            sConsignmentNumber = sConsignmentNumbers(iFoundIndexPosition)
            sShipmentMethod = sShipmentMethods(iFoundIndexPosition)
            sDepartureDate = sExpectedDepartureDates(iFoundIndexPosition)
            sArrivalDate = sExpectedArrivalDates(iFoundIndexPosition)
            sShipmentCost = sShipmentCosts(iFoundIndexPosition)
            sShipmentDuration = sShipmentDurations(iFoundIndexPosition)

            iFoundIndexPosition = iFoundIndexPosition + 1

            'Declare sLine as a record from the textfile to be writen on the webpage.
            sLine = "<TR><TD>" & sDutyManagerID & "</TD><TD>" & sConsignmentNumber & "</TD><TD>" & sShipmentMethod & "</TH><TH>" & sDepartureDate & "</TH><TH>" & sArrivalDate & "</TH><TH>" & sShipmentDuration & "</TH><TH>" & sShipmentCost & "</TH></TR>"

            sw_RepFile.WriteLine(sLine)
        Loop
        sw_RepFile.WriteLine("</TABLE>")
        sw_RepFile.WriteLine("<P>") 'Jumps to a new line
        sw_RepFile.WriteLine("<A HREF=http://www.rmit.edu.au> Jump to RMIT Home Page </A>")
        sw_RepFile.WriteLine("</BODY>")
        sw_RepFile.WriteLine("</HTML>")

        sw_RepFile.Close()

        System.Diagnostics.Process.Start(sFilename)


Is This A Good Question/Topic? 0
  • +

Replies To: View HTML page in form

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4318
  • View blog
  • Posts: 12,100
  • Joined: 18-April 07

Re: View HTML page in form

Posted 21 May 2010 - 11:13 AM

Did you notice that there is a web browser control in the toolbox? That will allow you to basically run a browser window right on your form. All you have to do then is load the browser control with the HTML report you create instead of launching it using process.start.

Check out the web browser control in action...

WebBrowser Class - MSDN

Be sure to look at its Navigate() method. :)
Was This Post Helpful? 0
  • +
  • -

#3 hass10452  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 10

Re: View HTML page in form

Posted 21 May 2010 - 08:53 PM

HEY thanks for that. Yer i knew about the web browser thingy, but yer thanks your comment helped. i managed to get the it viewing the same form. but when i press the button i would like to close that current form and open another and view it in that. I know i have to use functions or something like That but not good at it. sFilename is the were the report is. how do i send it over to another form? cheers
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: View HTML page in form

Posted 22 May 2010 - 03:07 AM

Use a public property on the new form. When you create the form pass the sFilename value to the property.
Was This Post Helpful? 0
  • +
  • -

#5 hass10452  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 10

Re: View HTML page in form

Posted 22 May 2010 - 07:09 PM

As simple as it sounds im not goood at this stuff. lol
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: View HTML page in form

Posted 23 May 2010 - 03:11 AM

This is the basic layout for a property. This goes on the form you are creating that needs to know the filename.
Private _filename As String
Public Property FileName() As String
    Get
      'any code validating for the string goes here
      'like does it have a "\" at the beginning
      'so it joins well with a directory
      Return _filename
    End Get
    Set(ByVal value As String)
      _filename = value
    End Set
End Property


Code when creating the form.
Dim f As New Form
f.FileName = sFilename
f.Show


Also I like this for disposable objects, looks clean and disposes the object nicely.
Using sr As New StreamReader(...)
...
End Using


HTH
Was This Post Helpful? 0
  • +
  • -

#7 hass10452  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 10

Re: View HTML page in form

Posted 23 May 2010 - 05:24 AM

Hey thanks for that Heaps Man it really helped cheers
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1