Tuesday, May 5, 2009

Cats and Dogs Assignment

I discovered a few things while doing my Cats and Dogs assignment. Firstly, you can make one panel the child of another panel without realizing it. I made this mistake as I have four panels that fit in to the space of one panel. When I slid them in to place manually, one of the panels wouldn't show up because it was the child of a different panel which, through the code created had had its visibility set to false. This meant that the program would fail to run properly.

What I had to do to fix this problem was to extend the form and seperate all of the panels. I then set the panels in to position using their Location property and then resized the form back to its original size (i.e, big enough to hold one panel). From this point, the program ran perfectly, showing all the panels at the appropriate times.

Another thing I came across was the use of images. I had them set from an absolute path on my memory stick. The problem was that when I handed the assignment in, Rachael wouldn't have access to the pictures for the slide show. I figured that there had to be a way to set the pictures in to the program itself, but I could not see how to do this. I tried putting the pictures into the Resources folder, but I had dragged and dropped and it didn't work when I tried to use Intellisence. I found a very easy to use example for adding pictures to your resource folder written by Craig Cureton, one of the students in the other Cert IV Programming class and this problem was also solved.

I still have two assignments to get done for Programming, the Class Diagram and the Alarm Clock. I'm hoping to have these done by the end of the week.

Friday, May 1, 2009

Methods used in Now function...

Our blog task this week is to list the methods that can be used in the Now function. Our assessment involved using the Now function, but we used it in a very simple way. So Rachael has given us this task to show what other methods can be used.

If you want to display the time in a label for example, you might use something like this:
lblCurrentTime.Text = Now
This will retrieve the current time and date from the computer and display it in the label lblCurrentTime. If you only want to display the time though, you would need to do it like this:
lblCurrentTime.Text = Now.ToString("HH:mm:ss")
This will display the time in Hours, Minutes and Seconds. It will only show the time when the program starts though, it won't keep updating the time to keep it current. If you want it to act like a clock, you need to add a Timer function and put this code in to the function as well.






I have been posting a little bit on this function in recent times, relating to my sleep calculator. What I'm going to do is use this function to create a real, bonafide sleep calculator, but that will have to wait until the workload of assignments has thinned out a little bit.
Anyway, what other methods can be added to the Now function? So far ToString has been added. According to the list in Intellisense, the following can be added as methods to the Now function:
  • Add (AddDays, AddHours, AddMilliseconds, AddMinutes, AddMonths, AddSeconds, AddTicks, AddYears)
  • To (ToString, ToLongTimeString, ToOADate, ToShortDateString, ToShortTimeString, ToUniversalTime, ToBinary, ToFileTime, ToFileTimeUtc, ToLocalTime)
  • TryParse, TryParseExact
  • Compare, CompareTo
  • DaysInMonth
  • Equals
  • From (FromBinary, FromFileTime, FromFileTimeUtc, FromOADate)
  • Get (GetDateTimeFormat, GetHashCode, GetType, GetTypeCode)
  • IsDaylightSavingTime, IsLeapYear
  • Parse, ParseExact
  • ReferenceEquals
  • SpecifyKind
  • Subtract
I spent a couple of hours searching the internet looking for a list like this one. Once I finally used my brain however, I realised that I could find what I needed in Intellisense. I'm not too sure what it is that all of these methods do, but I'm sure we'll be finding out at least some of them in the coming months.