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").
Graphics Fixed in Office VBA Article
Visual Basic and Office - An Update
I've been tracking one of the mistakes that I think Microsoft is making with their VSTO product line for years now. You can check out the blog I wrote about it a year and a half ago right here. Microsoft has repeatedly assured customers that VBA will be in the next version of Office: Office 14. But the big question is, "Will VSTO be there too?" I'm guessing that it will and I'll finally be able to retire the gripe against Microsoft in my previous blog.
As a counterpoint that illustrates what Microsoft should be doing, here's an announcement that was made by one of the biggest companies using VBA in their own products: AutoDesk.
"We will continue to support VBA now and into the foreseeable future in the AutoCAD product line. We are putting together a transition plan to .NET and VSTA and expect to support VBA until our research shows most customers have migrated their code (which could take years.)"
--Eric Stover, Autodesk.
Now, that's a company that understands their customer investment in VBA!
In the latest version of Microsoft InfoPath - a new product to manage forms and information for a large office environment that is considered to be part of the Office family these days - they finally broke the mold. InfoPath uses, not VSTO (Visual Studio Tools for Office), but VSTA (Visual Studio Tools for Applications). VSTA is actually a superset of VSTO and it's the product that Microsoft is now encouraging other companies to include in their software products. And InfoPath does not include VBA as we know it.
For those of us who prefer the productivity and transparent syntax of Visual Basic, VSTA ends the monopoly we've had on Office programming for so long. Any .NET language can be used with VSTA. Ah well ... Microsoft has also announced that their direction is to grow VB and C# closer together over time.
VSTA can be thought of as a mature product these days since it was announced (but not shipped) with Visual Studio 2005. The 2.0 version was released in May of this year. One of the changes in VSTA is something I've been writing about here for quite a while: WPF. WPF is the replacement for Windows Forms going forward. Version 2.0 of VSTA puts the nails in the coffin for Windows Forms in Office.
A top priority for VSTA has been a more graceful migration from VBA to VSTA than we got from VB6 to VB.NET. VSTA has the ability to manage both COM and .NET code. Expect VSTO (if they still keep using that acronym) to allow you to use your running VBA code inside the VSTA environment rather than converting it. AutoDesk has announced that AutoCad 2010 will provide this feature. But ArtinSoft, the company that created the Upgrade Companion for VB6 to VB.NET migration, is already selling migration technology for converting VBA to VSTA if you choose to go that direction.
(Note ... For those of you who receive the About Visual Basic newsletter, a system error prevented the illustrations from uploading correctly to the About.com servers. We're working on it and expect to get the problem corrected soon.)

