Avoiding descriptor in binary data

JapanFreak

Registered User.
Local time
Today, 19:39
Joined
Aug 25, 2007
Messages
45
Hi there,

I have a question with regards to printing binary data in a txt file. The code below retrieves historical stock price data from Yahoo. This works fine so far. However, at the beginning of the txt file there are always some weird symbols (e.g. "  ¿M"), which are not part of the array occArray (which contains the data from the website).
In the meantime I have learnt that when you use "Put" to print binary data from a dynamic data field to a file a descriptor will be printed first. I assume that this produces the weird symbols. Is there any possibility to avoid this?

Best regards
JapanFreak

Code:
Option Explicit
 
Sub DownloadYahooData()
    Dim vTicker(3) As Variant
    Dim SD As Integer, SM As Integer, SY As Integer, SY_2 As Integer     
    Dim i As Integer
    Dim occURL As String
    Dim occArray As Variant
    Dim sFileName As String
    Dim occXMLHTTP: Set occXMLHTTP = CreateObject("Microsoft.XMLHTTP")
 
    'Ticker einlesen
    vTicker(1) = "INTC" 'Intel
    vTicker(2) = "XOM"  'Exxon Mobil
    vTicker(3) = "JNJ"  'Johnson & Johnson
 
    'Datum einlesen
    SD = Day(Now)
    SM = Month(Now)
    SY = Year(Now) - 1
    SY_2 = Year(Now)
 
    For i = 1 To UBound(vTicker)
        occURL = "http://ichart.finance.yahoo.com/table.csv?s=" & vTicker(i) & _
                    "&d=" & SM & "&e=" & SD & "&f=" & SY_2 & "&g=d&a=" & SM & _
                    "&b=" & SD & "&c=" & SY
 
        occXMLHTTP.Open "GET", occURL, False
        occXMLHTTP.send
        occArray = occXMLHTTP.ResponseBody
 
        sFileName = ThisWorkbook.Path & "\TimeSeriesData\" & vTicker(i) & ".txt"
 
        Open sFileName For Binary As #1
        Put #1, , occArray
        Close #1
   Next iEnd
Sub
 
I don't have a direct answer to your question, but I am curious why you're even using "Put" to save the text file?

occXMLHTTP.ResponseBody should be XML.
If so, I think you can just save the file with:
ResponseBody.Save (sFileName)
 

Users who are viewing this thread

Back
Top Bottom