personal info | online resume | vb articles | contact
Page Links
  • Recursion
  • String Handling
  • Subclassing
  • Hooks
  • Associations

  • Free "Tutorial-style" Articles
    The goal of my articles are to cover, step by step, some basic (and some advanced) tools that just about all VBers will need from time to time. Each topic covers one subject and provides a generic sample application to assist you in understanding the concepts described.

    If you find any problems with the sample applications or have any suggestions to make them more informative or effective, please let me know. If you have any ideas for other topics, please let me know those as well. Thanks!

    While some would probably debate the "advancedness" of this topic, I certainly think it's one worth covering because it's a tool that should be in every VBers toolbox.
    String Handling
    I never have really looked, but I would imagine that about 90% of all VB programs utilize strings in some way. We store them, check them, build them up, tear them down, slice them, and dice them. Sometimes, we use small ones like If s = "A" Then (do something). Sometimes, we build huge ones like web pages or entire documents built entirely programmatically. Either way, VB rings true in making things as easy for us as possible. If you've ever tried to work with strings or characters in other languages like C++, then you'll know what I mean. There's actually a good bit of work to managing strings internally, and VB/COM takes care of all that for us.

    For our part, we need to understand a little about what's going on under the hood. When we do, we can achieve a great deal of efficiency and speed by just keeping a few short rules in mind. Let's look at a few of those rules and see what we can do to work within them.
    Windows is a world of messages. As you move your mouse around on the screen, messages are being sent to all the applications that lie under the mouse cursor. As you type keys on the keyboard, messages are being sent to the application you're typing into. At any given point in time, there are hundreds, even thousands, of messages flying all over the system. As each application gets messages, it's responsible for handling those messages appropriately. Your VB applications are no different. When the user clicks on one of your buttons, your application gets a button click message. When the user moves one of the forms in your application, your application gets a window move message. You may not have known it, but you've been responding to these messages (albeit, indirectly) ever since you started programming in VB, you just may not have known it. As I've said before, VB is great for hiding some of the complexity of programming Windows applications. In the area of message handling, this is certainly also true.
    You hear a lot about subclassing. Subclassing allows you, as a Visual Basic programmer, to intercept messages that were being sent to your application. If you were interested in a particular message, you could act based on that message and then allow it to continue to be processed normally by Windows. Subclassing allows you to act on some messages that the VB runtime doesn't normally allow you to see. After reading that, hopefully you were opened up to a new world of capabilities you thought previously unreachable by a VB application, and in a sense, you would have been right. In some cases, even subclassing may not be enough. Sometimes, you may need to intercept events before they even reach your application. In some cases, you may want to tap into events that subclassing doesn't catch or that don't even involve your application. To do this, you need to tap into the world of Windows Hooks.
    This article is a little different. We're going to look at a way you can save yourself some time working with the files that we VBers typically work with every day.

    As an example, let's think about text files, those plain old text documents with the txt extension. Open up Windows Explorer and find a text file in folder somewhere. Right click the file and examine the upper part of the context menu that appears. Depending on what's installed on your system, you'll probably see things like Open, Print, etc.. The items that appear in the menu are the things that Windows knows how to do with the type of file you right-clicked on.

    This article has been republished with permission from EZ Programming Weekly. To subscribe, send an email to
    personal info | online resume | project details | vb downloads | contact
    Copyright 2001 by Earl Damron