-
Jan 21st, 2017, 09:11 PM
#1
Thread Starter
New Member
Read text file from website VB6
hello, im new here 
please help me, how to read .txt content from a url?
-
Jan 21st, 2017, 09:52 PM
#2
Hyperactive Member
Re: Read text file from website VB6
 Originally Posted by lebersia
hello, im new here 
please help me, how to read .txt content from a url? 
prob a few diferent ways ive used this way . . .
put this in a form
Code:
Private Sub Form_Load()
Text1.Text = URLSource("http://www.yoursite.com/svrip.txt")
End Sub
and this in a module
Code:
Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function GetInputState Lib "user32" () As Long
Private Const IF_NO_CACHE_WRITE = &H4000000
Private Const BUFFER_LEN = 256
Public Function URLSource(ByRef URL As String) As String
Dim strBuffer As String * BUFFER_LEN, lonRet As Long
Dim strData As String, lonHandle As Long, lonSession As Long
Dim lonResult As Long
lonSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
If lonSession Then lonHandle = InternetOpenUrl(lonSession, URL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
If lonHandle Then
lonResult = InternetReadFile(lonHandle, strBuffer, BUFFER_LEN, lonRet)
strData = strBuffer
Do While lonRet <> 0
lonResult = InternetReadFile(lonHandle, strBuffer, BUFFER_LEN, lonRet)
strData = strData & Mid$(strBuffer, 1, lonRet)
If GetInputState Then DoEvents
Loop
End If
lonResult = InternetCloseHandle(lonHandle)
URLSource = strData
End Function
-
Jan 21st, 2017, 10:39 PM
#3
Thread Starter
New Member
Re: Read text file from website VB6
oh yeah, thank you friend
this is work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|