Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public dicTitle As Scripting.Dictionary
- Public dicFound As Scripting.Dictionary
- Public Function runPolluxFull(voerUit As Boolean, updateList As Boolean)
- Dim myURL As String
- Dim status As Boolean
- Dim inc As Integer
- Dim ObjectsJSON As Object
- Dim jsonlibPollux As New jsonlib
- Dim klaar As Boolean
- Dim WinHttpReq As Object
- Dim responseString As String
- 'Issues beginnen op 1, en niet op 0
- inc = 1
- UserForm1.update.Enabled = False
- status = True
- If updateList = True Then
- Set dicTitle = New Scripting.Dictionary
- Set dicFound = New Scripting.Dictionary
- While status
- On Error GoTo 0
- 'Download file, als errors zijn (geen nieuwe issues) dan status = True
- myURL = local site which provides json
- Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
- WinHttpReq.Open "GET", myURL, False
- WinHttpReq.send
- myURL = WinHttpReq.ResponseBody
- 'Wat error handling met HTTP headers
- If WinHttpReq.status = 200 Then
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Open
- oStream.Type = 1
- oStream.Write WinHttpReq.ResponseBody
- 'Decode response string naar Unicode
- responseString = StrConv(WinHttpReq.ResponseBody, vbUnicode)
- 'Skip als issue niet bestaat
- If responseString = "This issue does not exist" Then
- GoTo OnError
- End If
- 'gooi response door JSON parser
- Set ObjectsJSON = jsonlibPollux.parse(responseString)
- With dicTitle
- .Add inc, ObjectsJSON.Item("title")
- End With
- With dicFound
- .Add inc, ObjectsJSON.Item("description")
- End With
- 'Voeg items toe aan formlist
- With UserForm1.ListBox1
- .AddItem ObjectsJSON.Item("title")
- End With
- 'Check of het text vervangen is, en als dat is stop while
- If klaar = True Then
- status = False
- End If
- 'Nog wat HTTP header error handling
- ElseIf WinHttpReq.status = 404 Then
- status = False
- ElseIf WinHttpReq.status = 403 Then
- MsgBox ("POLLUX Down!")
- Else
- MsgBox ("Error met POLLUX")
- End If
- 'GOTO voor errors
- OnError:
- If inc = 200 Then
- status = False
- End If
- oStream.Close
- inc = inc + 1
- Wend
- End If
- If voerUit = True Then
- 'Select 20 chars naar links, en gebruik deze om te zoeken
- Selection.MoveLeft Unit:=wdCharacter, Count:=40, Extend:=wdExtend
- For i = 1 To dicTitle.Count
- klaar = findReplace(dicTitle.Item(i), "x" + dicTitle.Item(i), dicTitle.Item(i) + vbCrLf + vbCrLf + dicFound.Item(i))
- If klaar = True Then
- Exit For
- End If
- Next i
- End If
- 'Enable update button
- UserForm1.update.Enabled = True
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement