Solved

double check my code please?

Posted on 2008-06-23
2
152 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
ID: 21850481
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
ID: 21853278
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

21 Experts available now in Live!

Get 1:1 Help Now