Hungarian Notation Revisted
This may be a pretty obvious idea, but it hadn't occurred to me before.
W-a-a-a-y back in 2005, I wrote a blog, Hungarian Notation - Good Idea?, in which I noted that Microsoft wasn't consistently recommending a naming style called Hungarian notation anymore. In brief, Hungarian notation names variables according to their type. "txt" would be a text variable; "dbl" would be double and so forth.
If you go back through the examples I code in the articles here, you will see that I have never had a consistent naming sytle. Quite frankly, I name 'em according to the mood I'm in at the moment. I usually use a descriptive name based on camel case: theFirstVar, theSecondVar, and so forth. (In my first programming job with IBM, many many years ago, I can remember using variable names based on variations of the name of the love of my life. That was a good lesson in what not to do. Maintaining the code later was not only embarrasing, it was really confusing.)
That old blog has consistently attracted a comment every now and then over the years and just yesterday, "Matt" left this comment:
"If I'm looking for a textbox and can't immediately remember exactly what I named it, I can type "txt" and Intellisense shows me everything beginning with "txt" and I can find the textbox I'm looking for without having to return to the designer. If the textbox were named "DisplayNameTextbox" and I thought I named it "NameTextbox", then I would have no easy way of finding it with Intellisense and would waste my time in the "N" section.
Good point! Check the graphic above to see how that works.
But the original reason for Hungarian notation was to avoid type conversion errors. Since VB6 declared everything as a "Variant" type, inefficient code and sometimes nasty bugs could be created by thinking you were working with a string when it was actually an integer. VB.NET doesn't have this problem since it features "strong typing". (Although, we're starting to get close to what we had in VB6. I can use "Option Explicit Off" and then simply code myVar = "ABC" with no variable declaration at all.)

It seems to me that, since avoiding type conversion problems is no longer a motivator, you might be better off simply using this idea to group your variables according to some requirement specific to your system. For example, you might have two GDI+ Graphics objects in the same program and you need to make sure that you keep the objects, such as Color, organized.
Fixing the InputBox
In The Trouble With InputBox, I pointed out that InputBox wasn't really a very good way to input data to a ListBox and I pointed out that it also had a fatal flaw - there wasn't any way to tell the difference between blank input and the Cancel button.
It turns out that this isn't quite true ... About Visual Basic reader "SmetsRoger" pointed out that his whole night school class had worked on this problem and had discovered a solution. I checked it out and, yes, the solution does work ... for now. But I wouldn't use it. The reason it works now and why I still wouldn't use it is a fascinating investigation that you can read about in a followup article, Fixing the InputBox.
Thanks much to SmetsRoger for sending this one in! It was fun!
The Trouble With InputBox
A reader asked for help coding a loop to input data to a ListBox control. The problem was that the reader was using an ancient holdover from VB6 that still happens to be available in VB.NET ... for backward compatibility. There are better ways and this Quick Tip shows one of them: the Validating Event of a TextBox control. This Quick Tip shows the difference.
It's Good to Share!
VB.NET Shared and Instance Members
Old programmer joke:
There are 10 kinds of programmers. Those who understand binary and those who don't.
There are also 10 kinds of Class members: Shared and Instance.
I was looking for information about this and I found my own article! It answered my questions! But it was a couple of years old so I updated and republished it. Click here to see the result.
A Different Program
In my "other" life, I'm a writer. I was recently thinking about books that have been bypassed by the march of time such as 1984 and 2001: A Space Odyssey. When they were written, their dates were far into the future. Now, they're artifacts of history. The idea of using Visual Basic to write an "eternal" story that would always be current came to me, so I did it. In addition to the VB code, how do you like the story?
If you're interested in calling Microsoft Word from VB.NET, both to display the updated text of the story and for date and time calculations, this program might be of interest to you. In addition, the interface is WPF (Windows Presentation Foundation) rather than Windows Forms based. It's also written using VB.NET 2008 Express Edition.
Read the "Eternal Story" here!
If you're more interested in the programming, Click Here to see how the code works.
Win7 and VB ... A Report from the Front Line
Anybody above ground knows that Windows 7 is out now. "SpiritualMadMan" sent in this report from the field and I thought I'd share it ...
I am running Windows 7 Ultimate 64 on an HP DV6609wm and I installed Visual Studio 6 and initially had problems.
However, ignoring Microsoft's dire warnings of incompatibilities I plunged ahead.
Yes, I had problems...
But, the fix was extremely easy.
Navigate through the Folders and Right-Click on the VB6 executable. Under Properties - Compatibility set options for all Users (Checkbox at Bottom) to WindowsXP SP3 Mode and Run as Administrator.
Also, a Note about unsigned drivers... I had been Using FreeOTFE (On The Fly Encryption). However the Installation broke because the Encryption Drivers are all "unsigned".
However, installing VirtualPC allowed me to install FreeOTFE there and recover my Encrypted data. The ease with which I could transfer files between the Virtual Machine and the Win7 was also way much better than VirtualPC 2004.
What's a Programmer To Do?
A reader recently sent some emails asking about one of my articles, Application Settings in VB.NET 2008. To answer the question, I read the article with fresh eyes and decided two things:
- It needs some work! (Click here to read the new article.) Every writer should be forced to review his own work.
- Microsoft has some work to do in Applications Settings architecture too.
I've read everything I can find about it and it seems to me that it just doesn't do what they say it does. In fact, I can find half a dozen message threads in forums between Microsoft forum watchers (MSFW) and programmers with problems (PWP) that read something like this.
PWP: This doesn't work.
MSFW: Yes it does. Do this.
PWP: No, it doesn't. I tried what you said and it doesn't work.
MSFW: Do this and it works.
< ... End of thread - I assume PWP got tired of talking to a wall and went away. ... >
Oooo! That's frustrating! Past experience reporting these kinds of problems through official channels to Microsoft has generally resulted in them saying something like, "The software works as designed." (In other words, "I've got a secret and I won't tell - I won't tell - I won't tell!")
In an effort to at least not repeat the same error, I've rewritten the article to both clarify what I do understand and clearly state what I don't understand (and suspect that Microsoft needs to rework). Read the article and if you can explain something, let me know and I will tell. And if you have experienced bugs trying to use application settings, let us know that too. There's a survey at the end of the article.
LINQ Queries - An Example Driven Introduction
LINQ - Language Integrated Query - is the reason a whole host of new technolgies were introduced in VB.NET 2008. For example, Lamda expressions and partial methods. Another technology that was introduced with LINQ is the LINQ query ... a faster and more direct way to write LINQ query expressions. This article explains it.
It would also be interesting to find out whether you find the "traditional" dot notation (object.method) or the new SQL-style query in LINQ easier to understand and use. Add your response at the end of the article.
VBA to Shade an Excel Spreadsheet Cell
A reader in the forum asked how to shade a spreadsheet cell. The answer involved three techniques that could be useful in a lot of other cases, so I wrote a Quick Tip to explain what they are:
Use a VBA Macro To Change the Background of a Cell.
What's the difference between a control and a component?
These two terms are often used interchangeably in articles that you might see. Here's an example from Wikipedia:
"ASP.NET supports creating reusable components through the creation of User controls."
Which is it? A control or a component. I can't tell.
Here's my definition. A "component" is a generic term that means just what the dictionary says it means: "a part of something". It doesn't really have a technical definition. A "control", however, is a specific thing, but most sites define it the way it was in VB6, that is an "ActiveX Control". VB.NET can use those controls by wrapping them in managed code (ActiveX Controls are called "COM Components" in the Visual Studio tooltip displayed for them.), but VB.NET also has controls that are .NET managed classes. VB.NET is a little more consistent in that usually when something is called a "component" it means that it doesn't have a user interface. Everything in the Components tab (like Timer) is only visible at the bottom of the design window in Visual Studio (an area called the "component tray").

