Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim data As String
- data = Inet1.OpenURL("http://test.com/sample.txt")
- Text1.Text = data
- Dim Data As String
- Dim DataLines() As String
- Data = Inet1.OpenURL("http://test.com/sample.txt")
- DataLines = Split(Data, vbCrLf)
- For Index = LBound(DataLines) to UBound(DataLines)
- MsgBox DataLines(Index)
- Next
- 'References to MSXML 3.0 or later,
- ' ADO 2.5 or later.
- Private Function GetHttpText(ByVal URL As String) As ADODB.Stream
- Dim Req As MSXML2.XMLHTTP
- Dim CharSet As String
- Dim CharsetPos As Long
- Dim LineSeparator As LineSeparatorEnum
- Set Req = New MSXML2.XMLHTTP
- Set GetHttpText = New ADODB.Stream
- With GetHttpText
- .Open
- .Type = adTypeBinary
- With Req
- .Open "GET", URL, False
- .send
- CharSet = LCase$(.getResponseHeader("CONTENT-TYPE"))
- End With
- .Write Req.responseBody
- CharsetPos = InStr(CharSet, "charset")
- If CharsetPos Then
- CharSet = Split(Mid$(CharSet, CharsetPos), "=")(1)
- Else
- 'UTF-8 is a reasonable "default" these days:
- CharSet = "utf-8"
- End If
- If CharSet = "utf-8" Then
- LineSeparator = adLF
- Else
- 'Your milage may vary here, since there is no line-end
- 'header defined for HTTP:
- LineSeparator = adCRLF
- End If
- .Position = 0
- .Type = adTypeText
- .CharSet = CharSet
- .LineSeparator = LineSeparator
- End With
- End Function
- Private Sub DumpTextLineByLine()
- With GetHttpText("http://textfiles.com/art/simpsons.txt")
- 'Read text line by line to populate a multiline TextBox
- 'just as a demonstration:
- Do Until .EOS
- Text1.SelText = .ReadText(adReadLine)
- Text1.SelText = vbNewLine
- Loop
- .Close
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement