Solved

double check my code please?

Posted on 2008-06-23
2
151 Views
Last Modified: 2010-04-23
3rd part of my stock quote question...just want to make sure this looks clean to a trained eyeball... :^)
Imports System.IO

Imports System.Net
 

Public Class frmMain

    WithEvents tmr As New Timer

    Const strURL As String = "stocksite"
 

    Private Sub frmMain_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        Me.Size = New Size(90, 20)

        Me.BackColor = Color.FromArgb(37, 95, 220)

        Me.Location = New Point(0, Screen.PrimaryScreen.Bounds.Height - Me.Height)

        lnkQuote.BackColor = Me.BackColor

    End Sub
 

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        tmr.Interval = 600000

        tmr.Enabled = True

        tmr.Start()

        UpdateQuote()

    End Sub
 

    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick

        UpdateQuote()

    End Sub
 

    Sub UpdateQuote()

        Dim client As WebClient = New WebClient

        client.Proxy = New WebProxy("myproxy", True)

        client.Proxy.Credentials = CredentialCache.DefaultCredentials

        Dim data() As Byte = client.DownloadData(strURL)

        Dim strData As String = System.Text.Encoding.ASCII.GetString(data)
 

        'Function to parse strData and get the quote information...
 

        lnkQuote.Text = strQuote
 

        If strChange.Substring(0, 1) = "+" Then lblChg.ForeColor = Color.Lime

        If strChange.Substring(0, 1) = "-" Then lblChg.ForeColor = Color.Red

        lblChg.Text = strChange

    End Sub

End Class

Open in new window

0
Comment
Question by:sirbounty
2 Comments
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Only thing I was thinking was to add a try/catch block when downloading the page...
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 total points
Comment Utility
Hi sirbounty!

Looks good to me. Maybe specify the parameters when setting the proxy, so it doesn't confuse True for the port number (-1). It probably won't (haven't tested it), but better to be safe than sorry....

    client.Proxy = New WebProxy(Address:="myproxy", BypassOnLocal:=True)

Wayne
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now