Archive for the ‘phil’ Category.

Adventures in C#: Excel automation

So I’ve been working a fair bit with C# and Excel automation, and I’ve picked up a few things from the whole experience so far - namely that the thing is really poorly put together and requires a whole lot of work to make things work nicely.

The emphasis there is on nicely. You can hack together something real quick in about 5 minutes that probably almost does what you want, and will be good enough if you just need the job done. However, the Excel COM uses about 3 different standards and each time you get to guess which one you’ll need to use.

Over the next few days [or weeks] I’m going to outline a few of the problems I encountered and how I went about fixing them:

Problem: The syntax for inserting a column and changing a column’s width is completely different

This might not seem to big of an issue until you realize that:

column.Insert(); exists, but:
column.Width = 10; or column.setWidth(10); or anything like that, does not exist.

The actual solutions to do these tasks are as follows. Note, they reference the variable oSheet is the Excel.Worksheet you’re working with. These samples assume a basic knowledge of C# and using the Excel COM.

Inserting a columm:

Excel.Range rng = (Excel.Range)oSheet.Cells[rowNumber, colNumber];
Excel.Range column = rng.EntireColumn;
column.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, false);

This will insert a column to the left of row rowNumber.

Changing a column’s width:

((Excel.Range)oSheet.Columns["A", Type.Missing]).ColumnWidth = 10;

This will change column A’s width.

Notice that one method uses numeric identifiers for rows, while the other uses a string. Also, interestingly enough, its a bit of a pain to actual get a hold of a column using either method.

On the eve of a very difficult exam

Tomorrow I write my database exam. Now, some of you who know a thing or two about me know that:

  • I’m not half bad at using database driven applications such as forums, WordPress, etc
  • I’ve actually coded a weaksauce CMS before using MySQL

Now, taking that into account - one would assume this course would be a breeze for me. Not the case dear sirs or madams. While the assignments and even the project were relatively easy - pulling me marks between 75-100 percent - both midterms managed to completely ruin me, as I failed them both. How, you might be asking yourself, is this possible? I can’t tell you any names, but it is through a certain person that this has come to pass. A certain person who is employed by a certain university, who teaches a certain course.

Certainly.

