File IO (Streaming)

Team Fly 

Page 39

        Debug.WriteLine(''Number of hours elapsed is: " + Difference.Hours.ToString)         Debug.WriteLine("Number of minutes elapsed is: " + _ Difference.Minutes.ToString) 

The following sections provide some additional examples that illustrate how to manipulate date and time.

Adding Time

Here's an example of using the AddDays method:

 Dim ti As Date = TimeOfDay 'the current time         Dim da As Date = Today 'the current date         Dim dati As Date = Now 'the current date and time         da = da.AddDays(12) ' add 12 days         Debug.WriteLine("12 days from now is: " & da) 

Similarly, you can use AddMinutes, AddHours, AddSeconds, AddMilliseconds, AddMonths, AddYears, and so on.

Using the Old-Style Double DateTime Data Type

There is an OA conversion method for currency data types and for date data types. (OA stands for Ole Automation, a legacy technology that still keeps popping up.) Here is an example showing how to translate to and from the old double-precision date format:

 Dim dati As Date = Now 'the current date and time Dim da as Date, n As Double n = dati.ToOADate ' translate into double-precision format n = n + 21 ' add three weeks (the integer part is the days) da = Date.FromOADate(n) ' translate the OA style into .NET style Debug.WriteLine(da) 

Use Now, not Today, for these OA-style data types.

Finding Days in a Month

2004 is a leap year. Here's one way to prove it:

 Debug.WriteLine("In the year 2004, February has " & _ Date.DaysInMonth(2004, 2).ToString & " days.") Debug.WriteLine("In the year 2005, February has " & _ Date.DaysInMonth(2005, 2).ToString & " days.") 

File I/O (Streaming)

The classic familiar VB file opening syntax is this:

 Open filepath {For Mode}{options}As {#} filenumber {Len = recordlength} 
Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net