Here is a VB6 utility that I wrote to download csv files.
http://www.geocities.com/mbspringer133b/live_1.zip
the web page it comes from is:
http://www.geocities.com/mbspringer133b/
=================================================
for the hard core :) HERE IS THE SOURCE CODE
=================================================
THE STUBS AND ALL ARE STILL IN HERE MODIFY THIS AT YOUR OWN RISK.
WHY BOTHER IT WORKS AS IS.
THERE IS NO WARRANTY EXPRESS OR IMPLIED. USE AT YOUR OWN RISK.
BLAH , BLAH , BLAH
USE THESE FILES TO FEED FCHARTS SE
============================================
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
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
Public Sub load_file()
'=================================
'---------- load file
Dim TextLine, x
CommonDialog1.Filter = "TXT Format files|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
DoEvents
Line Input #1, TextLine ' Read line into variable.
DoEvents
List1.AddItem (Trim$(TextLine))
DoEvents
x = x + 1
DoEvents
Text1.Text = Str(x)
DoEvents
' Debug.Print TextLine ' Print to Debug window.
Loop
Close #1 ' Close file.
'==================================
End Sub
Public Sub rfrshr()
DoEvents
'====================================
frmMain.Refresh
DoEvents
Text4.Refresh: DoEvents
DoEvents
List1.Refresh: DoEvents
DoEvents
Text3.Refresh: DoEvents
DoEvents
tickerTXTB.Refresh: DoEvents
DoEvents
frmMain.Refresh: DoEvents
DoEvents
End Sub
Private Sub Command1_Click()
Dim retVal As Long 'our return value
Dim theUrl As String 'the url you want to download
Dim savePath As String 'where you want to save the url
Dim pathExist As Long 'will contain our path exist or not value
Dim startURLstring As String 'where you want to save the url
Dim endURLstring As String 'where you want to save the url
Dim ticker As String
Dim fillDir As Integer
Dim xDirLBL As Integer
Dim goodLD As Integer
Dim badLD As Integer
'=================================
'---------- load file
load_file
'==================================
goodLD = 0
badLD = 0
fillDir = 0
xDirLBL = 4400 ' starting subdirectory
'==================================
For y = 0 To List1.ListCount - 1
rfrshr
x = x + 1
fillDir = fillDir + 1
If fillDir >= 200 Then
fillDir = 0
xDirLBL = xDirLBL + 200
rfrshr
End If
startURLstring = "http://ichart.finance.yahoo.com/table.csv?s="
ticker = List1.List(y)
rfrshr
endURLstring = "&a=03&b=30&c=1980&d=01&e=03&f=2008&g=d&ignore=.csv"
'For x = 0 To 999
rfrshr
theUrl = startURLstring + ticker + endURLstring
rfrshr
' savePath = Text3.Text + Trim$(Str(xDirLBL)) + "\" + Trim$(ticker) + ".csv"
savePath = Text3.Text + Trim$(ticker) + ".csv"
rfrshr
retVal = URLDownloadToFile(0, theUrl, savePath, 0, 0)
rfrshr
'==================================
' show the lines, a debug trick
' remove in final version
'==================================
Text4.Text = ""
DoEvents
Text4.Text = Text4.Text + ticker + vbCrLf
If retVal = 0 Then Text4.Text = Text4.Text + "File was downloaded successfully!" + vbCrLf: goodLD = goodLD + 1
DoEvents
If retVal <> 0 Then Text4.Text = Text4.Text + "There was a error downloading the file.!" + vbCrLf: badLD = badLD + 1
Text4.Text = Text4.Text + "Success " + Str(goodLD) + vbCrLf: rfrshr
Text4.Text = Text4.Text + "Failure " + Str(badLD) + vbCrLf
rfrshr
rfrshr
' If retVal = 0 Then
' Debug.Print "File was downloaded successfully!" ' Print to Debug window.
' MsgBox "File was downloaded successfully!", vbExclamation, " Download Successful"
' Else
' Debug.Print "There was a error downloading the file. Make sure that the url is valid and try again!"
' End If
Next y
End Sub
Private Sub cmdMethod1_Click()
Dim thePath As String
thePath = InputBox("What is the url to download the file?", " File Url", "http://")
'The path has to be converted to Unicode
thePath = StrConv(thePath, vbUnicode)
DoFileDownload thePath
End Sub
Private Sub Command2_Click()
Dim retVal As Long 'our return value
Dim theUrl As String 'the url you want to download
Dim savePath As String 'where you want to save the url
Dim startURLstring As String 'where you want to save the url
Dim endURLstring As String 'where you want to save the url
Dim ticker As String
Dim goodLD As Integer
Dim badLD As Integer
'==================================
' load_file
'==================================
goodLD = 0
badLD = 0
rfrshr
startURLstring = "http://ichart.finance.yahoo.com/table.csv?s="
ticker = Trim$(tickerTXTB.Text)
rfrshr
endURLstring = "&a=03&b=30&c=1980&d=00&e=23&f=2008&g=d&ignore=.csv"
rfrshr
theUrl = startURLstring + ticker + endURLstring
rfrshr
' savePath = Text3.Text + "\" + Trim$(ticker) + ".csv"
savePath = Text3.Text + Trim$(ticker) + ".csv"
Text4.Text = "Starting Download of: " + tickerTXTB.Text
rfrshr
retVal = URLDownloadToFile(0, theUrl, savePath, 0, 0)
rfrshr
'==================================
' show the lines, a debug trick
' remove in final version
'==================================
Text4.Text = ""
DoEvents
Text4.Text = Text4.Text + ticker + vbCrLf
If retVal = 0 Then Text4.Text = Text4.Text + "File was downloaded successfully!" + vbCrLf: goodLD = goodLD + 1
DoEvents
If retVal <> 0 Then Text4.Text = Text4.Text + "There was a error downloading the file.!" + vbCrLf: badLD = badLD + 1
Text4.Text = Text4.Text + "Success " + Str(goodLD) + vbCrLf: rfrshr
Text4.Text = Text4.Text + "Failure " + Str(badLD) + vbCrLf
rfrshr
rfrshr
End Sub
Private Sub Command3_Click()
'---------- load file
Dim TextLine, x
CommonDialog1.Filter = "TXT Format files|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
DoEvents
Line Input #1, TextLine ' Read line into variable.
DoEvents
List1.AddItem (TextLine)
DoEvents
x = x + 1
DoEvents
Text1.Text = Str(x)
DoEvents
' Debug.Print TextLine ' Print to Debug window.
Loop
Close #1 ' Close file.
' RichTextBox1.LoadFile CommonDialog1.FileName, rtfText
' filz = RichTextBox1.Text
frmMain.Caption = CommonDialog1.FileName & " " & Str(Date)
'Label2.Caption = CommonDialog1.FileName
End Sub
Private Sub Command4_Click()
'---------- load file
Dim TextLine, x
CommonDialog1.Filter = "TXT Format files|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
DoEvents
Line Input #1, TextLine ' Read line into variable.
DoEvents
List2.AddItem (TextLine)
DoEvents
x = x + 1
DoEvents
Loop
Close #1 ' Close file.
End Sub
Private Sub cmdMethod2_Click()
Dim retVal As Long 'our return value
Dim theUrl As String 'the url you want to download
Dim savePath As String 'where you want to save the url
Dim pathExist As Long 'will contain our path exist or not value
For x = 0 To 999
DoEvents
theUrl = List1.List(x)
DoEvents
savePath = List2.List(x)
DoEvents
' theUrl = InputBox("What is the url you want to download?", " Url Path?", "http://")
'If theUrl = "" Then Exit Sub
'savePath = InputBox("What is the path and filename to save the url to?", " Path and Filename to save")
'If savePath = "" Then Exit Sub
retVal = URLDownloadToFile(0, theUrl, savePath, 0, 0)
DoEvents
If retVal = 0 Then
Debug.Print "File was downloaded successfully!" ' Print to Debug window.
' MsgBox "File was downloaded successfully!", vbExclamation, " Download Successful"
Else
Debug.Print "There was a error downloading the file. Make sure that the url is valid and try again!"
End If
Next x
End Sub
Monday, February 25, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment