Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Articles
Recherche: 

Using The WebRequest object to retrieve Yahoo stock quotes
Eric Moreau, March 1, 2004
The WebRequest class is a request/response model for accessing data from the Internet. This class can be used to query any uniform resource identifier (URI). A Web page on a server is probably the most used example.
Summary
The WebRequest class is a request/response model for accessing data from the Internet. This class can be used to query any uniform resource identifier (URI). A Web page on a server is probably the most used example.
Description
The WebRequest class is a request/response model for accessing data from the Internet. This class can be used to query any uniform resource identifier (URI). A Web page on a server is probably the most used example.

The WebResponse class is similar to the WebRequest class. This class is used to receive data from the Internet resource.

These 2 classes are located into the System.Net namespace. Using these 2 classes, we have everything we need to download a complete Web page into a stream. But what I really want to show you is how to retrieve data (stock quotes and currency exchange rate) from the Yahoo web sites.

Note: For those of you who read the February 2004 edition of the UTMag, Tom Bellmer wrote an article that uses XMLHTTP with Visual FoxPro. The approach is different but the results are much the same.

The WebRequest class

Figure 1: The demo application in action

This class is used to establish a communication with a URI. It initiates a communication. We use the Create method that receives a URL as parameter to initialize a WebRequest object. This new object can then be used with the GetResponse method to synchronously download the content and store it into a WebResponse object instance. Asynchronous download is also possible if you use BeginGetResponse and EndGetResponse methods but I won’t use them here.

The WebResponse class

Once that the WebResponse instance has been filled using the GetResponse method (see previous paragraph), you can get its content and fill a stream with it. The easiest way is to fill a StreamReader object using the GetResponseStream method.

Our first method

This first method will be used by most examples of this article to read character contents.

Private Function RequestWebData(ByVal pstrURL As String) As String
    Dim objWReq As WebRequest
    Dim objWResp As WebResponse
    Dim strBuffer As String
    'Contact the website
    objWReq = HttpWebRequest.Create(pstrURL)
    objWResp = objWReq.GetResponse()
    'Read the answer from the Web site and store it into a stream
    Dim objSR As StreamReader
    objSR = New StreamReader(objWResp.GetResponseStream)
    strBuffer = objSR.ReadToEnd
    objSR.Close()

    objWResp.Close()

    Return strBuffer
End Function

As you can see, this method uses the WebRequest and the WebResponse as described above to read the response of a URL passed as argument and returns the response into a string (named strBuffer).

Reading a complete Web Page

Now, using our RequestWebData method, we can read a whole page from a URL and display it within a message box simply by doing:

MessageBox.Show(RequestWebData("http://www.utmag.com"))
If you have a text file somewhere on the Internet, the previous call would only need to be changed to:
MessageBox.Show(RequestWebData("http://www.YourServer.com/YourFile.txt"))
Now that you have the complete page (or a file) in a string, you can do whatever you want with it. But, the best is yet to come. Continue to read!

Retrieving data from Yahoo finance web site

Some web sites are built to also return precise data (using a somewhat different URL) instead of a long page that you would need to parse. Don’t be fooled, we are not talking of WebServices here.

For example, open Internet Explorer and type http://quote.yahoo.com/q?s=msft to see the latest Microsoft quote. Notice the last trade price. Now type http://quote.yahoo.com/d/quotes.csv?s=msft&d=t&f=sl1d1t1c1ohgvj1pp2wern, and you will find much the same information but in a coma-separated string. This comes handy when you want to retrieve data.

As you know, the page layout of the first URL you typed may change from time to time which means that if you built something to parse the page source to find the data in it, your application will probably fail. Since the second URL returns only the data, it is not related to the page layout and your application will continue to run without any problem.

We can use our RequestWebData method to retrieve this data as well as the page source or the text file of the preceding example. It would then be easy to find the second element and return it as the price of the stock we are searching. But what if we passed 2 or more symbols in the URL? I built a simple wrapper around this to transform the comma-separated value string received into a XML string that is much easier to work it. Here is this method:

Public Function GetQuoteLatest(ByVal pstrSymbol As String) As String
    Dim strURL As String
    Dim strBuffer As String
    'Creates the request URL for Yahoo
    strURL = "http://quote.yahoo.com/d/quotes.csv?" & _
             "s=" & pstrSymbol & _
             "&d=t" & _
             "&f=sl1d1t1c1ohgvj1pp2wern"

    strBuffer = RequestWebData(strURL)

    'Loop through the lines returned and transform it to a XML string
    Dim strReturn As New System.Text.StringBuilder
    strReturn.Append("" & Environment.NewLine)
    For Each strLine As String In strBuffer.Split(ControlChars.Lf)
        If strLine.Length > 0 Then
            strReturn.Append(TransformLatestLine(strLine) & Environment.NewLine)
        End If
    Next

    strReturn.Append("" & Environment.NewLine)

    Return strReturn.ToString
End Function
This method receives a symbol and uses the RequestWebData method to get the data of Yahoo. It then loops through all the lines (in case we passed more then one symbol) calling the TransformLatestLineMethod that creates XML data from the string. The TransformLatestLineMethod is simply this:
Private Function TransformLatestLine(ByVal pstrLine As String) As String
    Dim arrLine() As String
    Dim strXML As New System.Text.StringBuilder

    arrLine = pstrLine.Split(","c)

    strXML.Append("")
    strXML.Append("" & arrLine(0).Replace(Chr(34), "") & "")
    strXML.Append("" & arrLine(1) & "")
    strXML.Append("" & arrLine(2).Replace(Chr(34), "") & "")
    strXML.Append("")
    strXML.Append("" & arrLine(4) & "")
    strXML.Append("" & arrLine(5) & "")
    strXML.Append("" & arrLine(6) & "")
    strXML.Append("" & arrLine(7) & "")
    strXML.Append("" & arrLine(8) & "")
    strXML.Append("" & arrLine(9) & "")
    strXML.Append("" & arrLine(10) & "")
    strXML.Append("" & arrLine(11).Replace(Chr(34), "") & "")
    strXML.Append("" & arrLine(12).Replace(Chr(34), "") & "")
    strXML.Append("" & arrLine(13) & "")
    strXML.Append("" & arrLine(14) & "")
    strXML.Append("" & arrLine(15).Replace(Chr(34), "") & "")
    strXML.Append("")
    Return strXML.ToString
End Function

Figure 2: Download data

If you know the URL to pass, you can retrieve any values from Yahoo Web site. The thing is that I didn’t find any clear documentation on that. If you find some, please let me know! The easiest way to find the URL is to copy the URL from the “Download Data” button (see the bottom-right of figure 2) and removing the “&e=.csv” parameter.

Using this very same technique the downloadable demo also includes the retrieval of historical price and also the currency exchange rate.

Retrieving images

When using the WebRequest and the WebResponse classes, we are not limited to text data. Images are also available using this technique.

This is the main method that connects to a URL, retrieves the image and save it:

Private Function RequestWebImage(ByVal pstrURL As String) As String
    Dim objWReq As WebRequest
    Dim objWResp As WebResponse
    Dim strBuffer As String

    'Contact the website
    objWReq = HttpWebRequest.Create(pstrURL)
    objWResp = objWReq.GetResponse()

    'Read the answer from the website and store it into a stream
    Dim objStream As Stream
    objStream = objWResp.GetResponseStream
    Dim inBuf(100000) As Byte
    Dim bytesToRead As Integer = CInt(inBuf.Length)
    Dim bytesRead As Integer = 0
    While bytesToRead > 0
        Dim n As Integer = objStream.Read(inBuf, bytesRead, bytesToRead)
        If n = 0 Then
            Exit While
        End If
        bytesRead += n
        bytesToRead -= n
    End While
    Dim fstr As New FileStream("weather.jpg", FileMode.OpenOrCreate, FileAccess.Write)
    fstr.Write(inBuf, 0, bytesRead)
    objStream.Close()
    fstr.Close()

    objWResp.Close()

    Return "weather.jpg"
