UVa Online Judge runtime error

It has apparently been a long time since I had to do any kind of reading and writing from the console in C.

I was trying to work through the Minesweeper problem on the UVa Online Judge site, and my submissions kept failing with a “Runtime error”, with no explanation given as to the source of the problem. Of course, everything was working swimmingly when I was trying to run through the code as a command line application in Xcode on my Mac. Some investigation into this led me to pad my arrays and strings so that there was no chance of an array index going into areas they were not supposed to, but it was still failing.

I finally discovered the problem was that I had used an int variable in my code, but a %i instead of a %d in the scanf format string. As soon as I switched that over, the “Runtime error” went away. And I was able to move on to the “What do you mean ‘Wrong answer’???” part of my evening.

Oh, and Happy Data Privacy Day everyone.

Easy way to format the time difference between two dates

In converting my VB6 code over to VB.NET, I was looking for an easy way to take the different between two DateTime items and display in hours and minutes.  The TimeSpan gives a nice structure to dive into the difference and see exactly the interval, but I was hoping to find a way to output this in the same way that you can use the ToShortTimeString method of DateTime.

As it turns out, I found a posting by Jay Barlow that mentions converting the time different to a date time, and then using a custom format string to do the work so that I wouldn’t have to.  Here is my new VB.NET code, where rec is a class that includes the start and end date and duration is a string that holds the information to be displayed:

If rec.endDate IsNot Nothing Then
    Dim ts As TimeSpan = CDate(rec.endDate).Subtract(rec.startDate)
    Dim dt As DateTime = DateTime.MinValue.Add(ts)
    duration = "Event duration: " + dt.ToString("H:mm")
End If

Oh, and one more thing. Am I the only one in the world that thinks that iPad is the worst product name in history? Sure, it is so close to iPod so as to create brand recognition and draw comparisons, but I would just wonder what kind of names were shot down, and if any of them did not begin with the letter i.

By the way, Happy (Belated) Australia Day.

My Tracks Android app review

I saw a news blurb a while back about this new app from the Google folks called My Tracks. I downloaded it to my Droid right away, but really didn’t try it out until today.

So I decided to try and use the application while walking one of my dogs. The navigation around the application is pretty simple, and the track recording seemed to work very well. After I got back from the walk, I was able to see the path that I walked along with a bunch of statistics about it.

The program has upload options to send to Google Docs and Google Maps, so I tried them both at first. This first upload did complete to my Google Docs, but I did have a bit of trouble when it tried to upload the track to Google Maps. The first few times I tried it, I got some miscellaneous errors, such as an authentication error and other nondescript messages. Finally it did go through, and the track then was showing up on the My Maps page of Google Maps.

Even though this app is in the early stages of development, I think it rates quite well. I would give it a 4 star rating, if only because I had some trouble getting the Google Maps upload working.

If you can find it in your heart to help out a fellow nerd, please help out Shawn Powers, he is having a tough go of it. Here are the details:

Urgent: Help Shawn Powers & Family

Oh, and I hope everyone out there had a good Martin Luther King Day.

VB.NET radio button groups act differently than VB6 radio button groups

The few dozen remaining WinForms developers left on this planet may have noticed that, for some reason, a group box with radio buttons in it as designed in the Visual Studio 2008 environment will have the first radio button of the first group box automatically selected when the form comes up, even though all of the radio buttons have their Checked property set to false in the design environment.  It never used to do this in VB6, as when you ran the application, the group of radio buttons would have no members selected.

The problem manifests itself when you are trying to perform additional tasks in the CheckedChanged event of the radio buttons when the user selects one of the radio buttons, since the first radio button is being automatically selected.

I asked this question on Stack Overflow, and got a couple of replies. The one that I finally used to solve the problem was to set the Checked property of the radio buttons to false in the form’s Shown event, which I had never used before. By doing this, the first radio button was no longer automatically showing up checked.

One other thing that I had to do in addition was to cast the sender into a RadioButton and look at the Checked property of the clicked radio button in the CheckedChanged event, as that event is fired for radio buttons both being turned on and also turned off.

Oh, and happy National English Toffee Day!

Nerdski

I have always enjoyed alpine skiing ever since the first time that I went to the local ski area in Ohio. I don’t make it to Brandywine much any more because I have been skiing in the West many times over the years, and once you go there, it is hard to go back to the little ski bumps. (Even though I live closer to the Ohio bunny slopes now than I ever have.)

A few Christmases ago, my wife bought me a deck of playing cards called Ski USA, A Bird’s-Eye View of 52 of the Best Ski Mountains, with each of the 52 cards having a trail map and vital statistics for 52 different American ski resorts. In this new decade, I have made a resolution to try and make a go of visiting the rest of the 52 resorts depicted on the playing cards that I have not been to yet.

I put together a Google Earth KML file with the 52 resorts on it, if you want to use it to track your own progress.

Ski USA KML file (Google Earth)

BTW, if you are interested in buying the deck of cards, here is a link to it on Amazon’s web site:

Ski USA Playing Card Deck

I am thinking of heading to New England in the winter/early spring time frame, if anyone has any suggestions about which of the resorts to visit, please let me know.

Oh, and Happy New Year everyone!

Control arrays in VB.NET

One of the things that I really liked (and used quite a bit) in the VB6 IDE was the ability to use the design surface to create a form with a bunch of controls with the same name as a control array. You would create the controls on the design page, give it the same name as another control, and the Index property would automatically be incremented. This would then let me use a loop to manipulate and examine these controls.

This functionality is missing in VB.NET, as I discovered when I tried to do my first .NET Compact Framework application way back when Visual Studio 2003 was shiny and new, and has continued to be missing from the feature set in VS2005 and VS2008.

Microsoft is not much help on this front. Their solution is to create the forms in code, as described in this article:

Not so helpful link (link redacted)

But I like using the design surface to create forms. A co-worker suggested we try to do a test in C# and tamper with the designer.cs file to create an array of controls in there, which worked OK. The big problems there were that the controls showed up on the design surface, but they could not be clicked and modified. Also, when we added a control to the form and saved it, all of the customizations we made to the designer file disappeared. (Oops.)

So instead, what I am now doing is creating my forms in the designer as before, with each control of the set having a different name with a number after it (such as cboName0, cboName1, etc.), referring to the index of the control in the array. At the top of the form’s class I have the arrays defined:

Dim cboName(10) as ComboBox
Dim lblNumber(10) as Label

Then, in the form load event, I am calling this subroutine:

Sub SetUpControlArrays()
 
    For Each cb In Me.Controls.OfType(Of ComboBox)()
        If cb.Name.Contains("cboName") Then
            cboName(CInt(cb.Name.Replace("cboName", ""))) = cb
        End If
    Next
 
    For Each lbl In Me.Controls.OfType(Of Label)()
        If lbl.Name.Contains("lblNumber") Then
            lblNumber(CInt(lbl.Name.Replace("lblNumber", ""))) = lbl
        End If
    Next
 
End Sub

Now I have the ability to address the controls in the same way that I used to do in VB6. The fact that I lived with this missing feature for about 6 years and just now figuring out a decent way around the problem pretty much guarantees that VS2010 will put the control arrays back in.

EDIT: At the request of a Strong Bad fan who shall remain nameless, I changed up the code above to be a bit more friendly. The previous code only extracted the rightmost 1 character from the name of the control on the design surface, which would not work if you had a control name such as cboName10.

Can we all get along?

I finally got tired of living with the inability of WordPress to automatically update on this very blog site, which is hosted on 1&1, so I did some digging into the WordPress forums. In addition to the automatic update just hanging up when trying to download the updated zip file, I also would never see anything appear under the WordPress Development Blog and Other WordPress News sections on the right side of the main dashboard.

One of the solutions mentioned was to set up your web site to use PHP5 instead of PHP4. So, I logged into the 1&1 administration panel, but could find no setting for the version of PHP used by my web sites. (My company has sites hosted on Rackspace Cloud, formerly Mosso, which has a nice little choice list on their admin panel to set the PHP version.)

A quick phpinfo() page on my blog site indicated that version 4.x of PHP is used. An equally quick search of the 1&1 FAQs yielded the answer.

You have to put the following line into the .htaccess file in the root of your web site:

AddType x-mapp-php5 .php

Apparently, this makes it appear to 1&1 hosting that all of your PHP files are meant to be run using PHP version 5 instead of version 4, without having to rename all of your files to have a php5 extension instead of php.

Oh, and I hope everyone is having a nice Boxing Day.

The keys to the Kingdom

The biggest problem that I have had over the past 2 years or so of working with the iPhone SDK is the seemingly insurmountable learning curve to have you applications do something reasonably simple. I think this is partly due to my lack of any free time to dive into the whole iPhone SDK/Cocoa Touch/Objective-C world, and partly due to my straight ahead, VB6 development mentality.

For example, in my VB6 applications, if I need to display a dialog to the user to collect some bit of information, the parent code creates the form and shows it, and the child code closes down the child form when the user is done. This reasonably simple task has proven a bit elusive, as it seems like at times, I can’t get this to work for one reason or another.

Alas, I think I have finally figured out a good way to do this very task. Now, all I do in my parent view controller is to run the following code when I need to:

ChildViewController *controller = [[ChildViewController alloc]
					initWithNibName:@"ChildViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];

In the new view that comes up by calling the code above, I use this code to get rid of the new view:

[[self parentViewController] dismissModalViewControllerAnimated:YES];

(Now of course, there is more going on here, as you need a way to pass values back and forth from one view to another. I think I might have a blog post from a few months ago to talk about this process.)

The end result is that I now have a simple way to show and dismiss forms in much the same way that I did with VB6. Does discovering this mean that I will continue to bumble around in the dark when it comes to the mysteries of inheriting from the correct classes in the iPhone SDK? Probably. Am I worried about it? Nope.

Oh, and I hope everyone has a nice Christmas (or insert your own holiday here, Kwanzaa, Festivus, Hanukkah, etc.), and drive safely out there. Grandma still hasn’t recovered after being run over by a reindeer.

Demo days (CONDG meeting, December 14, 2009)

The Central Ohio .NET Developers Group held their final meeting of the year last night at the Microsoft office in Polaris. Four people gave short demos of Xbox, Zune HD, Windows Mobile, and iPhone, and talked about developing for each platform.

The highlight of the evening was my name being drawn as winning the year’s final and perhaps most craptastic door prize, which I then gave to my coworker who was attending the meeting with me. He is into free t-shirts.

2009-12-15 09.13.18

Netbook resolution in Windows Virtual PC

A customer lets me know that they are having a problem with one of our software products. It was something specific to the 1024 by 576 pixel resolution of their Dell netbook, which was a problem since we did do not have a computer with that resolution.

So I decided to try to use the Windows XP Mode of Windows Virtual PC on my Windows 7 Ultimate dev box to simulate the netbook resolution and try the software in that virtual machine. Unfortunately, I fire up the Windows XP mode only to find that it is fixed to 1024 by 768 resolution in the display settings, with no way to change since the Advanced button is disabled and there are no other choices for the resolution slider.

After I investigated a bit, I found that I could edit the Windows XP Mode.vmc file (located in the folder C:\Users\My Name\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines, substitute your name for My Name in the path), which is an XML file. There is a ui_options section in the file, my file now contains the following 2 items:

<resolution_height type="integer">576</resolution_height>
<resolution_width type="integer">1024</resolution_width>