Visual Basic

MS Access: Printing the Range of Data on the Page on a Report

I wanted to print a report that indicated the first and last item on each page, just like a dictionary has. You know: "Azeri - Babcock", "Milk - Minder". It makes it easier to flip through printouts.

This is how to do it. It will put the range in the footer. I haven't figured out how to do one in the header, which is what I originally wanted, but found too difficult to do. (There is probably a way.)

First, take your report, and add an unbound field to your report. Rename it to "Range". See the picture below.

Then, set up event handlers for the On Print event of each section. An explanation follows the picture. Here's my code:

Option Compare Database
Option Explicit
Public FirstRow As String
Public CurrentRow As String

MS Access: Inserting Blank Rows

This is a way to insert empty or empty-like rows into a list of "seats" that contains not only reservations, but a number saying how many seats a group of people have.

Novice's Notebook

This is a repository of "novice" articles, written with the intent of driving more traffic to the site, and getting more ad clicks. It's pretty crass, I know, but the information may be very useful. Some of the content is adapted from the diy notes, and other notebooks, which are a bit rougher than these.

Most of these articles are not authoritative, because they're based on what I'm learning, as I'm learning it.

Learning VB: (s)locate files on a disk with VBA

This is a class that will help you find files on the disk, without hitting the disk too much. It's a simplified unix "slocate" library. The first time you use it, it creates an index of all the files on the drive. (Subsequent uses update the file when a day passes.) The index is loaded into memory, and searched with regular expressions.

On an AMD Sempron 2000, the first search on 200,000+ files takes around 11 minutes. The second search takes around 2 seconds, and subsequent searches during a single run take around 1 second each. The first run builds the database, and the subsequent searches use it.

Learning VB: running the code

This blog entry doesn't discuss any code, because I ended up doing very little work on the software. I was busy running it, and the app tends to take over the UI, making programing difficult. For the most part, it functioned as expected, but a couple things changed in how I actually used it.

I added a text box to restrict scanning for MXD files to a subdirectory. This new feature allowed me to set the source root and destination root directories, and then type the subdirectory to be processed. The text box could also be left blank.

I used this feature a lot.

The main feature I stopped using was the scheduler. The software was so slow that it failed to use the network 100%. The point of having the program pause at night was to let backups happen faster, to avoid competing for the network.... but since the job appeared to be CPU-bound, I had was a big disincentive to be a good network citizen. The most efficient thing to do was let the app run all the time, even if it impacted the network -- every time the app was "nice" to the network, the length of time to complete it's task would grow by that amount plus the additional CPU time it took to complete the task.

Learning VB: crash woes, threading template

It was looking pretty grim for the file copier. The main problems were twofold:

First, the app sometimes crashed on bad data. The Windows crash-reporting dialog box came up, and all work stopped until it was dismissed.

Second, after dismissing the dialog box, the app looped furiously, failing to process the remaining files, but marked them as completed (that's a little design bug there). The problem was that the COM server was returning an exception, and it was being trapped and effectively ignored. I say "effectively" because a special call to kill the app, via WMI, didn't clear the problem -- the underlying COM server didn't get stopped and unloaded.

The error could be cleared if I paused the batch job, and restarted it. That caused the thread that communicated with the COM server to abort, thus (probably) releasing the COM server. If only this could be automated.

Learning VB: rubber meets road

I'm finally running that program I've been writing. For the most part, it was "bug free" inasmuch as the different parts ran their test cases correctly, and it runs fine on a small subset of data. Of course, it's not like I ever really learned the system completely, so there are a lot of situations that I'm not handling (or even aware of). Moreover, because the users probably don't use all the features of the software, it's not likely that a complete solution is necessary. No project is debugged "enough" until it operates on real data, in a real situation. Fortunately, my first iterations were done in Perl and VBA, in a scripting environment, on real data, so my experiences debugging those determined the overall structure of the code -- that is, the code deals with messy situations.

Learning VB: recursion

It's going to be a lesson about recursion. It's strictly beginner level.

I don't have any code today, because I was working the polls yesterday, and spent most of today's worktime tuning that file copier. I hit a big problem because of some confusing, mis-coded loops. Here's the scenario in pseudocode (I don't want to fire up the Windows box just to get this code).

for each item in collectionA
    if type of item is Layer then
        processLayer item
    else if type of item is LayerGroup then
        for each subItem in item
            if type of subItem is Layer then
                processLayer subItem
            else if type of subItem is Raster
                processRaster subItem
            end if
        end for
    end if
end for

If you can really read this, it does a 1-level deep exploration when the item is a LayerGroup.

Learning VB: is a time within a time span?

This article discusses debugging a function by rewriting the code.

I'm not sure what I did wrong here, but, my first version of this function didn't work. The function returns true if the current time is withing two time spans. This code was written in a rush, without really thinking about how to do it, because it seemed pretty straightforward. The code, however, was a mess (and embarassing).

    Private Function itIsTimeToWork() As Boolean
        ' Get the two start and end times, and determine if we're within 
        ' the intervals.
        Dim now, start1, start2, end1, end2 As DateTime
        now = DateTime.Now
        start1 = DateTime.Parse(My.Settings.StartWorkAt1)
        end1 = DateTime.Parse(My.Settings.EndWorkAt1)
        If end1 < start1 Then

Learning VB: spinning my wheels, animating an image with the timer

For some reason or other, I didn't get an email response from the client on this gig*, and the week was hectic, so instead, I just worked on making the UI a little nicer. VB has a lot of controls, including a background threader, some standard dialogs, and a serial port. This is giving me a real "Rip Van Winkle" feeling, having been over in Unixville for a while.

(* It was lost in my huge email pile. My bad. No matters... the program got a nice facelift.)

I downloaded a bunch of code examples, and started looking through them. The second volume had some interesting programs. One thing hasn't changed about VB - you have to type a lot of code to get a little done. At least that's still true if you're writing algorithmic code... and clearly, C#'s job is to write that algorithmic code.

Some COM and .NET Notes

This document explains some terminology used on other pags.

ActiveX
A technology layered on OLE that supports a method, IDispatch(), that executes method calls by name (by a string argument). IDispatch() solved the problem of scripting languages being late bound, and not able to handle multiple interfaces. ActiveX also covered other technical things, but the IDispatch feature is relevant to this topic.
Assemblies
A group of classes. The classes generally work together, and form a namespace. Analagous to a Java package. The .NET assemblies are analagous to the Java class libraries.
CLR, Common Language Runtime
A "virtual machine" that executes programs coded in CL, a platform-neutral assembly language produced by compilers. The CLR is also called a "managed environment" because the virtual machine takes care of many runtime issues like allocating memory.

Learning VB: back on track, ole timeouts

Spending most of the evening thinking about ways to test OLE timeout code (and figuring out how to do it in .NET). The issue is simple: the server app isn't super-reliable when it handles bad data. So it will probably time out. The goal is to catch this situation, kill the server, record the error, and continue.

References:
How To Handle OLE Automation Server Timeout and Synchronization
App Object for Visual Basic 6.0 Users

OOOH, there's some really bad news: "OleServerBusyRaiseError: No equivalent. These properties relate to OLE automation, which is not supported by Visual Basic 2005."

So, I'm kind of screwed here.
This tutorial from SAMS gives some more insight: The Essentials for Using COM in Managed Code

Learning VB: ADO.NET insight...

I just got another idea about why ADO.NET keeps local copies of remote tables. With those tables in memory, and using OO code instead of SQL, it might be a little easier to write a JavaScript-based (or C#-based) OLAP client that performs queries on the dataset. Having been a perpetual OLAP noob for, like, forever, it never occurred to me, but, I was fooling around with Excel pivot tables and had that "aha" moment.

This is going to be tough on PHP, because it doesn't really have a good persistent runtime implementation. You can't really do something like allocate a 500k variable in the $_SESSION array. For PHP to compete, it's going to need an in-memory object store that maps to PHP objects. Heck, they'll also need olap services for mysql. So, maybe it won't happen for PHP... but then, maybe it won't happen for olap for average people for a while, either. (Check out Integrated Data Mining and OLAP for MySQL)

Learning VB: file mirroring, lost data

I'm bummed out, because a tutorial about events, delegates, and multithreading that I wrote got lost. There was some database problem on the server, and the text didn't get saved. It just compiled information from the last blog entires, but, it was pretty good. Oh well, I must forge on with this little project.

The latest really good news is that the threading stuff is working. I also added a little time-checking feature so that the batch processor will work for a while in the evening, take a break while backups happen, and then work again in the early morning.

File visitor

Someone else is batch processing with vb: Processing files within a file structure with plug-ins and events

File mirror

Learning VB: events, delegates, tired

Again, I didn't do much hacking. Yesterday really took it out of me, and I slept a lot (finally). Instead of hard stuff, a few simple things got done.

Copy URL+ is a great extension for [Firefox] that helps you create links to web pages. Instead of copying the URL, it lets you copy the URL-plus-title. Not only that, with a tweak, you can have HTML copied to your clipboard. It's a must-have for any blogger, writer, whatever.

I read more about events and delegates and updated my old blog post about them. When I was coding, I referred back to this blog to find my references. This temporal organization is better than a more formal categorization, because I'm still new to the topic, and don't really have a good overview of what I need to know.

Syndicate content