Results 1 to 5 of 5

Thread: can you make your vb program retrieve stock quotes?

  1. #1
    Aecaiah
    Guest

    can you make your vb program retrieve stock quotes?

    I want to make a program that will retrieve the stock quote of a company with a click of a button. Can you guys help me with the basic concept??
    Where would the program be able to pull this information from?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    What you could do is find a site that gives free quotes, then use the Inet Control to connect to that URL and get the source from the page. Then its just a matter of parsing the data that you get back to find what you want.

    I would recommend running a quote, and copy the format of the URL, so you know what the format of the URL will be. Then, do a View Source on the page, so you can code where to look more easily.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    This needs six text boxes and a command button (GetRates).
    I used this to get exchange rates in a program i wrote:
    This should go in the General Declarations:
    VB Code:
    1. Dim rateval(1 To 6) As String
    2. Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
    3.     "URLDownloadToFileA" (ByVal pCaller As Long, _
    4.     ByVal szURL As String, _
    5.     ByVal szFileName As String, _
    6.     ByVal dwReserved As Long, _
    7.     ByVal lpfnCB As Long) As Long
    8.  
    9. Public Function DownloadFile(URL As String, _
    10.     LocalFilename As String) As Boolean
    11.  
    12.     Dim lngRetVal As Long
    13.    
    14.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    15.    
    16.     If lngRetVal = 0 Then DownloadFile = True
    17.  
    18. End Function

    VB Code:
    1. Private Sub Form_Load()
    2. MsgBox DownloadFile("The location of thepage with the rates", "where to put file")
    3.     Dim CharFromFile As String * 100
    4.     ratename(1) = "USD/GBP"
    5.     ratename(2) = "CAD/GBP"
    6.     ratename(3) = "EUR/GBP"
    7.     ratename(4) = "FRF/GBP"
    8.     ratename(5) = "DEM/GBP"
    9.     ratename(6) = "JPY/GBP"
    10.     FilePos = 1
    11.     ratenum = 1
    12.     Open "table.txt" For Random As #1 Len = Len(CharFromFile)
    13.     Do
    14.         Get #1, FilePos, CharFromFile
    15.         PageString = PageString + CharFromFile
    16.         FilePos = FilePos + 1
    17.     Loop Until EOF(1)
    18.     Close #1
    19.     Do
    20.         TextPos1 = InStr(1, PageString, ratename(ratenum), 1)
    21.         TextPos2 = InStr(TextPos1, PageString, "class=", 1)
    22.         TextPos3 = InStr(TextPos2, PageString, "</a>&nbsp", 1)
    23.         LenOfNo = TextPos3 - (TextPos2 + 13)
    24.         rateval(ratenum) = Mid(PageString, TextPos2 + 13, LenOfNo)
    25.         ratenum = ratenum + 1
    26.     Loop Until ratenum = 7
    27. End Sub
    28.  
    29. Private Sub GetRates_Click()
    30.  
    31. ShowText1.Text = rateval(1)
    32. ShowText2.Text = rateval(2)
    33. ShowText3.Text = rateval(3)
    34. ShowText4.Text = rateval(4)
    35. ShowText5.Text = rateval(5)
    36. ShowText6.Text = rateval(6)
    37. End Sub
    38. kill "location of the downloaded file"   'deletes the file

  4. #4
    Aecaiah
    Guest
    the problem with pulling it from some website (which is the way i had it before) is that if i do it too often, will they find out?

    im talking about collecting prices for all the companies in the market. So thats over 1000 quotes alredy in one shot..

    maybe i should collect it in time intervals??

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    No matter what the interval, if you are going to hit a server over 1000 times each time, they will be pissed. I would recommend signing up for a service that provides software of their own.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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