Results 1 to 3 of 3

Thread: Read text file from website VB6

  1. #1

    Thread Starter
    New Member lebersia's Avatar
    Join Date
    Jan 2017
    Location
    Indonesia
    Posts
    2

    Read text file from website VB6

    hello, im new here
    please help me, how to read .txt content from a url?

  2. #2
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Read text file from website VB6

    Quote Originally Posted by lebersia View Post
    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

  3. #3

    Thread Starter
    New Member lebersia's Avatar
    Join Date
    Jan 2017
    Location
    Indonesia
    Posts
    2

    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
  •  



Click Here to Expand Forum to Full Width