Results 1 to 2 of 2

Thread: [resolved] Getting values off the stock market

  1. #1

    Thread Starter
    New Member ChrisChubs's Avatar
    Join Date
    Jun 2004
    Posts
    12

    [resolved] Getting values off the stock market

    Hey, anyone know how to read information off a website?

    Basically i just want to create a VBA function (or VB6 if necessary) that'll get the current stock market value for a given stock code.
    Last edited by ChrisChubs; Jun 23rd, 2004 at 11:31 PM.

  2. #2

    Thread Starter
    New Member ChrisChubs's Avatar
    Join Date
    Jun 2004
    Posts
    12

    Talking

    Thanks for all the replies, you useless buggers
    Figured it out myself - have to use the Microsoft Internet Transfer control.

    VB Code:
    1. Private Function GetStockValue(StockCode As String) As Currency
    2.     ' This gets the value of a stock from the ninemsn website
    3.     On Error GoTo bugger
    4.    
    5.     ' Create the url from the stock code
    6.     Dim StockUrl As String
    7.     StockUrl = "http://investor.ninemsn.com.au/investor/shares/quotes/delayed.asp?cntry=au&code=" & StockCode
    8.    
    9.     ' Grab the webpage
    10.     Dim WebPage As String
    11.     WebPage = INETXFER.OpenURL(StockUrl)
    12.    
    13.     ' Find the part with the price
    14.     Dim i As Long
    15.     i = InStr(WebPage, "lastsale")
    16.     If i = 0 Then GoTo bugger
    17.     i = InStr(i, WebPage, "<tr>")
    18.     If i = 0 Then GoTo bugger
    19.     i = InStr(i, WebPage, "<td") + 1
    20.     If i = 0 Then GoTo bugger
    21.     i = InStr(i, WebPage, "<td")
    22.     If i = 0 Then GoTo bugger
    23.     i = InStr(i, WebPage, ">") + 1
    24.     If i = 0 Then GoTo bugger
    25.    
    26.     ' grab the price
    27.     GetStockValue = CCur(Val(Mid(WebPage, i, 20)))
    28.    
    29.     Exit Function
    30. bugger:
    31.     GetStockValue = 0
    32. End Function

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