End Function
As you can see this new method is not very different from the first. Only the processing of the returned stream changed. This can be used to display the saved image to a picture box like this:
Dim strFile As String
strFile = RequestWebImage("http://image.weather.com/images/sat/canadasat_720x486.jpg")
PictureBox1.Image = Image.FromFile(strFile)

Conclusion

As you can see, retrieving data from a Web site can be easy. Other sites that don’t give you that kind of returned string are much more difficult to handle. In a perfect world, Yahoo would offer a WebService but none is available for now!

I hope you appreciated the topic and see you next month.

Source code

Eric Moreau, Moer Inc.
Eric Moreau is an independent contractor. He holds the Microsoft Certified Solution Developer (MCSD) certification and is also a Visual Developer - Visual Basic MVP. He is mainly programming client/server applications using VB/VB.Net and MS SQL Server (and all the stuff surrounding it) particularly in the financial industry. He works with VB since version 4 and teaches it since version 5. He is a member of the Montreal Visual Studio User Group (www.guvsm.net) where he gives some sessions. He is also a speaker at the DevTeach conferences since its beginning in 2003.
More articles from this author
Eric Moreau, January 1, 2006
Every once in a while, someone is asking in a newsgroup somewhere how he could change the fonts used by the MessageBox, or how he could translate the buttons, or how he could use his own icons, or how he could have the MessageBox disappear after 10 seconds, or how... I think you already know that th...
Eric Moreau, April 1, 2003
We often need to have users use a "folder browser" dialog in our applications. You surely already have used the Win32 ShBrowseForFolder function when building VB6 applications? Guess what, Microsoft Visual Studio .Net team forgot this feature when they built VS.Net 2002! There are at least tw...
Eric Moreau, May 29, 2001
If you need to pass parameters to your application, use the Command function to retreive them.
Eric Moreau, May 13, 2001
Using the SendMessageA API call, you can implement these features into any applications.
Eric Moreau, August 1, 2005
Have you ever think of extending an application already distributed? Have you ever think of distributing some modules or features of your applications only to some users or clients?
Eric Moreau, August 1, 2007
This component is a kind of delegate that let you do operations like settings properties or reacting to events for more then a single GUI element of your form. This way, you can really decouple UI elements from the code.
Eric Moreau, July 9, 2001
Suppose you want a form to perform a task while minimized, then notify the user without a message box and while remaining minimized. You can do this by changing the icon on the minimized form in the taskbar. The same code can also be used for a non-minimized form as well.
Eric Moreau, May 1, 2003
All Windows applications need to persist some data. Here I can think of three different kinds of data. The first kind of data is normally kept into a database. An application has been created to handle that data (customers, invoices, books, authors, …). I won't talk about that kind of data in this a...
Eric Moreau, March 1, 2007
Éric already covered this issue for the Framework 1.1, so this time he doesn't spend any time talking about other ways of storing applications and/or using settings other than what is available in the ConfigurationSettings class. This class was greatly enhanced in .Net 2.0.
Eric Moreau, July 9, 2001
To have your application launch whenever a file with a particular extension is Double-Clicked, you need to register your application with that extension in the Registery (CLASSES_ROOT Hive), here's a short wrapper function I put together and use for this purpose:
Eric Moreau, September 20, 2001
The greatest feature of the Date Time Picker control (available from the Microsoft Windows Common Controls-2 6.0) is that the date value is always a valid date when the control lost the focus. But ... you sometime needs blank dates. By setting the CustomFormat property to a space, you are able to ac...
Eric Moreau, April 28, 2001
It is possible to call a function/sub if the only clue you have of the function is its name stored in a variable.
Eric Moreau, July 7, 2001
Sometimes, you request the user to insert a CD in the drive. You can help the user by already opening the door for him (or her). Using the Windows Multimedia DLL (winmm.dll), you can open and close the CD drive's door from your application. Note that not all the CD drives support these functions.
Eric Moreau, November 1, 2003
The Debug and the Trace classes belong to the System.Diagnostics namespace. These are the two classes you need to know to be able to either Debug or Trace your apps.
Eric Moreau, July 1, 2005
For many months, many of my users, the oldest in particular, were complaining that controls are hardly readable when these same controls are not enabled. Each time I was telling them that I was not able to do much about that since it is a normal behaviour of controls.
Eric Moreau, July 9, 2001
The ComboBox control doesn't have a MaxLength property like the TextBox control does. You can add some code to emulate this property. Notice that you can't code only the KeyPress event. You also need to program the Change event (this event will not allow users to paste longer strings to your control...
Eric Moreau, January 1, 2003
I will author this new monthly column in which I will introduce you to topics mainly related to Windows Forms into the Visual Basic .Net environment (it is quite large to spend many months without rambling). The suggested format is a single topic in about 2 pages long (so that you can read it fast) ...
Eric Moreau, June 1, 2003
Almost all applications need to ask users to open or save a file. You may want to start building your own form to allow it but this feature is directly available from Windows. It is accessible through a single Common Dialog control from VB5/6 or through specialized controls from Visual Studio .Net. ...
Eric Moreau, February 1, 2007
The version 2.0 of the .Net Framework has added built-in compression features namely the DeflateStream class and the GZipStream class. These new features are part of the System.IO.Compression namespace.
Eric Moreau, May 2, 2001
Because menu definition is not code into a form and is not a control on a form, you cannot easily copy a menu from one form (or application) to another.
Eric Moreau, May 13, 2001
Instead of looping through characters to count how many you have, you can use the Split function (if you are using VB6).
Eric Moreau, May 13, 2001
It is sometime required to create DSN from a VB application. It is best to automatically create the DSN than to create it manually.
Eric Moreau, June 6, 2001
Many people find the task of creating ADO connection strings a difficult one. Knowing what provider to use and what options to specify in the string can be difficult. Fortunately, there's an easy shortcut:
Eric Moreau, May 13, 2001
If you want to create a non-rectanguar Form in Visual Basic, you might be surprised to know that it's actually very easy. It can actually be any shape that may be constructed using Win32 region functions. Using the SetWindowRgn Win32 function from within VB is so simple, but the results are unbeliev...
Eric Moreau, May 2, 2001
We can dynamically create an Access database using code and ADOX.
Eric Moreau, December 1, 2004
I’ll show you how to link your VB.Net Windows application to a help file. Before getting to it, I’ll show you, and that’s where all the books and articles normally fall short, how to create these simple help files (that may explain why many programmers never tried to create help files!).
Eric Moreau, March 1, 2003
In this month column, I will show you how to create your own custom controls by extending existing control with new properties, methods or events. For those of you who have created some using VB6, you will soon discover that the process is now more straightforward and that it requires a lot less cod...
Eric Moreau, October 1, 2006
This month, I will take last month demo and add new features to it. I will not explain what was in the previous article. I strongly suggest that you have a quick read if the reading is not fresh to your mind. Please refer to it for sections that may be unclear to you.
Eric Moreau, May 13, 2001
Use the Forms collection to find that.
Eric Moreau, May 4, 2001
Using the Debug object, you can determine in which mode your application is running.
Eric Moreau, May 13, 2001
IsNetworkAlive can be used by applications to determine whether there is network connectivity before proceeding with network operations.
Eric Moreau, May 2, 2001
When you implement your own popup menu for controls, before your popup menu appears to the user, the system popup menu is displayed. You can use at least 2 tips not to see it.
Eric Moreau, May 3, 2001
Beleive it or not you can show child form compiled into a DLL. All you need is a free OCX component (and you can download source code too).
Eric Moreau, July 8, 2001
Have you ever try to shade the form background just like the SETUP.EXE screen? This color shading is called dithering. It is very easy to do it. Actually, the form will be dithered from red to black. It is easy to do it in green RGB(0, 255 - intLoop, 0) or blue RGB(0, 0, 255 - intLoop).
Eric Moreau, February 1, 2004
Drag-and-drop is everywhere. Everywhere but probably not in your own applications! Possibly you are thinking that it is too hard to implement or that no-one uses this kind of feature. But if look how your users are working with other applications, you will find them using drag-and-drop intuitively...
Eric Moreau, February 1, 2008
Have you ever needed to distribute a font with one of your application and got blocked to install it into the Fonts folder? Or do you have a private font that you want to use in your application without having to other to be able to use it elsewhere?
Eric Moreau, October 1, 2004
Have you ever needed an extra property on an existing control? I am sure that this situation occurred many times. To solve your problem, you probably sub-classed existing controls. But what if you need to add this same property to all the controls you are using even those you are not using yet? Wil...
Eric Moreau, July 1, 2007
This month, I will show you how to extend the My namespace with your own methods. As you will soon discover, it is as simple as adding 2 lines to a class that you might already have written. The My namespace can be extended so that your own classes can sit beside My.Application, My.Computer, My.User...
Eric Moreau, September 1, 2006
This column will not show you how to place controls on a report, how to format fields, neither how to distribute reports. The topics have been narrowed to the communication between your current application and the reports you are building. The version that is used here is the version of Crystal Repo...
Eric Moreau, March 1, 2006
I really like to backup my precious data. You can think of my articles, the lines code I put together to create a solution, my e-mails, my contacts, some utilities written by friends, my tax files!
Eric Moreau, September 1, 2003
Remember what MDI means? Multiple document interface. This month column will talk about many topics all related to MDI forms and their children. Some of the topics include the children collection, options normally found under the Window menu, differences between VB.Net 2002 and 2003 (some bugs...
Eric Moreau, May 2, 2001
Do you need to retreive the system date format and the date separator? This is easy with the GetProfileString API call.
Eric Moreau, May 2, 2001
Some API calls to Kernel32 can tell you on which OS your application is running.
Eric Moreau, October 1, 2005
This month, I will show you how you could enable your applications for an offline mode. By offline, I mean that the user is not plugged to the central database. This feature is surely not required by every application and surely not the complete application should be available offline otherwise you ...
Eric Moreau, May 28, 2001
You already have seen in magazines, "undocumented features revealed". Do you know how these guys find these? Simply by showing the Hidden Members (members are Properties, Methods, Events and Constants). These features are hidden for some reasons (obsolete features, not completed features, ...). Usin...
Eric Moreau, April 23, 2001
A free wizard to convert an Access form to VB.
Eric Moreau, September 29, 2001
If you are using the DataGrid control, you may want to highlight a complete row when the user navigate through the grid. The datacontrol does not gives you a property that to this simple thing. You need to program the RowColChange event of the grid and play with bookmarks.
Eric Moreau, April 24, 2001
If you store form name in a database or you simply have the form name in a string variable, you can load it using the Forms collection.
Eric Moreau, May 13, 2001
You can this small code snippet to easily implement a Find/Replace feature into your application.
Eric Moreau, August 1, 2004
Ever need to schedule tasks from your own application. Information on that topic is not easily found. Nothing in pure VB.Net allows you to this. But someone out there figured out how to do it and created a wrapper class to address this task. This wrapper can be freely used in your own applications.
Eric Moreau, April 23, 2001
VB 6 introduced the Data Report. You can still install Crystal Reports (version 4.6.1.0) from the VB6 CD even if it isn't appearing in the installation pages.
Eric Moreau, July 1, 2004
Many methods were used through the years of computing to offer multilingual applications. I have seen text files, databases, binary files and even... hard coding (ouch!). You probably have seen the same techniques and maybe some more. Each of these methods has good and bad marks.
Eric Moreau, September 20, 2001
You may need to have a form child of another parent form without having the parent being set as a MDI main form and child set as a MDIChild form. The SetParent API call allow you to do that. The child form won't be able to exit the parent boundaries.
Eric Moreau, November 1, 2006
This month, Eric talks about two topics related for accessing data using specifically ADO.Net 2.0. He introduces MARS which stands for Multiple Active Result Set allowing to have more then one data reader on a single connection at a specific time. Then, he talks on asynchronous features of ADO.Net 2...
Eric Moreau, April 23, 2001
In VB5, we were having a setting that allow us to maximize all the windows within the VB IDE. This setting has disappear with VB6.
Eric Moreau, April 1, 2008
The latest version (3.0) of the Microsoft Visual Basic Power Packs includes a DataRepeater control. The previous version was containing the Line and Shape controls, the PrintForm component and the Printer Compatibility Library.
Eric Moreau, July 8, 2001
If you try to delete image from an image list control that is bound to a toolbar control, VB will complaint with this message: "ImageList cannot be modified while another control is bound to it". Detaching the toolbar from the image list control will reset all the toolbar button properties which is ...
Eric Moreau, February 1, 2006
If you are like me, you have learned not always to rely on hardware to run your perfectly written applications. Sometimes, and without any reasons, applications just refused to start. I have looked around to find a way to monitor my physically distributed applications. Performance Counters let me mo...
Eric Moreau, February 1, 2005
If you are a regular reader of my column, you know that controls provided -from the box- by Microsoft are somewhat limited. This is also the case of the ComboBox.
Eric Moreau, May 1, 2007
There is a lot of hype around LINQ. LINQ stands for Language Integrated Query. It is surely the biggest feature of the next release of Visual Studio (codename Orcas) that should be released early in 2008. In short, I would say that it offers a uniform approach to querying data wherever it comes from...
Eric Moreau, July 1, 2003
Programmers often need to save the value of properties of classes. The .Net Framework offers an alternate storage solution in cases where a database might not be practical. The serialization is the ability to save object instances to disk and then reload them later. The serialization treats all of a...
Eric Moreau, May 28, 2001
It is easy to play a .wav file to the default audio system using the sndPlaySoundA API call.
Eric Moreau, April 24, 2001
You can use the Access report engine to build your report and print your view/print report from VB.
Eric Moreau, May 3, 2001
You sometimes have operations that have the effect of a flickering form. For example, you parse a grid control. If you do nothing, the user will see the grid scrolls.
Eric Moreau, May 13, 2001
This function enhances the Replace function to allow the replacement of more then 1 character.
Eric Moreau, May 2, 2001
Using these API calls, you can get the Windows folder, the Windows system folder, the Temp folder, a temp file name.
Eric Moreau, May 28, 2001
Have you already tried to round values to discover that the results you get are not what you were waiting for? VB gives you at least 5 functions to round values: CInt, Fix, Int, Round and Format. These 5 functions are rounding values but the algorithm is a bit different for each.
Eric Moreau, May 13, 2001
IF your Stored Procedures only takes input parameters (or no parameter at all), you can completly bypass the Command object and use the Recordset object directly.
Eric Moreau, July 9, 2001
Ever wanted to run an ACCESS procedure or function (or macro) in a module through Visual Basic 6? It is really easy. The procedure needs to be publicly declared (Public Sub RunMe ...). Warning: You need to have Access installed on the PC that will run this.
Eric Moreau, April 1, 2004
Eric has written his own application updater.
Eric Moreau, December 1, 2005
Have you ever wanted to have scrolling text on your forms? You can display many things in this format such as stock quotes, temperatures of major cities around the world, sports scores, news headlines and so on.
Eric Moreau, April 23, 2001
Here is how you can search a combo and position on the first item containing a given string.
Eric Moreau, January 1, 2007
Say you have 2 ComboBox controls on a Windows forms. Those 2 ComboBox are related in a parent-child (or master-detail) relationship. For example, you could have a ComboBox that contains a list of countries for the user to choose from (the parent) and another ComboBox (the child) that contains the li...
Eric Moreau, March 1, 2005
Have you ever needed to change the default printer from an application? VB.Net lets you change the PrinterName property of the PrinterSettings class without a problem but you will very soon discover that the scope of this modification is limited to the current application only!
Eric Moreau, May 2, 2001
Long file names are we used the most today. But you may have a need for short path names.
Eric Moreau, July 8, 2001
Sometimes the data you want to display in a list is too long for the size of ListBox you can use. When this happens, you can use some simple code to display the ListBox entries as ToolTips when the mouse passes over the ListBox. This code requires the use of the SendMessage API call.
Eric Moreau, May 13, 2001
You can force a user/application to logoff, shut down or reboot a computer.
Eric Moreau, August 1, 2006
I will talk about 3 kinds of strings you find in the .Net Framework 2.0. These 3 classes are the String class, the StringBuilder class and the new SecureString class.
Eric Moreau, May 2, 2001
Using the IsDate function, you can test if a year is a leap year or not.
Eric Moreau, May 1, 2004
As you know, the TabControl is useful when you are building screens that have too many fields to display on a single form. The TabControl contains a collection of TabPages. The designer helps you add TabPage to a TabControl and set properties for each TabPage. Each TabPage may contain many control...
Eric Moreau, December 1, 2006
The BackgroundWorker component is a new component of the .Net framework 2.0, but it gives nothing new to programmers that did not already exist in the previous version. This new component provides an easy way to implement multithreading in Windows Forms application. This component helps programmers ...
Eric Moreau, August 1, 2003
The Clipboard is one of the features that existed in VB6 that got completely revamped in .Net. Even the tool that upgrades VB6 code to VB.Net code does not deal with the VB6 Clipboard object. If you try to upgrade such a project, you get "upgrade issues". The .Net Clipboard class is hosted by the...
Eric Moreau, January 1, 2005
It is often very hard for programmers in a culture different then the one used in the US to correctly handle date and time inputs.
Eric Moreau, February 1, 2003
Everyone has ever filled a form on the Web, either a survey, a registration, a taxation report, or maybe your expense report. Many of these page have validators (a mechanism that can validate on the client side if the data entered is valid (before going to server thus saving bandwidth). For years, ...
Eric Moreau, April 1, 2005
This component listens to the file system notifications events of Windows. It can be used in your application to monitor a folder and to receive events when there is any activity in that folder.
Eric Moreau, June 1, 2007
One of the great new feature in Visual Basic 2005 is the My namespace. The My namespace doesn’t bring anything new to the language. It simply offers a clearer path to methods and properties already existing in the .Net Framework. You can see it as a shortcut to quickly access features that are somet...
Eric Moreau, January 1, 2004
The NotifyIcon class lets you add your own application to the System Tray easily. This is located at the bottom right of the screen, just beside the clock. This part of the screen is also called the status notification area in Windows XP and in the MSDN Help. A NotifyIcon control also wraps the feat...
Eric Moreau, December 1, 2003
This month column will cover the Process class that is part of the System.Diagnostics namespace. It allows you to start, stop and query processes on your own PC. It also allows you to query processes on remote computers (as long as they are running Windows platforms).
Eric Moreau, June 1, 2004
The PropertyGrid control can be used to browse, view, and edit properties of one or more objects of your own application. These objects are not required to be controls. They can be class instances too. The PropertyGrid control uses Reflection to inspect your object and to display the properties usin...
Eric Moreau, September 1, 2004
I have seen a lot of programmers putting a StatusBar control to their main form and never using it. Are you one of these? In this column, I’ll show you some nice features (icons, back color setting, buttons, combos, progress bar) you can add to a StatusBar, that are requiring some code (but not that...
Eric Moreau, May 1, 2006
Controls like the ToolStrip (replaces the ToolBar), the StatusStrip (replaces StatusBar), the MenuStrip (replaces the MainMenu), and the ContextMenuStrip (replaces the ContextMenu) are an improvement over their previous versions in Visual Studio 2003. They all have more options and are all working m...
Eric Moreau, June 1, 2006
Microsoft provides great enhancements on the TextBox control. It also reintroduces the MaskedTextbox control into your toolbox. I hear you say: I have been using these controls for the last 10 years, why should I read about these basic controls?
Eric Moreau, November 1, 2004
Almost every application you use daily offers a toolbar providing shortcuts to the mostly used features. This control is relatively easy to use and implement into your own application. I can safely guess that a great number of your applications already have toolbars.
Eric Moreau, April 1, 2006
Almost every application has this kind of data to show and not all programmers are ready to use it. Sure there are many other ways of showing this kind of data but many times, the Treeview control is the one dedicated for the task.
Eric Moreau, July 1, 2006
It seems that the column I wrote for the April 2006 edition of the Level Extreme .Net magazine has generated a lot of enthusiasm. Is there anything else to say about this control? For sure and even after this one you will find plenty of subjects not being fully covered. This month, I will first conv...
Eric Moreau, April 1, 2007
Have you ever needed to include a browsing feature into one of your Windows-based application? For sure you will not want to recreate a complete new web browser. But maybe you wanted to display some HR pages, maybe you just wanted to easily load PDF files, or maybe you want to let your children to o...
Eric Moreau, June 1, 2001
Éric and his 2 daughters Laurence and Justine My name is Éric Moreau. I am living in the Montréal (Québec, Canada) area. I am the father of two marvelous daughters aged of 3 and 5. Since January 1997, I am working for CONCEPT S2i inc. which is a great (not to say the greatest) c...
Eric Moreau, May 13, 2001
You sometime needs to transform a number into a column name.
Eric Moreau, May 13, 2001
Using the Jet driver, it is easy to open and read a CSV file into a ADO recordset object.
Eric Moreau, June 1, 2005
What is the first thing you do when you open an Office application for the first time on a freshly installed PC? I would bet that you say goodbye to your dear friend ClipIt! Am I right?
Eric Moreau, September 1, 2005
My client wanted me to extract some properties of all the forms of a solution that contains more than one assembly so he can see if there were not any typo errors in text of buttons and labels controls, menu items, and even tooltips. I discovered that I could not simply loop through controls of a fo...
Eric Moreau, September 1, 2007
In the era of .Net Framework 1.0 and 1.1, the namespace that developers needed to use to send e-mail from an application was System.Web.Mail. It was confusing for some Windows application developers asking why reference a Web assembly when creating a Windows application. When Microsoft released the ...
Eric Moreau, April 1, 2009
Do you know what is the best way to manage the connection strings? Since the release of the version 2.0 of the .Net Framework, some extensions have been added to the framework to ease this management.
Eric Moreau, October 1, 2003
The registry is that huge repository that store just about anything you want and that you need to open with caution (otherwise your Windows or some applications can refuse to start if you delete invalid hives!). The registry, when used correctly, can be of great help. Much every application needs to...
Eric Moreau, May 1, 2005
Are you, just like me, Googling for any question you have? Every day, I Google for just about anything. Do you know that Google is a verb? Google gives us access to most of their features through a Web Service. This is by far, the easiest way to use it.
Eric Moreau, June 1, 2001
Play a wave file It is easy to play a .wav file to the default audio system using the sndPlaySoundA API call. Private Declare Function sndPlaySound _ Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, _ ByVal uFlags As Long) As Long ' Play synchronously (...
Eric Moreau, July 1, 2001
Rounding values Have you already tried to round values to discover that the results you get are not what you were waiting for? VB gives you at least 5 functions to round values: CInt, Fix, Int, Round and Format. These 5 functions are rounding values but the algorithm is a bit different fo...
Eric Moreau, May 13, 2001
Using the WaitForProcessToEnd function, you can launch an application from VB and wait that it terminates before the application that launch the other continue its execution.
Eric Moreau, November 1, 2005
At the time of writing, the launch of Visual Studio 2005 is scheduled for the week of November 7th (and I hope that Microsoft’s weeks count 7 days like mine). Like many of you, I have installed the betas of Visual Studio (I installed it under Virtual PC to limit damages) to start playing with it, to...
Eric Moreau, April 24, 2001
When you install VB under Windows NT 4 and Windows 2000, you need to have administrator rights. If you log under a different account after the installation, you will not see all the available wizards.
Eric Moreau, April 24, 2001
To find the user name from your VB application, you can use an API call.
Eric Moreau, March 1, 2008
This month, my column will show you how to save time on the creating help files and ensure that users cannot blame you if those files are not updated. Why not let the users create their own help system and maintain it? This is a very good idea that one of my friend (thanks Nicolas) told me lately. A...
Eric Moreau, May 13, 2001
Some forms are merely dialog boxes that show something to the user and sometimes get something in return.