Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOWNLOAD story of extraction of LOTTO 1

sal21

Programmer
Apr 26, 2004
476
IT
Based this link:


i need to download all story of extraction LOTTO.

From 1871 to 2025

I see possible to have each year based the butto .TXT
 

Attachments

  • LOTTO.jpg
    LOTTO.jpg
    125.1 KB · Views: 5
My test code:

'IN MODULE

Option Explicit

Public Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Public Const ERROR_SUCCESS As Long = 0
Public Const BINDF_GETNEWESTVERSION As Long = &H10
Public Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean

'//'Download the file. BINDF_GETNEWESTVERSION forces
'//'the API to download from the specified source.
'//'Passing 0& as dwReserved causes the locally-cached
'//'copy to be downloaded, if available. If the API
'//'returns ERROR_SUCCESS (0), DownloadFile returns True.

DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function

'IN FORM
Private Sub LOTTO_Click()

Me.Text1.SetFocus

Call LOOP_LOTTO

Me.Text1.SetFocus

End Sub

Private Sub LOOP_LOTTO()

For R = 1871 To Year(Date)
ANNO = R
Call TEST_LOTTO
Next R

End Sub

Private Sub TEST_LOTTO()

Dim URL As String, Path As String
URL = "https://www.lottologia.com/lotto/archivio-estrazioni/?as=TXT&year=" & ANNO
Path = "C:\Lavori_Vb6\LOTTO\FILE_LOTTO\" & ANNO & ".TXT"
Call DownloadFile(URL, Path)

End Sub

this worlk but return the .txt file with 0 kb!
 
Last edited:
Oddly, the code as presented works fine for me. I say 'oddly' because wherever you got this code from has an error. URLDownloadToFile does not take BINDF_GETNEWESTVERSION as a parameter. I'd change that to 0&, as the documentation requires, and see if that helps.

If you really want/need to get the newest version, then in VB the easiest way is to purge the cache with DeleteUrlCacheEntry


>If the API 'returns ERROR_SUCCESS (0), DownloadFile returns True
I also wouldn't rely on this too much. The API pretty much always returns ERROR_SUCCESS
 
DeleteUrlCacheEntry...

Where in my code?

and where i change BINDF_GETNEWESTVERSION with 0&
 
To answer both your questions, add following declaration to beginning of code

Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long

then change

Rich (BB code):
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS

to

Rich (BB code):
DeleteUrlCacheEntry sSourceUrl

DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS
 

Part and Inventory Search

Sponsor

Back
Top