Results 1 to 13 of 13

Thread: HTML in Visual Basic

  1. #1
    Guest

    Question

    hi,
    i want to insert html into my program, i need to make a text box (of html), so i could insert information into it, and change the color of the lines (or words). how do i do that, and how do i use html in my program.
    thanks..

    Boaz zemeR

  2. #2
    Guest
    Use a Richtextbox and search Richtextbox on the Vb-World itself for "Richtextbox" or "Richtextbox Tags".
    And to insert html:

    Code:
    RichTextBox1.Text = "<html>" & Chr$(13) & Chr$(10) & "<title>" & Chr$(13) & Chr$(10) & "...." & Chr$(13) & Chr$(10) & "</body>" & Chr$(13) & Chr$(10) & "</html>"
    To enter it and keep the older text:

    Either:
    Code:
    Richtextbox1.seltext = "....."
    or
    Code:
    Richtextbox1.text = Richtextbox1.text & "...."

  3. #3
    Guest

    Unhappy html html html

    i cant find much on rich text boxes, but that didnt help much anyway.
    i want the text in the textbox appear as it was in the web browser, not plain html.
    i want to see one line in a color, and the other in another color.

    i cant even change the forecolor property in the richtextbox.

  4. #4
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    You won't get a rich text box to display formatted HTML like you see in IE.

    You can however add the web browser control onto your form, then dynamically generate an HTML page and display it in the web browser control.

    I have done this succesfully several times.


    Regards

    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

  5. #5
    Guest

    Arrow ok, lets get over this again

    i want to write lines in html format (unless you know another way to write indevidual lines in different colors in any other text box)

    i want the first line be blue (for that matter) then the second red, and then the rest blue again

    i know it can be done by html, but i dont want to write a html file, i want to just show it on the text box

    how do i do that?

    thanks..

  6. #6
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Question WebBrowser

    Matt,

    How can I get the WebBrowser to open a file on a local drive. EG file://c:/windows/desktop/trial.htm?

    I can write html on the fly so that's ok but I want to see the resuts!
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  7. #7
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    If your using the browser control

    browser1.Navigate "c:/windows/desktop/trial.htm"

    or execute it into a full default browser using the shell execute API call



    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal opOperation As String, ByVal lpFile As String, ByVal opParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


    Call ShellExecute(0&, vbNullString, "http://c:/windows/desktop/trial.htm"
    , vbNullString, vbNullString, vbNormalFocus)




    Kurt Simons
    [I know I'm a hack but my clients don't!]

  8. #8
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137

    Bzemer

    The following code will output to an html file, which you can then display in the browser control,

    Note:
    I have used a style sheet to do the formatting, I will leave it up to you to write the actual styles, but at the least it needs to have the following classes in it.

    BODY {background-color:#FFFFFF;font-family:verdana;font-size:8pt;}
    .blueLine {color:#0000FF;}
    .redLine {color:#FF0000;}

    You need to add a reference to the Microsoft Scripting Runtime Library to your project for the OpenTheFile function to work correctly.

    You need a webbrowser control called browser on your form

    Call the function
    OutputHTMLCode "Line1", "line2", "therest"

    Code:
    'File to write to
    const HTMLFile = "c:/temp.htm"
    
    'Start of the document.
    const docHead ="<HTML><HEAD><TITLE>Auto Generated HTML</TITLE><LINK REL='stylesheet' HREF='style.css'></HEAD><BODY>"
    
    'End of the document
    const docFooter = "</BODY></HTML>"
    
    'Sub to do the work
    Sub outputHTMLCode(Line1 as string, Line2 as string, theRest as string)
    
       dim docBody as string, theDoc as string
       dim fileNo
     
       'Create the body of the document.
       docBody = "<DIV CLASS='blueLine'>" & Line1 & "</DIV>" & _
         "<DIV CLASS='redLine'>" & Line2 & "</DIV>" & _
         "<DIV CLASS='blueLine'>" & theRest & "</DIV>"
    
       'Concatenate the body to the header and footer
       theDoc = docHeader & docBody & docFooter
    
       'Open a file and write the data to it
       OpenTheFile HTMLFile, 2, theDoc
    
       'Display the page in the browser
       browser.Navigate(HTMLFile)
    
    End Sub
    
    Sub OpenTheFile(FileName As String, _
        Method As Integer, ByRef ts As String)
    
        Dim fs As New Scripting.FileSystemObject
        Dim f
        
        Select Case Method
        Case 1
            If fs.FileExists(FileName) Then
              Set f = fs.OpenTextFile(FileName, 1, False)
              ts = f.ReadAll
              f.Close
            Else
                MsgBox "The File (" & FileName & ") doesn't" & _
                    " exist." & vbCrLf & "Program will now" & _
                    " terminate.", vbCritical, "Error"
                End
            End If
        Case 2
              Set f = fs.OpenTextFile(FileName, 2, True)
              f.Write (ts)
              f.Close
        Case 8
            Set f = fs.OpenTextFile(FileName, 8, True)
            f.Write (ts)
            f.Close
        Case Else
            MsgBox "Bad method in file handling parameter" & _
                vbCrLf & "Program will now Terminate.", _
                vbCritical, "Error"
            End
        End Select
    End Sub

    If there are problems, you know where to find me

    Regards


    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

  9. #9
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Please help me with this post:

    http://forums.vb-world.net/showthrea...threadid=22260


    Thanx.

  10. #10
    Guest

    Arrow explanation

    i think i better explain all from the begining:
    my program rolls up random numbers.
    lets say i chosse to roll a number between 1 and 20.
    i want the program to know that if 20 has rolled up you get te number 20 in the color blue. 1 will be red, and the other is black.

    i need to implement it into my existing code.

    now everything works in a text box with no color.
    i want the color thats all.

    thanks.

  11. #11
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137

    This should do it

    This is pretty much the same code as above, I've just modified it to colour according to the numbers.

    This code assumes pretty much the same things as the other code, except you only pass an integer to the outputHTMLCode sub instead of the 3 lines of text. You will also need to add another class into the css file for the black line.

    Code:
    'File to write to
    const HTMLFile = "c:/temp.htm"
    
    'Start of the document.
    const docHead ="<HTML><HEAD><TITLE>Auto Generated HTML</TITLE><LINK REL='stylesheet' HREF='style.css'></HEAD><BODY>"
    
    'End of the document
    const docFooter = "</BODY></HTML>"
    
    'Sub to do the work
    Sub outputHTMLCode(number as Integer)
    
       dim docBody as string, theDoc as string
       dim fileNo
     
       'Create the body of the document.
       'Decide what colour the line will be
       If number = 20 Then
          docBody = "<DIV CLASS='redLine'>"
       ElseIf number = 1 Then
          docBody = "<DIV CLASS='blueLine'>"
       Else
          docBody = "<DIV CLASS='blackLine'>"
       End If 
    
       'Add the number in
       docBody = docBody & Trim$(Str$(number))
    
       'Close the div
       docBody = docBody & "</DIV>"
    
       'Concatenate the body to the header and footer
       theDoc = docHeader & docBody & docFooter
    
       'Open a file and write the data to it
       OpenTheFile HTMLFile, 2, theDoc
    
       'Display the page in the browser
       browser.Navigate(HTMLFile)
    
    End Sub
    
    Sub OpenTheFile(FileName As String, _
        Method As Integer, ByRef ts As String)
    
        Dim fs As New Scripting.FileSystemObject
        Dim f
        
        Select Case Method
        Case 1
            If fs.FileExists(FileName) Then
              Set f = fs.OpenTextFile(FileName, 1, False)
              ts = f.ReadAll
              f.Close
            Else
                MsgBox "The File (" & FileName & ") doesn't" & _
                    " exist." & vbCrLf & "Program will now" & _
                    " terminate.", vbCritical, "Error"
                End
            End If
        Case 2
              Set f = fs.OpenTextFile(FileName, 2, True)
              f.Write (ts)
              f.Close
        Case 8
            Set f = fs.OpenTextFile(FileName, 8, True)
            f.Write (ts)
            f.Close
        Case Else
            MsgBox "Bad method in file handling parameter" & _
                vbCrLf & "Program will now Terminate.", _
                vbCritical, "Error"
            End
        End Select
    End Sub
    Drop me a line if you need any more help.

    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

  12. #12
    Guest
    i'll try that but how do add a reference to the Microsoft Scripting Runtime Library, as you said above?

  13. #13
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    Got to the Project Menu
    Then select References

    Then check the box next to Microsoft Scripting Runtime library
    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

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