Thursday, September 27, 2007

Family-Work-Life Balance

The Family & Parenting Reporter for the Seattle Post Intelligencer Paul Nyhan made an interesting post last night about Work-Family Balance: Work-Family Balance is a Joke: Embrace the Chaos

The post talks briefly about efforts towards new family leave law in Washington and then moves on to an evaluation over whether a happy Work-Family Balance is actually realistic and attainable. He concludes that it isn't and that working parents need to roll with the punches.

I'm not sure how I feel about the phrase "Work-Family balance." Typically when I hear the term Work-Something Balance it's "Work-Life Balance" that's being talked about. I've never heard anyone without kids refer to their "Work-Family Balance." Perhaps it's only once we have kids that family actually factors into the equation.

I think that the phrase for everyone should be Family-Work-Life balance. Family comes first, then work (gotta pay the bills), and then you can squeeze in some time for yourself after you taken care of your family and your work is in order. Not that this is the arrangement of my priorities all the time but it's something to shoot for. Actually, the thing to shoot for is Family-Life-Work but that's really hard to do. Focus on your family and living your life and let work be an afterthough. Work to live vs. the other way around and all that.

Finding time for yourself is definitely a challenge even as a single person with a full time job let alone as a parent. Pamela Slim (who maintains the Escape From Cubicle Nation blog) posted yesterday morning about 8 Strategies to get the most from painful or awkward life transitions. A lot of the strategies she posted definitely apply to parenting and the attempt to maintain some sort of balance. In an effort to not copy the meat and potatoes of her post into mine I'll say you should go check out her post. I'll end this with a quote from that post that I really liked:

The interesting thing is that no matter what the ultimate benefit of a change, going from "what was" to "what will be" can be very unsettling.

Saturday, September 22, 2007

The Excel Interop

I just finished up a project working on a win32 client application that is used to import data from an Excel spreadsheet into a database via a secure web service. Working with the interop was interesting and it was nice to get exposed to something new. I'll post more about web services later (as well as returning custom data types via web service methods, serializable Dictionary objects, and converting rtf to html) but I wanted to rant about the Excel Interop a bit.

Indexing
When I started working with the interop I went in and created an instance of Excel:

Microsoft.Office.Interop.Excel.Application excelObj = new Microsoft.Office.Interop.Excel.Application();


This is all well and good. After that I set visible to false and went about starting to access some of the bits and pieces in my xls file. Oh, and because we're using C# and because Open isn't overloaded:

Microsoft.Office.Interop.Excel.Workbook workbook = excelObj.Workbooks.Open(
filename,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value
);

Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(0);

Now, if you run this code you'll get an exception citing an invalid index:

System.Runtime.InteropServices.COMException (0x8002000B): Invalid index

If you're like me you'll immediately try starting your index off at 1 because I suppose it makes sense to start off your worksheets at 1. As much as this seems like VB and as much as I don't like VB I think I can live with it. So you change the sheet number to one and go on your merry way.

Then you try to access some data in your first worksheet:

string str = (string)((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[0, 0]).Value2;

Running this code gives you an exception and you want to assume it's because you started your indices off at 0 but it doesn't quite make sense because it gave you a different exception:
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT

Hopefully at this point you immediately try Cells[1, 1] and don't spend some time trying to figure out what you did to go from a meaningful exception that made sense to a generic COM Exception. If you try 1,1 you'll find that it works and all will be right in the world.

What bothers me about this isn't the fact that I have to start the index off at 1 rather than 0. What bothers me is that when I tried to open a worksheet with an out of bounds index I got an exception telling me that it was an index issue. When I tried cells that were out of bounds I got a generic exception. The worksheet exception was actually helpful and immediately let me know what the problem was whereas the cell exception wasn't even though it was pretty much the same exact issue.

Killing Your Instance:
I'm not even going to into detail on this as it's been beaten to death already. Killing off an instance of Excel is a pain though I don't think that's really the fault of the interop. You have COM to thank for that one. Essentially you have to make sure that for each Excel COM object you create you're calling ReleaseComObject:

Marshal.ReleaseComObject(excelObj);

And then calling the Garbage Collector:

GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.GetTotalMemory(true);

I'm not really one to talk in this instance though since my client app still has a bug where when multiple instances of the Excel application are created once I close them out all of the processes go away except for the first one I created. It's really bizarre. See the references section for some links.

Hyperlinks
This isn't so much a beef with the Excel Interop as it is with Excel in general. In Excel you can't have a link within a cell. You can have the entire cell be a link to some location but you can't have the text "click HERE for pictures of my cat" and have only the text "HERE" act as a hyperlink. This ended up saving me some time on the rtf to html conversion but is kind of lame in my opinion.

References:
Here are some of the pages that I found the most helpful when working through this:
- MSDN: Excel Tasks
- Craig Murphy: Excel Interop - killing Excel.exe
- MS Help and Support: Office application does not quit after automation from Visual Studio .NET client
Excel Solutions Forum

Tuesday, September 18, 2007

Catching Up

I've found myself wanting to post fairly often lately. Typically it's about some technical aspect that's either irritating me or making me really happy. It's not very often that I'm working with something and I sit back and reflect on how much I love n technology because n technology makes my life easier or is just plain cool. I've gone through and made draft posts containing nothing more than a title and a brief description for some of them and at some point I may come back to them.

I need software that automatically extracts a topic along with my feelings towards and knowledge of that topic from my mind with minimal effort on my part. It would then take the randomness floating around in my head and structure it in a rational way, write up a few paragraphs, and post it to my blog. That way when I say to myself "wow, this is really cool" or "holy hell this is such a pain to work with" I can just hit a button and a post automagically appears on this blog (or whichever blog I choose).

Joel Spolsky

I know some people don't like Joel Spolsky and I know some people do. I'm in the latter camp and I don't care what other people think. Sure some of the things he writes and posts about aren't of a whole lot of interest to me. But then he'll post things like this and it makes up for all the posts of his that I only skim or skip over.

If you have time go read his most recent post (as of my posting this) here:
Strategy Letter VI

This article was particularly largely for the history of computing and software aspect. Being rather young in the grand scheme of things I don’t have the amount of experience and perspective that he has. Given that fact I appreciate hearing about things like the rise and fall of Lotus 1-2-3 and the changes in the business of writing software as a result of the progression of hardware. It’s even more interesting when patterns can be identified.

I'm not sure what happened to Strategy Letters 1 - 5 but I'm sure they were at the very least somewhat interesting. I may have to go dig those up at some point.

Tuesday, September 11, 2007

Restructuring

I've decided to change things up a little bit. From now on I will be trying to post a lot more often and on a larger variety of topics. I can only post about the struggles and triumphs of working from home so much. This doesn't mean I'll be posting pictures of my cat (I don't own a cat but I could always post photos of the neighbor's cat) or what I had for dinner tonight. From this point forward there will be more variety which will likely include little technical snippets, some details regarding what I'm working on, and my take on living with a kidlet.

Oh, and we're expecting kidlet #2. Good times.