This man/woman [I'm not narrowing it down anymore] can not teach worth shit, and they are very aware of it. As such, the course materials - including assignments, midterms, and projects - are allegedly taken almost verbatim from the website for a database course offered in Hong Kong. However, this professor was slightly ashamed of their blatant thievery - so they attempted to change the wording on our final project. Instead of doing so, they managed to horribly muddle the task’s description and cause severe confusion as to how the implementation was to be handled. Magically I ended up with my lowest passing mark in the course - the 75 - from that project.

So I have faced for the last few days, the task of studying for this exam which is sure to test me on things that my professor did not teach [though it should not be implied that my professor actually taught something else, they more so tried and failed miserably to teach something else]. As such, I’ve spent most of my time reading the textbook for the course, and hoping that somehow I’ll have achieved enough of a broad knowledge of the book to scrape by with a pass in the course.

Now that really won’t happen, but I’ll post in the comments once I finish failing the exam to fill you in. So here’s to bell-curves; saving my ass since ‘05.

Why you should be the guy who corrects the teacher

Lets face it. Nobody likes that guy [or girl] - the one who always pipes up and corrects the teacher. Its annoying, and usually he disturbs class just to make himself look smart.

The unfortunate fact is that we should all be that guy. I realized this today as I was sitting in Math class when my teacher asked a question. I replied with what I thought was a fairly obvious and logical answer - but my teacher disagreed with me. She then went on to explain to the class the correct answer - which was the exact same method I had suggested moments before, but using confusing terminology.

After she had finished this topic, she then went on to explain about arc-overlap graphs. While constructing an example, she made a mistake. Now, I will admit that I corrected this mistake out of vindication - but to my surprise she was quite happy that I corrected her - and she began to praise me for my “sharp eye”.

It was at this point I remembered; at the beginning of the term, she openly called for students to correct mistakes like this. The reason being, that if the mistake was not caught students who were taking notes would write down an improper example.

Come study time:

  • the students might be confused as to why their example didn’t work
  • the students might learn the material incorrectly - assuming that the example was correct

This started me thinking; why is it that it’s so hard to be the person that corrects the teacher - especially when it’s a fairly critical function for effective learning? As much as I really dislike my math teacher’s style of teaching, in acknowledging the fact that she makes mistakes, she really enhanced the classroom experience.

In my own experience, I find that once I learn a concept I eventually discard the details and retain a general idea of how the concept works. I can’t count the number of times I’ve been doing an assignment or homework, complaining that “Being able to produce specific answers isn’t a good test of my knowledge”. It is painfully true - spitting out answers is not an accurate test of knowledge - but it is a very good way to learn the concepts.

A few of my professors admit to being awful at basic concepts of math such as addition or multiplication - but they understand the high level concepts that rely on these basics. Logically speaking, the only way they learned these high level concepts was by practicing them through homework and assignments just like us, churning through the gruntwork to get the results.

That said, it’s entirely likely that our teachers may have become foggy on the details. As people who know these high level concepts, teachers aim to pass on their knowledge by making us learn the details - even though their examples using the details are prone to having mistakes. As students who are paying to learn these concepts - it should be us that prompts the teacher to correct their mistakes and thereby further the learning environment. In time, when we have a good understanding of the ideas, we can forget the concepts but retain the ideas.

By being quiet and scribbling down everything the teacher says, we don’t really commit ourselves to learning. We’re just memorizing information, and that is not the same as learning it. My point is, the classroom should really be a learning environment - and sitting quietly in your chair writing down what the teacher says verbatim does not take advantage of the possibilities presented in a classroom.

[Update] Fixed some typos - thanks Laura.

Who let me in here? - The story of extended partitions

So allegedly Jake is foolish enough to have given me an “Editor” account on here - which not only lets me post stuff - but also lets me edit his posts. Now I’m a generally responsible person, but seriously - I made the Martina-Shot, okay?

Also, the new WordPress admin panel is much nicer than it use to be, and comes with a nice Web 2.0 colour scheme; mixing pale and vibrant blues with a sandy yellow, as well as a blue tinged black that would look much better were it brown.

alt textThis is not the right kind of partition!

However I digress, I have something more important to say than the obligatory “first post“. This, my captive audience, is a story of extended partitions.

A while back I decided that I wanted to give Vista a try, and the only machine I had that was capable of running all the whorish features I wanted to try was my laptop - and there was no way at that time I was making my laptop’s primary OS Vista. So my friend Murdoch who runs Linux suggested I download partition magic and make a partition to install Vista to. This sounded like a great idea, so I tried it, it worked - and for a while I was happy with my dual boot.

That is until I realized I wasn’t using Vista that often, and my hard drive size was becoming increasingly small. So I decided to embark on the quest of removing this extended partition.

Allegedly this is not something easily done. Partition magic failed at it, which didn’t really make me all that happy - and after some quick google searches and conferencing with Jake I came to the conclusion that the only way to do it was to wipe my entire disk and reinstall an OS.

Three months later [read: last night], I was finally ready to do a reformat. In went the Vista disk [which I've adopted on the laptop now], and up came the “Install Vista where?” screen. I saw my quarry - sitting proudly ontop of my 15 gigs of space that I’d like back - but it had outsmarted me because the Vista install disk had no idea what the fuck and could not delete, reformat, or do anything to the partition.

Great. So I installed Vista overtop of the old XP install and decided to try the Vista Disk Management tool that a few of my friends have been talking about. The extended partition showed up as “Free Space” which unfortunately is neither “Unallocated Space” or an “Extended Partition”. After a few attempts at deleting the partition - each time met with the oddly inapplicable error message: “There is not enough space available on the disk(s) to complete this action”.

After some posts on the good old interweb, I’ve been suggested a few apps to try and help recover my 15 gigs. I’ll post back if I end up reclaiming them.

The moral of the story though? Don’t use extended partitions unless you never want the space back!

Welcome, Phil: another one joins the mess

My good friend Phil has joined the ranks of the whiny bloggers union and installed WordPress. He will likely complain about things even more vocally than I, perhaps in a more emo-tastic way. Go visit him and convince him to keep things online, since he gives things up quickly if not encouraged. :)