Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Q&A

  1. Why would I want to perform date arithmetic?

    Date arithmetic is useful for determining the exact date (or time) after another period of time goes by. For example, suppose you need to know the exact day that three months from today's date falls on. You cannot just add 3 or 90 (3 times 30 days) to a date value; not only can you not add to a Date datatype, but even if you could, such math doesn't take into account leap years, number of days in the months, and year changes. By using DateAdd() and DatePart(), you can perform such calculations with date values and be assured that the result will fall on a valid date.

  2. If Timer returns the number of seconds since midnight, how can I use Timer to determine how much time has passed for a given task?

    The key to using Timer is to save the value of Timer before the task begins and then save the value of Timer after the task ends. You then can subtract the values to determine how many seconds elapsed between the two tasks. A single Timer reading would not be very beneficial by itself, but the two before and after values can be very helpful indeed.

Share ThisShare This

Informit Network