Click here to Skip to main content
15,893,622 members
Articles / Programming Languages / Visual Basic

WebResourceProvider VB.NET style

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
30 Aug 20023 min read 82.6K   263   24  
Ravi Bhavnani's WebResourceProvider ported to the .NET Framework
Public Class QuoteProvider

    ' QuoteProvider.vb
    '
    ' Written by Marcel Spring, ADVIS AG, Switzerland <marcel.spring@advis.ch>
    ' Copyright (c) 2002.  All Rights Reserved.
    '
    ' code adapted from original c++ library from
    ' Ravi Bhavnani <ravib@ravib.com>
    ' http:'www.codeproject.com/internet/WebResourceProvider.asp.
    ' Copyright (c) 2002.  All Rights Reserved.
    '
    ' This code may be used in compiled form in any way you desire. This
    ' file may be redistributed unmodified by any means PROVIDING it is 
    ' not sold for profit without the author's written consent, and 
    ' providing that this notice and the author's name and all copyright 
    ' notices remains intact. 
    '
    ' An email letting us know how you are using it would be nice as well. 
    '
    ' This code is provided "as is" with no expressed or implied warranty.
    ' The author accepts no liability for any damage/loss of business that
    ' this product may cause.
    '
    '
    ' Revision history:
    '
    ' 06 Jun 2002 - Initial release
    '------------------------------------------------------------------------------------------

    Inherits WebResourceProvider

    '==========================================================================================
    'Private stuff 
    '==========================================================================================

    '------------------------------------------------------------------------------------------
    Private mySymbol As String = ""
    Private myQuote As String


    '==========================================================================================
    'Public stuff 
    '==========================================================================================

    '------------------------------------------------------------------------------------------
    Public Property Symbol() As String
        Get
            Return mySymbol
        End Get
        Set(ByVal Value As String)
            mySymbol = Value
        End Set
    End Property

    Public ReadOnly Property Quote() As String
        Get
            If mySymbol <> "" Then
                Try
                    Me.FetchResource()
                Catch ex As Exception
                    Throw New System.Exception("Error fetching quote from Yahoo", ex)
                End Try
                If myQuote = "" Then
                    myQuote = "not found!"
                End If
                Return myQuote
            End If
        End Get
    End Property


    '==========================================================================================
    'Overriden methods from base class
    '==========================================================================================

    '------------------------------------------------------------------------------------------
    Overrides Sub ConstructUrl(ByRef myURL As String)
        Me.URL = [String].Format("http://finance.yahoo.com/q?h=1&s={0}&d=t", mySymbol)
    End Sub

    '------------------------------------------------------------------------------------------
    Overrides Sub ParseContent()
        myQuote = ""

        'get the quote
        If Not skipTo("Last Trade") Then
            Return
        End If
        If Not skipTo("<b>") Then
            Return
        End If
        If Not extractToExact("</b>", myQuote) Then
            Return
        End If

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions