1. Technology

Quick Tips for VB Programmers

Need a fast answer to a specific question? Here's a collection of past answers to Visual Basic programming questions that might have your answer.

Identifying Which Properties Are Dependency Properties
If you're not sure if a WPF property is actually a dependency property, finding the documentation to be sure can be a real time waster. Here's a quick way to do it.

Changing Font Properties in VB.NET
A reader asked how to write the Visual Basic code for a Bold, Underline and Italic checkbox. It should be dead easy, but in VB.NET, they've made it a little harder. (Isn't everything?) It's a fundamental topic.

Fixing the InputBox
A reader asked for help using InputBox to code a loop to input data to a ListBox control. The InputBox is a VB6 holdover function that probably shouldn't be used. Another article that is linked in this one shows why and what to do instead. But this article shows how to use unmanaged code to solve one problem with the InputBox: You can't tell the...

Getting Input and Validating It
A reader asked for help coding a loop to input data to a ListBox control. The problem was that the reader was using the holdover InputBox from VB6. There are better ways and this Quick Tip shows one of them: the Validating Event of a TextBox control.

Predicate Explained
"Predicate" expressions, an integral part of VB.NET 2008 Lamda expressions, are explained in this Quick Tip.

Use a VBA Macro To Change the Background of a Cell
A reader asked how to change the background color of an Excel spreadsheet cell with VBA macro code. The answer involved some techniques that could come in handy for more than just this. This Quick Tip explains it all.

Display a PDF With VB.NET
PDF is an Adobe format for presenting documents. But since Adobe is a competitor to Microsoft, there's uneven support for the format in Microsoft products. You can save Office files as PDF files, but Microsoft doesn't provide any software tools for integrating the format into systems created with VB.NET. But you can do it anyway. This Quick Tip shows you how.

Anonymous Types - What and How
Anonymous types are a quicker way to use objects, but some of the tricks in using them are not obvious. This Quick Tip explains it all.

Object Initializers
VB.NET has a quicker way to initialize data objects. This Quick Tip shows you how to do it with both parameter based constructors and anonymous types.

Events - Program and Handle Your Own Unique Event in VB.NET
Handling events that are made available to you by other objects is easy. Mainly, you just have to select the event in the code window and add some statements to the event subroutine that is automatically created. But what if you want to create your own event? This Quick Tip shows you how.

Write Programs That Run When a File is Added, Changed, or Deleted
The FilesystemWatcher component makes it easy to write programs that run when a file has been added, deleted, or just changed.

Accessing a Secure Web Site Using VBA
A reader asked if VBA could be used to login to a secure web site using HTTPS and SSL. The answer is yes ... and no. This Quick Tip explains what that means.

Use The Registry To Find The Path To A Program In VB.NET
A reader asked for help finding a way to determine the path to installed software. This Quick Tip not only shows how to do that, it can serve as an introduction to working with the Windows registry in general using VB.NET.

Programming Control Arrays in VB.NET
The lack of VB6 Control Array in VB.NET is by far the most popular single topic at About Visual Basic. A lot of programmers remember the convenience of simply dragging and dropping multiple controls onto a form and then addressing them as an array of controls. The topic attracted ideas from programmers for years after the original article that I wrote about it. This article is a summarization of all of the ideas received about the best way to program something similar in VB.NET.

The Equals and ReferenceEquals Methods of the Object Object
The root of the .NET Framework contains six public methods and two of them are used for testing equality: Equals and ReferenceEquals. This article explains how those two work.

The ToString Method
The ToString method is one of the fundamental methods in the root of the entire .NET Framework. That makes it available in every other object. This quick tip shows some of the ways ToString can be used.

The Object Object
The Object object is the root of the entire .NET Framework. That means that the methods and properties of Object are available all the time and in every .NET Framework object because everything inherits from Object. This Quick Tip tells you about it.

Block Level Scope in VB.NET
VB.NET uses what is called block level scope for variable declarations. This article shows what it is, and also explores some dark corners that you might run into when you use it.

Open a Web Document at a Specific Location
A reader asked for help finding a way to open a specific location in an HTML document using the # marker in a URI. (As in file:///C:\webdoc.htm#location). The reader was trying to use Process.Start(). This doesn't work. But WebBrowser.Navigate() does.

