Category Archives: VB

BASIC turns 50

The BASIC programming language turned 50 on Thursday.

This Time article is a great read — and notes the importance of the language on getting school students programming.

What’s the equivalent today? The Raspberry Pi is helping make hardware affordable. Some might dabble in Visual Basic or C# via Visual Studio Express, or the many of the other freely available languages such as Python, PHP, Javascript… or here’s another way of looking at it, from Jeff Atwood:

How to do null dates in database queries in VB.Net

They do make you jump through some hoops, but I think I’ve got it worked out.

Dim dYourDateField As Nullable(Of Date)

…then you either set it to be a date (using DateSerial or CDate or whatever, or you set it to Nothing.

Then when you’re using it in a database query, the parameter can be set like this:

oCmd.Parameters.Add(“@YourDateField”, System.Data.OleDb.OleDbType.DBDate).Value = dYourDateField

That’s it. At least, it seems to work okay for me. Touch wood. Apparently it should be okay in the .Net Framework 2 onwards.

[Another in an occasional series of things Daniel posts about so he can easily re-discover it next time he needs to remember how it’s done.]

Cool XML stuff

A bunch of XML Tools from the good people at Got Dot Net. The particular one I needed was XSD Inference, which creates an XSD from an XML document. I needed it to use with some code to validate XML against XSDs in VB6. It seems XSDs created from XML with some tools (I’m looking at you, XMLSpy — though maybe it’s fixed in later versions) won’t work properly using VB6/XML Parser 4 (which is what I’m using, at least for some of my stuff).

Misc stuff

Cool links I’ve found recently:

Super (MOV to AVI conversion).

VB to Java converter. That is, it compiles VB6 code into a Java class. Latest update here. Q+A. (No, you can’t download it yet, they’re still working on it.)

Oh, guess who’s on about giving away Digital set top boxes again? Yup. I do like this argument, actually: It is not the Government’s job to champion new technology. It is the Government’s job to provide universal infrastructure and manage the task in a financially responsible way.

XML Notepad, which after a looooong time not being available, is back, and upgraded. (Requires the .Net Framework 2).

Calling COM from .Net, and vice versa

I’m working on a project that uses web services code written in .Net (‘cos it’s heaps easier that way) but calls legacy code written in VB6. And vice versa.

(Wow, I never thought I’d be referring to VB6 code as legacy, but there you go. None of your smart comments, any VB-haters out there.)

Here’s what I’ve discovered about making it work. Continue reading

Fun with wildcards and DOS 8.3 filenames

I’ve found under some circumstances, new versions of Windows (XP and 2000, using NTFS) are still looking at the DOS 8.3 versions of filenames when using wildcards.

Real world example: a set of files such as tpo12345.xml tpo12346.xml tpo12347.xml etc. To find these, you’d use a wildcard such as tpo?????.xml

If you have a file called tpo1234567890.xml, it shouldn’t match using this wildcard, but it does, because the filename’s backward-compatible short version (in DOS 8.3 format) is something like TPO123~1.XML, which matches. It appears to only happen when the first part of the wildcard (without the suffix) is 8 characters long.

So it may be ten years since most of us said goodbye to short filenames, but it seems they’re still with us. I wonder if Windows Vista will still use them?

Migrating .Net 1.x to 2.x

Having got Visual Studio 2005 into my hot little hands, I’ve upgraded one of my projects from VS 2003 to 2005, and .Net Framework 1 to 2. Just loading it into VS2005 seemed to do most of the work for me.

I did find the new VS gives out a few very informative warnings in the code editor, such as unused variables. Good stuff (and shame on me for being so sloppy during repeated revisions of code).

The other thing I found was a few things had changed in the Web.Config file format. After much fiddling I found it easier to create a fresh one and copy my custom settings into it, than try and convert the old one over.

The only catch is that after copying it all over to the test server, it didn’t work. Turns out apart from installing the .Net 2.X Framework on your server, you’ll also need to get into the IIS setup and make sure it knows it’s now a 2.X application.

Other than that, pretty smooth. The one gotcha on my actual code was a custom button click routine that took the form QueryString and stripped out all the ASP.Net guff I didn’t want needed a bit of tweaking, as in .Net 2.0 there’s an extra __EVENTVALIDATION value. (My version is adapted from a 15seconds.com article, and is used to produce tidy QueryStrings that can be bookmarked.)

Hiding Excel warnings during automation

Well, I sorted out my problem of confusing warnings appearing whilst controlling Excel with VBA. Turns out there is an Application.DisplayAlerts property which, when set to false, hides warnings such as the one I was getting. It took a little Googling to find the solution, which wasn’t readily apparently in any of the MS help for the methods I’d got the warnings from.

The other Office applications also have a DisplayAlerts property.

Needless Excel automation warnings

Okay, this is annoying. I’m working on a VB program that uses the Excel object library to automate a fairly complex update into Excel. The general idea when you’re automating Excel is to smoothly do your operation behind-the-scenes, to hide the complexity from the user.

Excel warning

So the last thing you need is complicated dialog boxes popping up to ask the user questions. I’m the programmer: I’m meant to make the decisions. Tell me, the programmer, that if I save this Shared Workbook with a password that certain parts of the file won’t be encrypted. Don’t tell my user, and ask them to decide if it should happen or not.

Microsoft 2005 dev tool betas

To those who watch Microsoft’s dev tools, there are betas of the 2005 versions now available. MSDN subscribers can download full products straight away; others can order CDs, or stick to the Express products, which for trying out new languages, are quite nicely featured.

It’s a cunning strategy for Microsoft, helping to counter the proliferation of free programming languages such as Java and PHP by providing free development environments for ASP, VB, C#, C++ and their own (some would say mutated) J# implementation of Java.

MSDE, which has been around for years now, providing a royalty-free cut-down SQL Server, has been renamed SQL Server Express to show its heritage. (Well, its SQL Server heritage… most people know it grew out of Sybase, but that’s ancient history). Keeping it free thus helps fight off the MySql threat and allowing people for whom Access isn’t cutting it to be encouraged up to SQL Server).

Looking back 20 years to when I was growing up, trying out BASIC on my Commodore 64 or BBC Micro, I ponder how the next generation of programmers are getting hooked into this game. I suspect a mix of freebie entry-level products like this (and their counterparts from the world of open-source) is one way they can get involved. Which probably explains MS’s “Coding 4 Fun” web site.