home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / checkl1g / checklin.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-06-30  |  5.1 KB  |  178 lines

  1. VERSION 5.00
  2. Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3195
  6.    ClientLeft      =   5820
  7.    ClientTop       =   8445
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3195
  11.    ScaleWidth      =   4680
  12.    Begin VB.TextBox Text1 
  13.       Height          =   1095
  14.       Left            =   120
  15.       MultiLine       =   -1  'True
  16.       TabIndex        =   2
  17.       Text            =   "checklinks.frx":0000
  18.       Top             =   120
  19.       Width           =   3255
  20.    End
  21.    Begin VB.CommandButton Command1 
  22.       Caption         =   "Quit"
  23.       Height          =   495
  24.       Index           =   1
  25.       Left            =   3480
  26.       TabIndex        =   1
  27.       Top             =   2640
  28.       Width           =   1095
  29.    End
  30.    Begin VB.CommandButton Command1 
  31.       Caption         =   "Start"
  32.       Height          =   495
  33.       Index           =   0
  34.       Left            =   3480
  35.       TabIndex        =   0
  36.       Top             =   1920
  37.       Width           =   1095
  38.    End
  39.    Begin InetCtlsObjects.Inet Inet1 
  40.       Left            =   3840
  41.       Top             =   120
  42.       _ExtentX        =   1005
  43.       _ExtentY        =   1005
  44.       _Version        =   393216
  45.       RequestTimeout  =   120
  46.    End
  47.    Begin VB.Label Label4 
  48.       Caption         =   "Label4"
  49.       Height          =   255
  50.       Left            =   120
  51.       TabIndex        =   6
  52.       Top             =   2880
  53.       Width           =   2895
  54.    End
  55.    Begin VB.Label Label3 
  56.       Caption         =   "Label3"
  57.       Height          =   255
  58.       Left            =   120
  59.       TabIndex        =   5
  60.       Top             =   2400
  61.       Width           =   2775
  62.    End
  63.    Begin VB.Label Label2 
  64.       Caption         =   "Label2"
  65.       Height          =   255
  66.       Left            =   120
  67.       TabIndex        =   4
  68.       Top             =   1920
  69.       Width           =   2655
  70.    End
  71.    Begin VB.Label Label1 
  72.       Caption         =   "Label1"
  73.       Height          =   255
  74.       Left            =   120
  75.       TabIndex        =   3
  76.       Top             =   1440
  77.       Width           =   2415
  78.    End
  79. Attribute VB_Name = "Form1"
  80. Attribute VB_GlobalNameSpace = False
  81. Attribute VB_Creatable = False
  82. Attribute VB_PredeclaredId = True
  83. Attribute VB_Exposed = False
  84. Option Explicit
  85. ' Put the full name and path to your file here.
  86. Const FILENAME = "c:\documents\stamps\links.xls"
  87. Dim XLObj As Excel.Application
  88. Private Sub Command1_Click(Index As Integer)
  89. Select Case Index
  90.     Case 0 'Start
  91.         Command1(0).Enabled = False
  92.         Call CheckLinks
  93.         Command1(0).Enabled = True
  94.     Case 1 ' Quit
  95.         End
  96. End Select
  97. End Sub
  98. Private Sub Form_Load()
  99. ' Create the Excel object and open the worksheet.
  100. Set XLObj = CreateObject("Excel.Application")
  101. XLObj.Workbooks.Open FILENAME
  102. Inet1.Protocol = icHTTP
  103. End Sub
  104. Public Sub CheckLinks()
  105. Dim row As Integer, url As String
  106. Dim buf As String, msg As String, fnf As Integer
  107. Dim snf As Integer, tout As Integer, ok As Integer
  108. On Error Resume Next
  109. ' Make row equal to the Worksheet row where
  110. ' your data starts.
  111. row = 4
  112. tout = 0
  113. fnf = 0
  114. ok = 0
  115. snf = 0
  116. ' Minimize the form.
  117. Form1.WindowState = 1
  118.     ' I keep URLs in column 3 (C) of the worksheet.
  119.     url = XLObj.Cells(row, 3)
  120.     ' If it's empty we are done.
  121.     If url = "" Then Exit Do
  122.     ' Try to open the URL.
  123.     Text1.Text = Inet1.OpenURL(url)
  124.     DoEvents
  125.     ' If the URL returned any text, put the
  126.     ' first 50 characters in a buffer. Error
  127.     ' messages will be found here.
  128.     If Len(Text1.Text) > 50 Then
  129.         buf = Left(Text1.Text, 50)
  130.     Else
  131.         buf = Text1.Text
  132.     End If
  133.     ' Catch a time out error.
  134.     If Err = 35761 Then
  135.         msg = "Timed out"
  136.         tout = tout + 1
  137.         Err.Clear
  138.     ' If nothing is returned it usually means
  139.     ' that the server was not found.
  140.     ElseIf Text1.Text = "" Then
  141.         msg = "Server not found"
  142.         snf = snf + 1
  143.     ' If error 404 is returned from the URL
  144.     ' it means the server was found but
  145.     ' the requested file was not present.
  146.     ElseIf InStr(1, buf, "404") Then
  147.         msg = "File not found"
  148.         fnf = fnf + 1
  149.     ' Otherwise the link is OK.
  150.     Else
  151.         msg = "OK"
  152.         ok = ok + 1
  153.     End If
  154.     ' Put the result in column 5 of the worksheet.
  155.     XLObj.Cells(row, 5) = msg
  156.     ' Move to the next row.
  157.     row = row + 1
  158.     ' Display current status on form.
  159.     Form1.Caption = ok + fnf + snf + tout
  160.     Label1.Caption = "OK: " & ok
  161.     Label2.Caption = "File not found: " & fnf
  162.     Label3.Caption = "Server not found: " & snf
  163.     Label4.Caption = "Timed out: " & tout
  164. Loop While True
  165. ' When all links checked, restore the form.
  166. Form1.WindowState = 0
  167. ' Close the worksheet.
  168. XLObj.Workbooks.Close
  169. ' Delete the object.
  170. Set XLObj = Nothing
  171. ' Display a summary of results.
  172. buf = "OK: " & ok & vbCrLf
  173. buf = buf & "Server not found: " & snf & vbCrLf
  174. buf = buf + "File not found: " & fnf & vbCrLf
  175. buf = buf & "Timed out: " & tout
  176. MsgBox (buf)
  177. End Sub
  178.