The Region Directive in VB.NET
In the very first edition of VB.NET, compiler generated code was kept in a hidden Region section to protect it from being accidentally changed. When Framework 2.0 was released, Microsoft started using partial classes to do the same thing. But the Region directive is still available to programmers to use to make their own code better organized and easier to read. This Quick Tip shows you how to use it, and why.

ErrorProvider - A Visual Control For Windows Forms
The Windows Forms libraries in Visual Basic .NET includes a number of convenient provider components. One of these is the ErrorProvider component that pops up an icon to tell the user that something is wrong when your program is validating user input. This Quick Tip tells you how to use it.

Arrays: The Difference Between Jagged Arrays and Rectangular Arrays
There are two ways that you can declare an array in Visual Basic. You can declare it as a multidimensional rectangular array or a jagged array. There are some very important differences and this Quick Tip explains what they are.

How a VB.NET Structure Is Different From a Multidimensional Array
A structure and a multidimensional array have a lot in common in Visual Basic .NET programming. Often, you can use either one and your program will work just as well either way. But there are some clear differences. This Quick Tip helps you understand both of them so you can manage information inside a program better.

Friend and Protected Friend in VB.NET
Visual Basic .NET is completely OOP (Object Oriented Programming) because it supports inheritance, the major thing that previous versions of Visual Basic did not support. And because it supports inheritance, it also has two new access modifiers: Friend and Protected Friend. This Quick Tip introduces them to you.

Using Shared Access in Visual Basic .NET
When you instantiate, that is, "make a copy," of an object in VB.NET, it usually means that the members in the instance are unique from any other copies. But some members can also be Shared. This Quick Tip shows you what that means.

The SOOPercharged VB.NET sender and e Parameters
The sender and e parameters passed by the system to standard VB.NET event subroutines are key elements in your programming toolkit. It's all part of the new sOOPercharged VB.NET. This Quick Tip explains how to use them.

VB.NET and Recursion
Recursion is a valuable programming technique and when a programming problem requires this technique, nothing else quite works. But there is a hidden trap in recursion that you need to know about: It can eat memory resources like nothing else. This Quick Tip explains it.

VB.NET's Logical Operators AndAlso and OrElse
VB.NET features two logical operators "AndAlso" and "OrElse" that weren't in previous versions. They do a lot more than the old "And" and "Or". This Quick Tip shows you what they can do.

The VB.NET Imports Statement
The actual effect of the Imports statement in VB.NET is often a source of confusion for people learning the language. And the interaction with VB.NET References makes for even more confusion. This Quick Tips article clears it up.

NaN, Infinity, and Divide by Zero in VB.NET
There are some unique and unexpected ways that the "divide by zero" problem is handled in VB.NET. This article explores what they are and how the NaN (Not a Number) and Infinity VB.NET constants should be coded.

Declaring Variables in Visual Basic .NET
Visual Basic .NET encourages you to be very explicit in declaring variables. In fact, 'Option Explicit' is the default in VB.NET. Complex variable declarations are possible and declarations do what you expect them to. Read this Quick Tip to understand more about how to declare variables.

Understanding VB Logical Operators Work Bitwise
The VB logical operators AND, OR, NOT, and Xor do something interesting when they're evaluated 'bitwise' in VB.NET with a Boolean and an Integer. This article uses Xor to illustrate exactly what happens and why. It's a great exercise that will ensure that you understand exactly how they work.

Use CreateShortcut in VBScript to Manage Your Desktop
A really fast Quick Tip about a very useful object that you can use in VBScript - Visual Basic Script - to manage your desktop; the CreateShortcut object.

Debugging in VB.NET usually means using the Debug icons to single-step your program and maybe a few breakpoints. But there are a lot of little known things about debugging. This quick tip shows just a few of the more useful ones.

Setting Tabs in VB.NET and VB6 Forms Components
An About Visual Basic reader asked: How can I align colums in a ListBox. VB6 doesn't provide a convenient way. You can do it in VB.NET but VB6 requires API calls. This article shows both ways, and it also shows you how to call the API.

Convert Text to Number in Excel
The advice on the web that tells you how to convert text to numbers in Excel doesn't work. The advice here does. Tested in Excel 2003 and Excel 2007.

Selecting the Components Used in the VB6 Package and Deployment Wizard (VB6)
Selecting the Components Used in the VB6 Package and Deployment Wizard (VB6)

