Hi Mike,
You don't need code to do this. You can use xpath (InfoPath's macro language) and the eval command. Microsoft's InfoPath blog had an article about 2 years ago on the eval(eval(....)) method. It's pretty cool and we even have it in one of our InfoPath training labs. Send me email if you can't google it.
Best of luck
PS> there's also a count function which could be easier. :)