Thursday, January 29, 2009
Friday, January 23, 2009
Repeating Habits
I had a student's code not working. He was getting this error: A first chance exception of type 'System.FormatException' occurred in mscorlib.dll. Goggleing the error was no help. My first reaction was to take my working code and compare it to his broken code. See the examples below. Can you see the difference? I did not. The bad habit I had was taking my working code and comparing it line by line after the lines by line. I have fixed many student errors this way. It did not work this time. I also let the student see the code also. I was unable to see the error but the student found the error later.
Working Code:
btnDisplayCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayCost.Click
Dim strEnterNumberOfTickets As String
Dim intEnterNumberOfTickets As Integer
Dim decTotalCostOfTickets As Decimal
strEnterNumberOfTickets = Me.txtEnterNumberOfTickets.Text
intEnterNumberOfTickets = Convert.ToInt32(strEnterNumberOfTickets)
decTotalCostOfTickets = intEnterNumberOfTickets * cdecTotalCostOfTickets
Me.lblTotalCostOfTickets.Text = decTotalCostOfTickets.ToString("C")
Bad Code:
frmConcertTickets_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strEnterNumberOfTickets As String
Dim intEnterNumberOfTickets As Integer
Dim decTotalCostOfTickets As Decimal
strEnterNumberOfTickets = Me.txtEnterNumberOfTickets.Text
intEnterNumberOfTickets = Convert.ToInt32(strEnterNumberOfTickets)
decTotalCostOfTickets = intEnterNumberOfTickets * cdecTotalCostOfTickets
Me.lblTotalCostOfTickets.Text = decTotalCostOfTickets.ToString("C")
Friday, January 16, 2009
Closing Outlook before Backup
I backup my Outlook file to AVG online backup (this is free). I need Outlook to close automatically so the backup will be successful. I found a utility that makes it work. This command line utility adds a lot of function to scripts for XP: you can clear the recycle bin and clipboard. You can also close applications so the command is:
nircmd.exe killprocess outlook.exe
You can learn more about this utility by going here.
Make sure you copy all the files to your c:\windows\system32 folder or where ever you have you operating system installed.
Finally, I created a task and scheduled it to run right before my backup.
Tuesday, December 9, 2008
Excel Formula not Working
Symptoms:
I was working in Excel spreadsheet that was a downloaded csv sheet. I would put in a formula to sum a column and I would get this:
A |
40 |
60 |
20 |
=sum(a1:a3) |
The formula would not work. I changed it to average and still you only would get the text. The number
Gathering Information
I looked at the sheet and found that all the cell where formatted as text. This was because the sheet was an imported comma separated download of grades. Number are generally set flush right but the text was flush left.
Hypothesis
H1 Convert the cell format to numbers general. (Failed)
H2 Use error correct to covert text to numbers. (Accepted)
Results
The number stored as texts can be corrected using the excel error correcting utility. The cells have a green triangle in the upper left corner. See the video in previous post. You click on the diamond shaped and you get a dropped menu. Select convert to number.
See the movie in the previous steps to see the hands on instruction.
Reflection
Exporting data is tricky. This is a very simple example but imagine a whole school system's data needing adjustments.