Send and Receive EMail using Visual Basic
An About Visual Basic reader asked: How do I use Visual Basic to send and receive email?? A question and answer from About Visual Basic.

Using the Package and Deployment Wizard (VB6)
An About Visual Basic reader asked: How do I use the Packaging and Deployment Wizard to create files and folders when the user installs my application? A question and answer from About Visual Basic.

Processing a Web Page in Visual Basic
An About Visual Basic reader asked: How do I use Visual Basic to access the HTML code of a website? A question and answer from About Visual Basic.

DataTips in VB.NET 2010
There is so much you can do with the DataTips debugging feature in Visual Basic .NET 2010 that it's almost a subsystem all by itself. This Quick Tip covers this new feature and shows you how to use it.

Ten Tips For Coding Excel VBA Macros
Ten commonsense suggestions to make coding Excel VBA faster and easier. These tips are based on Excel 2010 (but they work in nearly all versions) and many were inspired by the O'Reilly book: Excel 2010 - The Missing Manual by Matthew MacDonald.

Maintain a Simple List Using DataGridView and Serialization
This article shows how to use DataGridView and binary file serialization to maintain a simple list of items in a file in just a few lines of code.

What Should Be In Program Documentation?
The most important elements of program documentation are covered.

What Does "Strongly Typed" Actually Mean?
The description "strongly typed" and "weakly typed" are frequently found in technical articles and Microsoft documentation but are seldom explained. This Quick Tip tells you what they really mean with examples.

Save a Value Between Executions in VBA
If you need to save a value after the program closes in VB.NET, you usually have to save it in a file. But in Office VBA programs, you have another option available: CustomDocumentProperties. This Quick Tip article tells you how to do it.

Dynamically Load Objects From Class Libraries
You can dynamically load a member of a class library to give your program more flexibility. I decided to document this Quick Tip when I discovered that VB and C# seem to require slightly different FullName parameters, and there wasn't any other documentation to be found about it.

Resizing Columns in ListView
There is quite a bit of ability to resize columns in a VB.NET ListView control. Some of it seems to be totally undocumented. Some of it doesn't seem to work at all. This article explains how to do it.

Formatting Controls - Using the Primary Control
Visual Studio has excellent ability to help you format controls on forms. But there are just a few corners that can be confusing, especially when you're trying to format a complicated form. This Quick Tip shines a light in those corners by explaining them.

Formatting Controls - Using the Primary Control
Visual Studio has excellent ability to help you format controls on forms. But there are just a few corners that can be confusing, especially when you're trying to format a complicated form. This Quick Tip shines a light in those corners by explaining them.

The Parse Method
The function of the static method Parse isn't obvious from the name but this Quick Tip tells you what it does and how to use it.

Objects, Parameterized Constructors, Anonymous Types and the With Keyword
The With Keyword, Object Intialization, Anonymous Types and Parameterized Constructors are all covered well at Microsoft. But they don't cover the way that all of these techniques interact. About Visual Basic does in the Quick Tip.

Public Class Variables Versus Class Properties
A property of an object can be coded in the class that defines the object as either a Property or a Public variable in the class. This Quick Tip tells you when to do which one. If your New constructor isn't working and you can't figure out why, this tip also documents a bug that might explain the problem.

The VB.NET Solution and Project Files sln and vbproj
The VB.NET Solution and Project Files sln and vbproj

Coding a Default Property for a Class
Coding a Default Property for a Class

How to add an Icon to a ToolStrip control
How to add an Icon to a ToolStrip control

Validating a Numeric String in VB.NET
This Quick Tip shows how to write the code that will guarantee that a string, such as input through a TextBox, is an strictly numeric characters, such as "12345". I needed this to make sure that input from a TextBox didn't contain any spaces or other characters.

A Guide to Drag and Drop
Drag and Drop can be programmed relatively easily in VB.NET, but it doesn't work unless all the components involved work together. This Quick Tip shows how it's done with different scenarios, including using a custom cursor and modifying the object being dragged before it's dropped.

A Guide to Programming AutoComplete
AutoComplete is a convenience that nearly any program that uses data - and that's virtually all of them - can use. For Windows forms, it's built into the ComboBox and TextBox controls. This Quick Tip shows how to write the VB.NET code. Bonus: There's a performance killing way to write the code that should be avoided. We tell you what it is.

A Guide to Programming Validation
Validating data entered into controls is built into .NET and it was part of Visual Basic back in VB6 days. There is a whole family of events and properties that can be used. This Quick Tip introduces you to the Validation family.

AutoScrollOffset, along with a companion method ScrollControlIntoView, are not a part of .NET that programmers are likely to know really well. This Quick Tip looks at how they work and the initial conclusion is: Not very well. If you would like to play with them yourself, the article includes downloadable code to use for your own experimentation.

A Guide to Programming 'Explicit' Validation
Explicit Validation in VB.NET is a concept that is used a lot in Microsoft documentation. But there are no examples and very little explanation of how it's supposed to work. This Quick Tip explains what 'Explicit' validation is.

How to save values in a ListBox control after the Form is closed.
Item values in a ListBox control are lost when the Form they are in is closed. This Quick Tip shows two ways to persist them so the Form can be closed and reopened without losing the values.

Unblock Downloaded Zip Files
Downloaded source code files are normally blocked. That means that a bit tells programs such as Visual Studio that the files have not been authenticated and might contain something dangerous. Usually, this is just an irritation because you actually do know what is in the files. This Quick Tip shows how to unblock the files while unzipping them...

Run Batch Files (DOS Commands) From Visual Studio
The ability to run a batch file (DOS command file) isn't built into Visual Studio. But it's not hard to add it. This Quick Tip explains how.

Is If Then Else or Select Case Better?
These two structures can do the same things. Which one should you use? A Quick Tip that compares them, including StopWatch and ILDASM analysis.

Using VBA to Copy Text into an Office document
Copying Text into Word, Excel, or some other Office document is a common requirement. There are a number of variations to this problem. This Quick Tip shows them to you, including using Notepad to do the job.

Versions of Your Programs
When it was introduced, .NET provided an easy way to mark each version of your program with a "Major, Minor, Build, and Revision" number. But it seems that every good thing gets complicated and that has happened here too. There are three of these numbers now and they can all be different. And there are at least four places where you will see...

ListBox, Dictionary, and ListView Example
A reader asked how to use a dictionary object to reference a list. This answer explores the different dictionaries and the different lists and ends up showing the difference between a ListBox and a ListView control.

A Quick ListView App
A reader asked a question about using the Dictionary object. Like a lot of questions, this seemed to be more a design question than a syntax question. Using ListView is a better solution. This Quick Tip shows how to solve his problem and also illustrates another use of binary serialization (BinaryFormatter).

A Fast Introduction to DataSet in VB.NET
DataSet is a fundamental object in dozens of VB.NET technologies. If you need a really quick introduction to complete some other task, this Quick Tip is designed to do just that.

Using For-Each to Iterate Through a Multidimensional Array of Different Types
Multidimensional arrays have always been obscure, and they're normally not the "today" way to do things. Today we normally use collections or datastores like a database or XML. I ran into an interesting dark corner of multidimensional arrays: It appears that it is now possible to assign different types to the same multidimensional array and even...

The VB.NET Form as a Class
The Form is a special object in VB.NET, but it's still a class. This Quick Tip covers some of the implications of this fact.

MyClass isn't seen nearly as often in code as the more common Me and MyBase keywords. In fact, most programmers may not even be aware how how it's used. This Quick Tip explains MyClass and compares it to Me and MyBase.

The New Constructor and Inheritance
The New constructor is a special method. It's special because it doesn't follow all of the normal rules of VB.NET methods. In particular, it's different when a class is inherited. This Quick Tip shows what that difference i

How to Raise an Event in an Inherited Class
When a class contains an event that you want to raise using the RaiseEvent keyword in an inherited class, you can have a problem. VB.NET doesn't allow you to raise the event directly. This Quick Tip tells you how to do it indirectly.

The Abstract Base Class
VB.NET fully supports what is called an "abstract base class" but there is no abstract keyword in VB.NET. You're just supposed to know what an abstract base class is. (Hint: The keyword is "MustInherit".) This Quick Tip tells you.

Multiple Interfaces
Programmers of the C++ religion believe that something called "multiple inheritance" is the only path to true enlightenment. The rest of us make due with "multiple interfaces". This Quick Tip shows the difference and explains how multiple interfaces work.

Using TimeSpan and DateTime
There are two ways to represent time in VB.NET, DateTime and TimeSpan. They're very different, even though they're companion objects. This Quick Tip reveals how they work.

©2014 About.com. All rights reserved.