This repository was archived by the owner on Jan 13, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcChecker.cls
More file actions
115 lines (92 loc) · 2.5 KB
/
Copy pathcChecker.cls
File metadata and controls
115 lines (92 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cChecker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Const strHttp As String = "http://"
Const strHttps As String = "https://"
Public dicBrokenLink As Scripting.Dictionary
Public arrLink As Variant
Public dicUsedLink As Scripting.Dictionary
Private Sub Class_Initialize()
Set dicUsedLink = New Scripting.Dictionary
Set dicBrokenLink = New Scripting.Dictionary
End Sub
Public Sub CheckStatus()
On Error GoTo ErrorHandler
Dim val As Variant
Dim i As String
Me.AddHttpToLink
For Each val In dicUsedLink
i = dicUsedLink.item(val)
Select Case URLResponse(val)
Case False
dicBrokenLink.Add val, i
End Select
Next val
Exit Sub
ErrorHandler:
MsgBox prompt:="AddHttpToLink" & Err.Description & " " & Err.Number
End Sub
Public Sub AddHttpToLink()
On Error GoTo ErrorHandler
Dim val As Variant
Dim posHttp As Integer
Dim posHttps As Integer
Dim arrJoin As Variant
Dim i As String
Me.ConvertArrToDic
For Each val In dicUsedLink
i = dicUsedLink.item(val)
posHttps = InStr(1, val, strHttps, vbTextCompare)
posHttp = InStr(1, val, strHttp, vbTextCompare)
If posHttp > 0 Or posHttps > 0 Then GoTo NextUnit
arrJoin = Array(strHttps, val)
arrJoin = Join(arrJoin, "")
If dicUsedLink.Exists(arrJoin) Then GoTo NextUnit
dicUsedLink.Remove val
dicUsedLink.Add arrJoin, i
NextUnit:
Next val
Exit Sub
ErrorHandler:
MsgBox prompt:="AddHttpToLink" & Err.Description & " " & Err.Number
End Sub
Public Sub ConvertArrToDic()
On Error GoTo ErrorHandler
Dim val As Variant
For Each val In arrLink
If Not (dicUsedLink.Exists(val)) Then
dicUsedLink.Add val, val
End If
Next val
Exit Sub
ErrorHandler:
MsgBox prompt:="ConvertArrToDic" & Err.Description & " " & Err.Number
End Sub
Private Function URLResponse(ByVal strUrl As String) As Boolean
On Error GoTo ErrHandler
Dim ErrorCode As Boolean
Dim codStatus As String
Dim objRequest As Object
Set objRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
With objRequest
.Open "GET", strUrl
.Send
codStatus = .status
End With
If codStatus = "200" Then
ErrorCode = True
GoTo ExitHandler
End If
ErrHandler:
ErrorCode = False
ExitHandler:
Set objRequest = Nothing
URLResponse = ErrorCode
End Function