Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Stock Server Anywhere?

Posted on 1999-07-22
Medium Priority
Last Modified: 2010-10-05

Is there a free stock quoting service server out there which I could interface with vb5/6. And if so, can you please provide a source code example of how to retrieve stock quotes from this server?

Question by:BabyFace
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

sharmon earned 800 total points
ID: 1526774
'Here ya go, this works fine and uses Yahoo's stock server
'You need to add the following to your form...
'Microsoft Inet Control
'2 Text boxes one named txtSymbol and the other named
'   txtQuotes
'1 Command button named cmdGetQuotes
'Paste the following code into the form and you're ready
'to go.  Make sure you are connected to the internet and
'enter your Stock Symbol into the first text box, click
'your command button and it should return no problem.
'If you don't like the format of the stock information
'just reformat it to fit your needs.  There is no error
'checking in this code as I don't know what you want to
'use it for, but it will definetly get you what you are
'looking for.

'----------BEGIN CODE HERE-----------------------------
' Get a row from the response string.
Private Function GetRow(response As String) As String
Dim pos As Integer
Dim symbol As String
Dim last_time As String
Dim last_price As String
Dim change_amount As String
Dim change_percent As String

    ' Find the "<tr" starting the row.
    pos = InStr(response, "<tr")
    If pos = 0 Then
        response = ""
        GetRow = ""
        Exit Function
    End If
    response = Mid$(response, pos)

    ' Find the items in this row.
    symbol = GetRowItem(response)
    last_time = GetRowItem(response)
    If InStr(last_time, "No such ticker symbol.") > 0 Then
        GetRow = "No such ticker symbol."
        Exit Function
    End If

    last_price = GetRowItem(response)
    change_amount = GetRowItem(response)
    change_percent = GetRowItem(response)

    GetRow = symbol & ": " & _
        last_time & ", " & _
        last_price & ", " & _
        change_amount & ", " & _
End Function

' Get the next table item from the table.
Private Function GetRowItem(response As String) As String
Dim start_pos As Integer
Dim end_pos As Integer
Dim pos As Integer
Dim count As Integer
Dim ch As String
Dim txt As String

    ' Find the "<td" and "</td" that bracket
    ' the item.
    start_pos = InStr(response, "<td")
    end_pos = InStr(start_pos, response, "</td")

    ' Save characters between these where the
    ' outstanding brackets match.
    count = 1
    For pos = start_pos + 1 To end_pos
        ch = Mid$(response, pos, 1)
        If ch = "<" Then
            count = count + 1
        ElseIf ch = ">" Then
            count = count - 1
            If count = 0 Then txt = txt & ch
        End If
    Next pos

    GetRowItem = txt
    response = Mid$(response, end_pos)
End Function

Private Function ParseResponse(ByVal response As String) As String
Dim start_pos As Integer
Dim end_pos As Integer
Dim i As Integer
Dim quotes As String
Dim new_row As String

    ' Find the table that contains the
    ' interesting information.
    start_pos = InStr(response, "Last Trade")
    If start_pos = 0 Then
        ParseResponse = "Error parsing response."
        Exit Function
    End If
    ' See where the table ends.
    end_pos = InStr(start_pos, response, "</table>")
    response = Mid$(response, start_pos, end_pos - start_pos + Len("</table>"))

    ' Parse the rows from the table.
        new_row = GetRow(response)
        If Len(new_row) = 0 Then Exit Do
        quotes = quotes & new_row & vbCrLf

    ParseResponse = quotes
End Function

Private Sub cmdGetQuotes_Click()
Dim not_first_symbol As Boolean
Dim symbol As String
Dim query_url As String
Dim i As Integer
Dim response As Variant

    MousePointer = vbHourglass
    txtQuotes.Text = ""
        query_url = ""
            symbol = LCase$(Trim$(txtSymbol.Text))
            If Len(symbol) > 0 Then
                If not_first_symbol Then _
                    query_url = query_url & "%2C"
                query_url = query_url & symbol
                not_first_symbol = True
            End If
        query_url = query_url & "&d=v1"
        ' Open the URL.
        response = inetQuotes.OpenURL(query_url)

    ' Parse the response.
    txtQuotes.Text = ParseResponse(CStr(response))

    MousePointer = vbDefault
End Sub

' Cancel any pending commands.
Private Sub Form_Unload(Cancel As Integer)
End Sub


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question