Private 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
Dim strFileName As String
Dim strFileContent As String
Dim nFreeFile As Integer
Dim nFileLenght As Integer
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
strfilename="C:\blablabla.htm" 'задаём файл для записи на диск
DownloadFile "http://www.blablabla.com/blablabla.htm", strfilename 'загружаем страницу из Инета
nFreeFile = FreeFile
Open strFileName For Input As nFreeFile 'открываем загруженный файл
nFileLenght = FileLen(strFileName) 'определяем длину файла
strFileContent = Input(nFileLenght, #nFreeFile) 'читаем данные из файла...
txtFile.Text = strFileContent '... и выводим их в ТекстБокс.
Close 'закрываем файл
End Sub
Public Function GetInetCBRRates(ByVal CurrencyID As String, Optional ByVal RateDate) As Currency
Dim inet As Object, itbl As Object, U As String
Dim curID As String, curCode As String, curName As String, curK As Long, curRate As Currency
Dim R As Long, C As Long, Z As String, fFind As Boolean
Const URL As String = "http://www.cbr.ru/currency_base/D_print.asp?date_req=#D#/#M#/#Y#"
Const READYSTATE_UNINITIALIZED As Long = 0&
Const READYSTATE_LOADING As Long = 1&
Const READYSTATE_LOADED As Long = 2&
Const READYSTATE_INTERACTIVE As Long = 3&
Const READYSTATE_COMPLETE As Long = 4&
If IsMissing(RateDate) Then RateDate = Now Else RateDate = CDate(RateDate)
U = URL
U = Replace(U, "#D#", Format$(RateDate, "DD"))
U = Replace(U, "#M#", Format$(RateDate, "MM"))
U = Replace(U, "#Y#", Format$(RateDate, "YYYY"))
Set inet = CreateObject("InternetExplorer.Application")
inet.Navigate U
Do Until inet.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Set itbl = inet.Document.All.Tags("TABLE").Item(2)
For R = 1 To itbl.Rows.Length - 1
For C = 1 To itbl.Rows(R).Cells.Length
Z = Trim$(itbl.Rows(R).Cells(C - 1).InnerText)
Select Case C
Case 1
curID = Z
Case 2
curCode = Z
Case 3
Z = Replace(Z, " ", "")
Z = Replace(Z, ",", ".")
curK = CLng(Z)
If curK = 0 Then curK = 1
Case 4
curName = Z
Case 5
Z = Replace(Z, " ", "")
Z = Replace(Z, ",", ".")
curRate = CCur(Z)
End Select
If C = 5 Then
If CurrencyID = curID Then fFind = True
If UCase$(CurrencyID) = UCase$(curCode) Then fFind = True
End If
If fFind Then Exit For
Next C
If fFind Then Exit For
Next R
Set itbl = Nothing
inet.Quit
Set inet = Nothing
If fFind Then GetInetCBRRates = curRate / curK
End Function
Сейчас этот форум просматривают: SemrushBot, Yandex-бот и гости: 15