Advertisement
Guest User

Untitled

a guest
Mar 13th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.68 KB | None | 0 0
  1. Public dicTitle As Scripting.Dictionary
  2. Public dicFound As Scripting.Dictionary
  3.  
  4. Public Function runPolluxFull(voerUit As Boolean, updateList As Boolean)
  5. Dim myURL As String
  6. Dim status As Boolean
  7. Dim inc As Integer
  8. Dim ObjectsJSON As Object
  9. Dim jsonlibPollux As New jsonlib
  10. Dim klaar As Boolean
  11. Dim WinHttpReq As Object
  12. Dim responseString As String
  13.  
  14. 'Issues beginnen op 1, en niet op 0
  15. inc = 1
  16. UserForm1.update.Enabled = False
  17. status = True
  18.  
  19. If updateList = True Then
  20. Set dicTitle = New Scripting.Dictionary
  21. Set dicFound = New Scripting.Dictionary
  22.  
  23. While status
  24.     On Error GoTo 0
  25.     'Download file, als errors zijn (geen nieuwe issues) dan status = True
  26.     myURL = local site which provides json
  27.     Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
  28.     WinHttpReq.Open "GET", myURL, False
  29.     WinHttpReq.send
  30.    
  31.     myURL = WinHttpReq.ResponseBody
  32.     'Wat error handling met HTTP headers
  33.     If WinHttpReq.status = 200 Then
  34.         Set oStream = CreateObject("ADODB.Stream")
  35.         oStream.Open
  36.         oStream.Type = 1
  37.         oStream.Write WinHttpReq.ResponseBody
  38.         'Decode response string naar Unicode
  39.         responseString = StrConv(WinHttpReq.ResponseBody, vbUnicode)
  40.         'Skip als issue niet bestaat
  41.         If responseString = "This issue does not exist" Then
  42.         GoTo OnError
  43.         End If
  44.         'gooi response door JSON parser
  45.         Set ObjectsJSON = jsonlibPollux.parse(responseString)
  46.        
  47.         With dicTitle
  48.         .Add inc, ObjectsJSON.Item("title")
  49.         End With
  50.  
  51.         With dicFound
  52.         .Add inc, ObjectsJSON.Item("description")
  53.         End With
  54.        
  55.         'Voeg items toe aan formlist
  56.         With UserForm1.ListBox1
  57.         .AddItem ObjectsJSON.Item("title")
  58.         End With
  59.         'Check of het text vervangen is, en als dat is stop while
  60.         If klaar = True Then
  61.         status = False
  62.         End If
  63.     'Nog wat HTTP header error handling
  64.     ElseIf WinHttpReq.status = 404 Then
  65.         status = False
  66.     ElseIf WinHttpReq.status = 403 Then
  67.         MsgBox ("POLLUX Down!")
  68.     Else
  69.         MsgBox ("Error met POLLUX")
  70.     End If
  71. 'GOTO voor errors
  72. OnError:
  73.     If inc = 200 Then
  74.     status = False
  75.     End If
  76.     oStream.Close
  77.     inc = inc + 1
  78. Wend
  79. End If
  80.  
  81. If voerUit = True Then
  82. 'Select 20 chars naar links, en gebruik deze om te zoeken
  83. Selection.MoveLeft Unit:=wdCharacter, Count:=40, Extend:=wdExtend
  84. For i = 1 To dicTitle.Count
  85. klaar = findReplace(dicTitle.Item(i), "x" + dicTitle.Item(i), dicTitle.Item(i) + vbCrLf + vbCrLf + dicFound.Item(i))
  86.  
  87. If klaar = True Then
  88. Exit For
  89. End If
  90. Next i
  91. End If
  92. 'Enable update button
  93. UserForm1.update.Enabled = True
  94. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement