April 8, 2008

The Old Man Still Has It

I gave up being a programmer over fifteen years ago. After about fifteen years spent programming, I realized that programmers are the 21st-century bricklayers, and that they will always be underfunded, overscheduled, and uncredited. Rather than building houses, I'd rather be the architect designing them.

Plus I just couldn't wrap my head around object-oriented programming. Or if it was possible, I was by then so finished with programming that I couldn't get up the energy or interest to do it.

But that doesn't mean I don't ever code. It just means I don't code very much.

Whenever I do write code, any accomplishments, however minor, are extra-special since I'm no longer a coder. Back in the mid-Nineties I wrote a piece of C-language code that would import all-capital-letters information from a mainframe, and translate it into appropriately capitalized-and-lower-case information. I remember how pleased I was when it worked.

Likewise, I modified a perl script that I found on the internet to turn it into a fairly robust image slideshow viewer.

So today's accomplishment was minor, but pleasing. Put simply, I've been re-creating the ability to build Visio diagrams with Layer buttons. This allows for parts of a diagram to be displayed and hidden - for example, a diagram of a street could have one button for "Cars", one for "People", and another for "Both," and each button would show what's on its label and hide what isn't.

Building each button takes a block of Visual Basic code that looks like this:

Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
  If LayerObj.Name = "Cars" Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
    LayerCellObj.Formula = True
  Else
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
    LayerCellObj.Formula = False
  End If
Next

The problem I was running into was that if you have a lot of buttons, you repeat that block of code very time. For instance, if I wanted "Cars" and "People" buttons, I'd have to duplicate that entire block of code, changing the word "Cars' to "People."

Then I started to create additional sheets in Visio, and I discovered that each button on EVERY sheet would have one of these entries in the same code file. Now the code block would go on for pages, with a big different block for each button on every sheet, and all the layer names extended across every sheet. This was going to be terribly clumsy.

Finally, if one wanted to show ALL layers again, or contrariwise show NO layers, then one needs those buttons on each sheet, an each of those buttons on every sheet would have an associated big block of code. This was going to be a mess.

What I needed to do was figure out a way to re-use the same block of code over again, with different label names - what's called a "subroutine" in coding language. Problem was, I had no idea how to specify such a thing in the Visual Basic coding language.

I started fooling around with it, but I didn't have a lot of time. I tried a few intuitive guesses, but when I started to find myself using Google looking for instructions, I figured I ought to give up. I didn't have the time to fool around digging in Google.

So I finished what I was doing, closed my quotations and parentheses, and saved my work. Then, more out of habit than anything else, I clicked the button.

It worked!

I didn't even know what I'd done to get it right. I'd simply closed quotes and parenthesis in a way that seemed reasonable, and amazingly I got the function correctly formatted, almost by accident.

Private Sub ShowLayer(ThisLayer)
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
' Debug.Print LayerName
  If LayerName = ThisLayer Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
    LayerCellObj.Formula = True
  Else
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
    LayerCellObj.Formula = False
  End If
Next
End Sub

Private Sub CommandButton1_Click()
'Example page Layer1 button
Call ShowLayer("Layer1")
End Sub

So now I have a handy little set of buttons and subroutines to let me set up more buttons. Instead of reproducing a big block of code, all I do is call the ShowLayer subroutine with the name of the layer to activate, or the AllLayers subroutine to turn all layers on or off.

If you're a Visio user who wants to learn how to make buttons, take a look at my example file and hopefully it will be helpful for you!

Posted by Albatross at 11:33 AM | Comments (0) | TrackBack

April 6, 2008

Weekend Oof

Well, this is my first weekend off in a while. It's rather nice not having to work seven days a week for a change, although who knows how long it will last. At the beginning of March my boss asked me to put in more time at work. We had one of these conversations over electronic chat (meaning that I captured it for posterity):

"how many hours are you burning per week?"

"Well, I'm burning about 45."

"is there anything preventing going up a little more? I am averaging 60"

So I took the hint and started putting in more hours. Certainly there was plenty of work that needed doing. Still is.

Fortunately this week some of my responsibilities were offloaded to another person. I could tell that in some senses this was viewed as some kind of "loss" for me, some kind of "win" for her. And within the corporate context of career employees, that's possibly true.

Whenever I've been part of such "wins," however, they are usually transient and meaningless. For one week you might be celebrated as an exceptional employee, but I have never seen long-term accruing benefits from such endeavors. Instead one's manager leaves or the business reorganizes, or one changes jobs, and then one might as well have sat quietly in a corner as worked like a fool, the end result is the same.

So I was happy to "lose" and hand some unwantd and unasked-for responsibilities off to the crazy person who stepped up for the job! What this change means, in addition to being able to relax on a weekend, or maybe even blog, is that I get to focus on the type of work I actually like doing and am skilled at. I'll probably still be called upon to work crazy hours, but at least I won't spend it, like I did last Sunday, fiddling with Microsoft Project and impossible milestones.

Yesterday I had the usual Saturday intentions of getting a million things accomplished. But in the afternoon I went biking with a friend (one of the planned things) and she suggested a different route. We headed out, and the next thing I knew I was a zillion miles from home on my bike, and a long way to go to return. I pedaled along diligently behind her for two and a half hours, but I am dreadfully out of shape and weigh twice what she does, so she was forced to wait up for me several times. I arrived home dog tired and sore in places I'd rather not discuss from too long on a bike. Towards the end I was even starting to get numb in my wrists from holding the handlebars, an attack of the carpal tunnel to which my wife is usually victim, not me.

So that was my weekend "oof" (I bet you thought I'd mistyped the title). Despite resting, I was useless for the remainder of the evening. I couldn't concentrate, and ended up getting little else done that I had planned. Today is taken up with church, and then family birthday party obligations.

Hopefully I'll have a chance to get some chores done tonight. But we'll see.

And then, weather and time permitting, I'll hop on my bike on Monday morning and pedal the twelve miles to work. Because I gotta do SOMETHING to get in shape. (Although I am proud of myself, I've been here at the cafe for more than an hour, and only eaten a yogurt and a sandwich, avoiding the tempting chocolate croissant.)

Hopefully my reduced workload will permit me a little more time for recreation.

Posted by Albatross at 11:20 AM | Comments (0) | TrackBack