Retrieve the title of a HTML page
By: Lorenzo Dalla Vecchia Date: 23/06/2000

This tip uses my GetChunck function: for more information see Get a chunck of text delimited by two strings.
Start with copying yhe following code into a module:

Public Function GetChunck(strString As String, _
strBegin As String, strEnd As String) As String
    Dim p0 As Integer, p1 As Integer
    p0 = InStr(strString, strBegin) + Len(strBegin)
    p1 = InStr(strString, strEnd)
    If p0 = 0 Or p1 = 0 Then GetChunck = "": Exit Function
    GetChunck = Mid(strString, p0, p1 - p0)
End Function

The above function can retrieve the text between two strings. The title of a HTML page is included between the strings <title> and </title>. Here's the code:

Dim FileText As String
Dim Title As String

'Open web page and read text
Open "filename.html" For Input As #1
FileText = Input(LOF(1), #1)
Close #1

'Get the title
Title = GetChunck(FileText, "<title>", "</title>")

Replace "filenmae.html" with proper filename/path.
Title string will contain the title of the web page.

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: