Author Archives: admin

Visual Basic 6 and Resource Files

0
Filed under Resource Files, Utilities, VB Feng Shui

Feng Shui is all about the placement of things to better harmonize with their (and consequently your) surroundings.

With VB, there’s no better place to examine that than the file footprint of your application.

Ask yourself: You have two apps to evaluate. They perform identically, are configurable in all the same ways and behave exactly the same. One app consists of hundreds of files scattered across dozens of folders. The other’s footprint is exactly one file, the EXE itself. Which would you choose?

Granted, that’s an extreme case, but the point is, the smaller your app footprint, the better, in almost all circumstances.

And a really nice way to shrink an app footprint is with resources.

If you’ve never messed around with resource files in VB6, or maybe only tried to use the built in resource editor add-in, you really don’t know what you’re missing.

Resources can be an immensely handy way to embed everything from pictures to WAV files, to chunks of script, to icons, and just about anything else directly into your application, but in a way that makes them accessible to the outside world, for one-off customizations, translations, or to just keep the file footprint of your app as small as possible.

However, resource files can be notoriously difficult to work with because of the lack of tools available natively with VB6. VB.NET dramatically improves upon the situation, but there’s still a lot of VB6 code out there that might benefit from resources.

Generally speaking, you have two “types” of resource files where VB6 is concerned.

  • the resource file the can be “included” in the project and is available to your code while you’re running in the IDE
  • Any resources “added” to your applications EXE/DLL/OCX file AFTER you compile it.

Why the distinction?

There’s one specific kind of resource that you very much should want to include in your compiled file, but which VB is notoriously lacking about. The Version Info Resource.

VB only allows you to specify the Major, Minor, and Build version numbers (although VB calls the Build number, the “revision” number, mysteriously).
Windows executables, on the other hand, support a Major, Minor, Revision, and Build.

Now, the truth is, VBs support is generally fine for utilities, hobbiest programs and the like. But real, commercial applications really should make use of all four numbers, and that’s something that is impossible using VB alone.

Ah, you say, VB does have that “Resource Editor” add-in, just use it! Not quite. You can’t create a version info resource in it, and even if you could, VB’s compiler replaces any version info element within that resource file with the information from the project properties window.

The solution is relatively simple and still preserves all the great things that resource files in VB can do for you.

The IN-THE-IDE Resource file

For this resource file, you have 2 choices, use the VB Resource Editor Add-In, or create an RC resource script file, and compile it to a RES binary format file that VB expects. I prefer the later, simply because scripting the resource file makes it much easier to include things like big chunks of text (xml, scripts, icons, what-have-you), and you can leave all of those things external to the RES file without having to manually pull them in via the Editor add-in every time they change.

I usually create an RC file with the same name as the VBP file, but with an RC extension

test.RC

// Test Resource Compiler file
// used to automatically compile the RC file into a RES file
// BEFORE the project itself is compiled
// This makes the Resource data available to code while in the IDE
//
//-----------------------------------------------------------------------------------
// Arbitrary Text File Resources
//
//----------------------------------------------------------------------
TEXTRES1   TEXTRES_DEFS PRELOAD DISCARDABLE TextRes1.txt
TEXTRES2  TEXTRES_DEFS PRELOAD DISCARDABLE TextRes2.txt

//-----------------------------------------------------------------------------------
// Bitmap Resources
//-----------------------------------------------------------------------------------
IMG_MAIN  BITMAP PRELOAD  DISCARDABLE ".\test.bmp"

Note that test.bmp is just some random bitmap file, and that TextRes1.txt and TextRes2.txt are arbitrary text files.

Then, you can access those resources via a little bit of VB code

To get the text file resources

Dim a() As Byte
dim buf$
a() = LoadResData("TEXTRES1", "TEXTRES_DEFS")
buf$ = StrConv(a, vbUnicode) 'need to convert the raw ansi text file content to UNICODE to make VB happy

Or to load the bitmap

Set form.Picture = LoadResPicture("IMG_MAIN", vbResBitmap)

Icons, and string tables are a little more difficult, esp. with respect to XP and VISTA format icons, so I’ll worry about them later.

You can compile the RC file using a command line similiar to the following:

rc.exe /r /fo "test.res" "test.rc"

Make sure the RC.EXE resource compiler is on your path for it to run right. The RC.EXE file itself should be somewhere in the VB6 installation folder under Program Files. For a muhc more thorough explanation of the Resource Compiler, check here. Microsoft has some very good RC information here also.

Alternatively, you can put this command in a BAT file, and execute it quietly:

cmd /Q /c rc.ex /r /fo "test.res" "test.rc"

One caveat. If you decide to use the RC file, be aware that VB loads the compiled RES file when you load the project. So if you make a change to one of the component resource files (say, an ICO or BMP file), you’ll need to exit VB, recompile the RC file to a RES file, and then RELOAD the project in VB. Since RES files don’t change all that much once initially created, this isn’t a huge problem.

Another note: You can only include one resource file in a single VBP project, so it has to contain all the resources the app will need (except, of course, for the Version Info Resource).

And a final note: You can easily add a resource file to a project by
1) compiling the RC file to a RES file
2) Opening your VBP project
3) dragging the RES file from Explorer to the VB Project Window.

For next time, handling the Version Info Resource….

Let’s get ready to Roomba

0
Filed under Roomba

I recently picked up one of these little guys after reading what seemed like nothing but 100% good press about them, and a good friend (and a bit of a hacker) saying they worked surprisingly well.

I’d thought about it for some time but always felt like they’d probably not work all that great.

I put a few RSS feeds up on CraigsList and eventually got a hit for an SE for 100$

We’ve had it now for about 2 months, and, well, it’s a bit like Star Wars Episode III. You really wanted it to be good. Hoped for a miracle to wrap things up nicely, but knew deep down, it just wasn’t going to be.

First off, they call it a robotic vacuum, but hold your hand up to the exhaust port and you don’t feel much exhaust. More like what gets blown by one of those cigarette lighter fan things you see in old delivery vans. A robotic sweeper would be more apropos.

The dust bin is also rather small, so it won’t do much cleaning before you end up doing some cleaning. And speaking of cleaning, I’ve never, ever had to brush out the brush in my real vacuum, nor have I ever had to use a pick to untangle hair from around the sweeper axle so it would turn properly. Any more maintenance than changing a bag out every 2-3 months and winding the cord up when I’m done with it is just too much maintenance for a dang vacuum (and some new ones wind the cord for you!).

Further, I’ve got the yellow high capacity battery, but I get a run time of about 30 minutes or less, not even enough to do a room decently. Maybe the battery’s shot, maybe not. Do I really want to pop 50$+ just to find out?

No, even though the SE model is the “third generation” Roomba, this is clear Gen One stuff.

In my mind, a robotic vacuum should:

  • Be about the same size and shape as the Roomba. That I like. Maybe a bit bigger to handle the rest.
  • Have a much bigger bin.
  • Have a more powerful vacuum.
  • Be a tad smarter about where it’s been and where it needs to go.
  • Be able to run for at least 3-4 hours. Long enough to clean, say, 1000-1500 sqft.
  • And of course, it should have built in WIFI!

That said, iRobot may get there eventually. Roombas have been a surprise seller for them, so that bodes well.

In the meantime, there’s that nifty serial port to play with!

Zip Library

0
Filed under ActiveX

I know, there’s a ton of zip libraries out there. And some are actually free, though, typically, those come with some pretty onerous licensing if you intend to use it in a commercial product.

.NET has some built in zip support I believe, but if you’re still playing in ActiveX land, one library to check out is FathZIP.

It’s 79$, is fast, seems very stable, and, the kicker, supports completely in-memory zipping and unzipping, so you don’t actually have to save a file as a temp file just to uncompress it.

Oh, and did I mention it’s 79$!

Excel XLSB Format

0
Filed under Office

For anyone that might not be familiar with the issue yet, Office 12 introduces a rather large number of new file formats.

There are formats that include macros (DOCM, XLSM, etc), formats that explicitly exclude macros (DOCX, XLSX, PPTX), and, for the Excel aficionados out there, a whole new binary format, XLSB.

This new binary format is not the old style XLS format, although both are binary and relatively proprietary. It is, however, based on a ZIP container file, just like the other new Office formats. This is a big difference from the older DOC and XLS files, which were OLE Structured storage files.

Stephane Rodriguez has written an excellent article on Code Project about the new format, with some good info on the old formats too.

Very interesting that the BIN files within the zip container turn out to be OLE Structure Storages almost exactly like what the old formats used, just wrapped up in a ZIP container instead of a Stuctured Storage container.

So much for really simplifying anything.

Fun with the Office 2007 Ribbon

0
Filed under Office

I was trying to exercise the repurposing functionality in the Office 2007 ribbon today.

Specifically, I wanted to intercept the FileDocumentInspect command on the Office Menu.

Now, I’ve already added a button to the ribbon, so I added the <commands> section just like all the examples I’ve found indicate:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
 <ribbon>
  <tabs>
   <tab idMso="TabHome">
    <group id="MyGroup" label="My Controls" insertAfterMso="GroupClipboard">
     <button id="MyButton" label="Hello, Word!"
      imageMso="HappyFace" onAction="HelloMacro" size="large"/>
    </group>
   </tab>
  </tabs>
 </ribbon>
 <commands>
  <command idMso="FileDocumentInspect" onAction="MySub"/>
 </commands>
</customUI>

Run the app, load up Word, no joy.

Is the example I found based on Beta bits? Have I mistyped a quote somewhere?
So I start hunting.

Eventually, I had what you might call an AHA moment.

If you have ever played with the .NET configuration stuff, you know that one of the infuriating aspects of it is that the XML sections can be “positional”, meaning that if you put a particular section after another section, it won’t work, but put it BEFORE and all is good. I suppose there might be a rational explanation for this, and for that matter, I suppose there might be a rational reason I’d want two different files to be distinguishable only by case<g>, but sorry, I just don’t see it.

Anyway, put the commands section BEFORE the ribbon section and all is right in the world again:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
 <commands>
  <command idMso="FileDocumentInspect" onAction="MySub"/>
 </commands>
 <ribbon>
  <tabs>
   <tab idMso="TabHome">
    <group id="MyGroup" label="My Controls" insertAfterMso="GroupClipboard">
     <button id="MyButton" label="Hello, Word!"
      imageMso="HappyFace" onAction="HelloMacro" size="large"/>
    </group>
   </tab>
  </tabs>
 </ribbon>
</customUI>

Positionally dependent XML. Gotta love it.

Changing an existing group in the Office 2007 Ribbon

0
Filed under Office

I ran into this several weeks ago and initially blew it off as something I was probably not doing right.

I was trying to add my own button to an existing group on one of the Word 2007 tabs.

Nothing I tried would work. I finally gave up and just created a new, 1 button group with my button in it.

Fine.

Today, I ran across this PDF of a presentation by Ken Getz. On one of the slides towards the end, he makes an offhand comment about not being able to customize an existing group in the Ribbon.

Instead, he goes on, you could hide the existing group, and recreate it entirely, then add your own button(s).

He does not recommend doing so, though, because other addin’s might end up wanting to alter the original group and the results would be less that perfect.

So, I guess you just can’t.

Flight Sims

3
Filed under Helicopters

If you’re at all into radio controlled models (specifically planes or helicopters) you need to check out FMS.

Maybe I’m just late to the party with this one. It’s been out in various incarnations for quite some time now.

The website even lists the latest version as being released around July of 2005, but, well, wow!

I got into RC helicopters some time ago, but was always stymied by the process of just getting used to steering the dang thing, mush less hovering, or god forbid, any kind of acrobatics. As the saying goes, Crash a plane, fix a wing, Crash a helicopter, fix the whole damn thing.

So, my models and radio sat for quite some years.

Then I happened into a hobby shop recently and stumbled across an RC flight simulator demo they had going. This was a commercial package weighing in at 200$ but it included a cheap but effective radio control style joystick that plugged into to the PC’s USB port. Now that was hot! Practice flying on a PC but using a radio style joystick.

I came home and started googling.

One thing led to another and I came across the freeware FMS, Flying model Simulator.

A quick install and it was clear this could actually let me learn to fly and get used to the controls enough so that taking the real thing out wouldn’t be as scary as, say that Gem Sweater video.

But what about the controls? I really liked the idea of controlling the simulator with actual RC joysticks, but, I thought, even better if I could actually use my real radio for the controls.

Lo and behold, Simblaster.

For about 40$, you get a usb dongle with an phono style plug that plugs right in the back of my radio (an older model Galaxy Computer 8 PCM, but they’ve got versions for other radios too).

This is one of the few gizmos I’ve bought that has just plain worked, right out of the box, with basically nothing else to do.

A few more weekends getting used to flying a helicopter out and then back at me on the sim and I might just have to take the real model back out the park!

Hummingbird DOCS Open PCDType.tlb

0
Filed under DMS, DOCSOpen, TypeLibs

So I’m moving along quite nicely integrating some code to handle document checkins into the DOCS Open Document Management System via their API, when I hit a nasty little snag.

I try to run the app and get a compile time error at

x$ = string$(78, 10)

Saying that STRING$ is not a valid function.

Huh?!

A little digging and come to find out, the DOCS Open api typelib PCDTYPE.TLB contains a constant definition of STRING. Of course, that is overriding the VBA definition and boom, a problem.

I could go through my app and replace all STRING$ occurrances with VBA.STRING$… I could, but that seems just flat nasty.

Matt Curland’s PowerVB to the rescue again. Load up TLB Editor included with the book, one quick change to rename the bogus constants, and then a good scrubbing of the registry to remove all traces of the old TLB and we’re back in business.

Of course, you wouldn’t want to redistribute the modified TLB file, but, since all the definitions in it are compiled into your VB app, you wouldn’t have to do that anyway.

Technically, you should be able to alter the precedence of references (such that the VBA class definitions would have more weight than the PCDTYPE entries).

Alas, that didn’t seem to work in this case (I’m guessing because the VBA reference is a built in).

Moral: If you’re still messing with VB6 on occasion (I know you’re out there!), Matt’s book is a must have. And you can probably get it cheap on the bargain racks now.

Formatting Code Snippets in a Blog Entry with CSS

0
Filed under Blogging, CSS

Since this blog is a relatively new thing for me, I’ve picked up quite a few tidbits while setting it all up.

One thing I just ran into is formatting code chunks. I’m guessing there’s loads of different ways to do it, but in my case, I just wanted something easy to tag, and with a nice format, but not necessarily “pretty printed” with color, keyword highlighting etc.

In researching it, I came across Nikhil Kothari’s blog. He has a number of nice things there, so check it out for everything else as well, but I noticed he was formatting code almost like what I had in mind.

The CSS he uses is:

pre {
 font: inherit;
 color: inherit;                        
 white-space: inherit;
 margin: 0;
}

The problem I had with this is that it tends to allow the text to flow over past it’s containing block on the right, which, to me, doesn’t look all that good.

Plus, to set off the code more, I’d prefer it indented to the left and right.

A little CSS reading later and I came up with this:

pre {
   font-family: 'Lucida Console', Courier;
   font-size: 10pt;
   color: inherit;
   white-space: no-wrap;
   margin: 0 3em 0 3em;
   overflow: hidden;
}

It gets the font right, the indents right, and just chops the text at the right edge. I suppose for some purposes, it might be better to wrap the code, but at least for what I need right now, it seems perfect.

Just Added: The above doesn’t quite work in all cases. Appearently, in IE6, overflow:hidden isn’t necessarily supported properly. You might also need to specify a Width property. In my case, I used:

pre {                        
   font-family: 'Lucida Console', Courier;
   font-size: 10pt;
   color: inherit;
   white-space: no-wrap;
   margin: 0 3em 0 3em;
width: 80%; overflow: hidden; }

Which seems to do the job just fine.