Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Html Coding to be displayed in Textbox

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Resolved [RESOLVED] [2005] Html Coding to be displayed in Textbox

    Hello sir,
    I want HTML coding to be displayed in textbox.
    I having 3 forms. When i press button in form2 the code to be executed.
    So i used the coding below. But am gettting the path of that html file as output. But i actually wants only the code to be displayed.

    Code:
    Private Sub LinkLabel4_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel4.LinkClicked
            Form3.TextBox.Text = (Application.StartupPath & "\Check\c4.html\")
            Form3.Show()
        End Sub

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: [2005] Html Coding to be displayed in Textbox

    Thats right - you are setting the textbox's text property to a string which just happens to be the path of a file.

    A textbox isn't capable of loading an HTML file directly (or any other file for that matter).

    You would need to read the html into a string and then set the text box's text property to that string.

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: [2005] Html Coding to be displayed in Textbox

    Something along the lines of

    vb Code:
    1. Imports System.IO
    2. Public Class Form1
    3.     Private Sub Button1_Click(ByVal sender As System.Object, _
    4. ByVal e As System.EventArgs) Handles Button1.Click
    5.         Try
    6.             Dim line As String
    7.             Dim sHTML as String
    8.             Dim readFile As System.IO.TextReader = New _
    9.                 StreamReader((Application.StartupPath & "\Check\c4.html\")
    10. )
    11.             While True
    12.                 line = readFile.ReadLine()
    13.                 If line Is Nothing Then
    14.                     Exit While
    15.                 Else
    16.                     sHTML = sHTML & line & vbCrLf
    17.                 End If
    18.             End While
    19.             readFile.Close()
    20.             readFile = Nothing
    21.  
    22.             TextBox.Text = sHTML
    23.  
    24.         Catch ex As IOException
    25.             MsgBox(ex.ToString)
    26.         End Try
    27.  
    28.  
    29.     End Sub
    30. End Class

  4. #4

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: [2005] Html Coding to be displayed in Textbox

    Quote Originally Posted by keystone_paul
    Something along the lines of

    vb Code:
    1. Imports System.IO
    2. Public Class Form1
    3.     Private Sub Button1_Click(ByVal sender As System.Object, _
    4. ByVal e As System.EventArgs) Handles Button1.Click
    5.         Try
    6.             Dim line As String
    7.             Dim sHTML as String
    8.             Dim readFile As System.IO.TextReader = New _
    9.                 StreamReader((Application.StartupPath & "\Check\c4.html\")
    10. )
    11.             While True
    12.                 line = readFile.ReadLine()
    13.                 If line Is Nothing Then
    14.                     Exit While
    15.                 Else
    16.                     sHTML = sHTML & line & vbCrLf
    17.                 End If
    18.             End While
    19.             readFile.Close()
    20.             readFile = Nothing
    21.  
    22.             TextBox.Text = sHTML
    23.  
    24.         Catch ex As IOException
    25.             MsgBox(ex.ToString)
    26.         End Try
    27.  
    28.  
    29.     End Sub
    30. End Class
    I used your coding but i am getting this error during runtime.
    Name:  error.bmp
Views: 63
Size:  446.5 KB

  5. #5
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Html Coding to be displayed in Textbox

    Remove the extra slash at the end of the filename:
    Code:
     StreamReader((Application.StartupPath & "\Check\c4.html\"))
    Code:
     StreamReader((Application.StartupPath & "\Check\c4.html"))
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: [2005] Html Coding to be displayed in Textbox

    Sorry I didn't check with your exact filename - as knxrb says just remove the trailing backslash!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width