Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. Dim data As String
  2. data = Inet1.OpenURL("http://test.com/sample.txt")
  3. Text1.Text = data
  4.  
  5. Dim Data As String
  6. Dim DataLines() As String
  7.  
  8. Data = Inet1.OpenURL("http://test.com/sample.txt")
  9. DataLines = Split(Data, vbCrLf)
  10. For Index = LBound(DataLines) to UBound(DataLines)
  11. MsgBox DataLines(Index)
  12. Next
  13.  
  14. 'References to MSXML 3.0 or later,
  15. ' ADO 2.5 or later.
  16.  
  17. Private Function GetHttpText(ByVal URL As String) As ADODB.Stream
  18. Dim Req As MSXML2.XMLHTTP
  19. Dim CharSet As String
  20. Dim CharsetPos As Long
  21. Dim LineSeparator As LineSeparatorEnum
  22.  
  23. Set Req = New MSXML2.XMLHTTP
  24. Set GetHttpText = New ADODB.Stream
  25. With GetHttpText
  26. .Open
  27. .Type = adTypeBinary
  28. With Req
  29. .Open "GET", URL, False
  30. .send
  31. CharSet = LCase$(.getResponseHeader("CONTENT-TYPE"))
  32. End With
  33. .Write Req.responseBody
  34. CharsetPos = InStr(CharSet, "charset")
  35. If CharsetPos Then
  36. CharSet = Split(Mid$(CharSet, CharsetPos), "=")(1)
  37. Else
  38. 'UTF-8 is a reasonable "default" these days:
  39. CharSet = "utf-8"
  40. End If
  41. If CharSet = "utf-8" Then
  42. LineSeparator = adLF
  43. Else
  44. 'Your milage may vary here, since there is no line-end
  45. 'header defined for HTTP:
  46. LineSeparator = adCRLF
  47. End If
  48. .Position = 0
  49. .Type = adTypeText
  50. .CharSet = CharSet
  51. .LineSeparator = LineSeparator
  52. End With
  53. End Function
  54.  
  55. Private Sub DumpTextLineByLine()
  56. With GetHttpText("http://textfiles.com/art/simpsons.txt")
  57. 'Read text line by line to populate a multiline TextBox
  58. 'just as a demonstration:
  59. Do Until .EOS
  60. Text1.SelText = .ReadText(adReadLine)
  61. Text1.SelText = vbNewLine
  62. Loop
  63. .Close
  64. End With
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement