Chapter 14 Scripting Quicktest Professional Page 1Dani Vainstein DotNetFactory Page 1 of 151DOTNETFACTORY ...................
Chapter 14 Scripting Quicktest Professional Page 2Dani Vainstein DotNetFactory Page 2 of 151DateTime.AddSeconds ( Double )...
Chapter 14 Scripting Quicktest Professional Page 3Dani Vainstein DotNetFactory Page 3 of 151DateTime.ToString ( IFormatPro...
Chapter 14 Scripting Quicktest Professional Page 4Dani Vainstein DotNetFactory Page 4 of 151TimeSpan.FromSeconds ( Double ...
Chapter 14 Scripting Quicktest Professional Page 5Dani Vainstein DotNetFactory Page 5 of 151If you want to use a .NET obje...
Chapter 14 Scripting Quicktest Professional Page 6Dani Vainstein DotNetFactory Page 6 of 151"wow!!" I said to my self, nic...
Chapter 14 Scripting Quicktest Professional Page 7Dani Vainstein DotNetFactory Page 7 of 151Fri, 12 Jan 2007 2390$Mon, 12 ...
Chapter 14 Scripting Quicktest Professional Page 8Dani Vainstein DotNetFactory Page 8 of 151The application has hundreds o...
Chapter 14 Scripting Quicktest Professional Page 9Dani Vainstein DotNetFactory Page 9 of 151Str = Str & DateTime.AddMonths...
Chapter 14 Scripting Quicktest Professional Page 10Dani Vainstein DotNetFactory Page 10 of 151DateTime.MaxValue FieldRepre...
Chapter 14 Scripting Quicktest Professional Page 11Dani Vainstein DotNetFactory Page 11 of 151Int32, Int32, Int32, Int32,D...
Chapter 14 Scripting Quicktest Professional Page 12Dani Vainstein DotNetFactory Page 12 of 151).TicksSet dtCustom = DotNet...
Chapter 14 Scripting Quicktest Professional Page 13Dani Vainstein DotNetFactory Page 13 of 151Option ExplicitConst DATE_PA...
Chapter 14 Scripting Quicktest Professional Page 14Dani Vainstein DotNetFactory Page 14 of 151Set myDt = DateTime.SpecifyK...
Chapter 14 Scripting Quicktest Professional Page 15Dani Vainstein DotNetFactory Page 15 of 151ArgumentOutOfRangeException ...
Chapter 14 Scripting Quicktest Professional Page 16Dani Vainstein DotNetFactory Page 16 of 151ArgumentOutOfRangeException ...
Chapter 14 Scripting Quicktest Professional Page 17Dani Vainstein DotNetFactory Page 17 of 151minute The minutes (0 throug...
Chapter 14 Scripting Quicktest Professional Page 18Dani Vainstein DotNetFactory Page 18 of 151"System.DateTime", , year, m...
Chapter 14 Scripting Quicktest Professional Page 19Dani Vainstein DotNetFactory Page 19 of 151DateTime.DateTime(Int32, Int...
Chapter 14 Scripting Quicktest Professional Page 20Dani Vainstein DotNetFactory Page 20 of 151DateTime.DateTime(Int32, Int...
Chapter 14 Scripting Quicktest Professional Page 21Dani Vainstein DotNetFactory Page 21 of 151Set object = DotNetFactory.C...
Chapter 14 Scripting Quicktest Professional Page 22Dani Vainstein DotNetFactory Page 22 of 151Set object = DotNetFactory.C...
Chapter 14 Scripting Quicktest Professional Page 23Dani Vainstein DotNetFactory Page 23 of 151Parameter Descriptionyear Th...
Chapter 14 Scripting Quicktest Professional Page 24Dani Vainstein DotNetFactory Page 24 of 151DayOfYear Gets the day of th...
Chapter 14 Scripting Quicktest Professional Page 25Dani Vainstein DotNetFactory Page 25 of 151DateTime.Day PropertyGets th...
Chapter 14 Scripting Quicktest Professional Page 26Dani Vainstein DotNetFactory Page 26 of 151A DayOfWeek enumerated const...
Chapter 14 Scripting Quicktest Professional Page 27Dani Vainstein DotNetFactory Page 27 of 151DateTime.Hour PropertyGets t...
Chapter 14 Scripting Quicktest Professional Page 28Dani Vainstein DotNetFactory Page 28 of 151Gets a value that indicates ...
Chapter 14 Scripting Quicktest Professional Page 29Dani Vainstein DotNetFactory Page 29 of 151DateTime.Millisecond Propert...
Chapter 14 Scripting Quicktest Professional Page 30Dani Vainstein DotNetFactory Page 30 of 151expressed as the local time....
Chapter 14 Scripting Quicktest Professional Page 31Dani Vainstein DotNetFactory Page 31 of 151A TimeSpan that represents t...
Chapter 14 Scripting Quicktest Professional Page 32Dani Vainstein DotNetFactory Page 32 of 151Starting with the .NET Frame...
Chapter 14 Scripting Quicktest Professional Page 33Dani Vainstein DotNetFactory Page 33 of 151are equal.FromBinaryDeserial...
Chapter 14 Scripting Quicktest Professional Page 34Dani Vainstein DotNetFactory Page 34 of 151ToFileTimeUtcConverts the va...
Chapter 14 Scripting Quicktest Professional Page 35Dani Vainstein DotNetFactory Page 35 of 151Option ExplicitDim saveNow, ...
Chapter 14 Scripting Quicktest Professional Page 36Dani Vainstein DotNetFactory Page 36 of 151Print "Today is --> " & save...
Chapter 14 Scripting Quicktest Professional Page 37Dani Vainstein DotNetFactory Page 37 of 151valueA number of whole and f...
Chapter 14 Scripting Quicktest Professional Page 38Dani Vainstein DotNetFactory Page 38 of 151Set object = instance.AddMon...
Chapter 14 Scripting Quicktest Professional Page 39Dani Vainstein DotNetFactory Page 39 of 151A The fractional part of val...
Chapter 14 Scripting Quicktest Professional Page 40Dani Vainstein DotNetFactory Page 40 of 151This method does not change ...
Chapter 14 Scripting Quicktest Professional Page 41Dani Vainstein DotNetFactory Page 41 of 151Compares this instance to a ...
Chapter 14 Scripting Quicktest Professional Page 42Dani Vainstein DotNetFactory Page 42 of 151Before comparing DateTime ob...
Chapter 14 Scripting Quicktest Professional Page 43Dani Vainstein DotNetFactory Page 43 of 151Set Info = Nothing : Set Dat...
Chapter 14 Scripting Quicktest Professional Page 44Dani Vainstein DotNetFactory Page 44 of 151
Chapter 14 Scripting Quicktest Professional Page 45Dani Vainstein DotNetFactory Page 45 of 151DateTime.Equals ( DateTime )...
Chapter 14 Scripting Quicktest Professional Page 46Dani Vainstein DotNetFactory Page 46 of 151Parameter Descriptiont1 The ...
Chapter 14 Scripting Quicktest Professional Page 47Dani Vainstein DotNetFactory Page 47 of 151ArgumentException - dateData...
Chapter 14 Scripting Quicktest Professional Page 48Dani Vainstein DotNetFactory Page 48 of 151Dim dteNow, DateTimeDim fCre...
Chapter 14 Scripting Quicktest Professional Page 49Dani Vainstein DotNetFactory Page 49 of 151DateTime.GetTimeFormats Meth...
Chapter 14 Scripting Quicktest Professional Page 50Dani Vainstein DotNetFactory Page 50 of 151For nFormat = 0 To july28For...
Chapter 14 Scripting Quicktest Professional Page 51Dani Vainstein DotNetFactory Page 51 of 151A string array where each el...
Chapter 14 Scripting Quicktest Professional Page 52Dani Vainstein DotNetFactory Page 52 of 151A string array where each el...
Chapter 14 Scripting Quicktest Professional Page 53Dani Vainstein DotNetFactory Page 53 of 151DateTime.GetTimeFormats ( Ch...
Chapter 14 Scripting Quicktest Professional Page 54Dani Vainstein DotNetFactory Page 54 of 151http://msdn2.microsoft.com/e...
Chapter 14 Scripting Quicktest Professional Page 55Dani Vainstein DotNetFactory Page 55 of 151A 32-bit signed integer hash...
Chapter 14 Scripting Quicktest Professional Page 56Dani Vainstein DotNetFactory Page 56 of 151DateTime.IsLeapYear ( Intege...
Chapter 14 Scripting Quicktest Professional Page 57Dani Vainstein DotNetFactory Page 57 of 151Set tSpan = DotNetFactory.Cr...
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Scripting qtp   ch14 - dot netfactory
Upcoming SlideShare
Loading in …5
×

Scripting qtp ch14 - dot netfactory

809 views

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
809
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Scripting qtp ch14 - dot netfactory

  1. 1. Chapter 14 Scripting Quicktest Professional Page 1Dani Vainstein DotNetFactory Page 1 of 151DOTNETFACTORY .................................................................................................................... 4THE DOTNETFACTORY OBJECT................................................................................................ 4CREATEINSTANCE METHOD.................................................................................................. 4QTP DOTNETFACTORY ............................................................................................................. 5SYSTEM.DATETIME STRUCTURE............................................................................................... 9SYSTEM.DATETIME FIELDS................................................................................................... 9DateTime.MaxValue Field............................................................................................ 10DateTime.MinValue Field ............................................................................................ 10SYSTEM.DATETIME CONTRUCTORS.................................................................................... 10DateTime.DateTime( int64 ) Constructor..................................................................... 11DateTime.DateTime ( int64, DateTimeKind ) Constructor .......................................... 12DateTime.DateTime(Int32, Int32, Int32) Constructor.................................................. 14DateTime.DateTime(Int32, Int32, Int32, Calendar) Constructor.................................. 15DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32) Constructor................... 16DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Calendar ) Constructor . 17DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind )Constructor.................................................................................................................... 19DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32 ) Constructor ....... 20DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar )Constructor.................................................................................................................... 20DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind )Constructor.................................................................................................................... 21DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar,DateTimeKind ) Constructor......................................................................................... 22DATETIME PROPERTIES....................................................................................................... 23DateTime.Date Property ............................................................................................... 24DateTime.Day Property ................................................................................................ 25DateTime.DayOfWeek Property................................................................................... 25DateTime.DayOfYear Property .................................................................................... 26DateTime.Hour Property............................................................................................... 27DateTime.Kind Property............................................................................................... 27DateTime.Millisecond Property.................................................................................... 29DateTime.Minute Property ........................................................................................... 29DateTime.Month Property ............................................................................................ 29DateTime.Now Property ............................................................................................... 29DateTime.Second Property ........................................................................................... 30DateTime.Ticks Property .............................................................................................. 30DateTime.TimeOfDay Property.................................................................................... 30DateTime.Today Property............................................................................................. 31DateTime.UtcNow Property ......................................................................................... 31DateTime.Year Property ............................................................................................... 32DATETIME METHODS.......................................................................................................... 32DateTime.Add ( TimeSpan ) Method ........................................................................... 34DateTime.AddDays ( Double ) Method........................................................................ 35DateTime.AddHours ( Double ) Method ...................................................................... 36DateTime.AddMilliseconds ( Double ) Method ........................................................... 36DateTime.AddMinutes ( Double ) Method................................................................... 37DateTime.AddMonths ( Integer ) Method .................................................................... 37
  2. 2. Chapter 14 Scripting Quicktest Professional Page 2Dani Vainstein DotNetFactory Page 2 of 151DateTime.AddSeconds ( Double ) Method................................................................... 38DateTime.AddTicks ( Long ) Method .......................................................................... 39DateTime.AddYears ( Integer ) Method ....................................................................... 39DateTime.Compare ( DateTime, DateTime ) Method .................................................. 40DateTime.CompareTo ( DateTime ) Method................................................................ 40DateTime.DaysInMonth ( Integer, Integer ) Method.................................................... 41DateTime.Equals ( DateTime ) Method........................................................................ 45DateTime.Equals ( DateTime, DateTime ) Method...................................................... 45DateTime.FromBinary ( Long ) Method....................................................................... 46DateTime.FromFileTime ( Long ) Method................................................................... 47DateTime.FromFileTimeUtc ( Long ) Method ............................................................. 48DateTime.GetTimeFormats Method............................................................................. 49DateTime.GetTimeFormats () Method ......................................................................... 49DateTime.GetTimeFormats ( Char ) Method................................................................ 50DateTime.GetTimeFormats ( IFormatProvider ) Method............................................. 51DateTime.GetTimeFormats ( Char, IFormatProvider ) Method................................... 53DateTime.GetHashCode () Method .............................................................................. 54DateTime.GetTypeCode () Method .............................................................................. 55DateTime.IsDaylightSavingTime () Method ................................................................ 55DateTime.IsLeapYear ( Integer ) Method..................................................................... 56DateTime.op_Addition ( DateTime, TimeSpan ) Method ............................................ 56DateTime.op_Equality ( DateTime, DateTime ) Method ............................................. 57DateTime.op_GreaterThan ( DateTime, DateTime ) Method....................................... 57DateTime.op_GreaterThanOrEqual ( DateTime, DateTime ) Method ......................... 58DateTime.op_Inequality ( DateTime, DateTime ) Method........................................... 58DateTime.op_LessThan ( DateTime, DateTime ) Method ........................................... 59DateTime.op_LessThanOrEqual ( DateTime, DateTime ) Method.............................. 59DateTime.op_Subtraction Method................................................................................ 59DateTime.op_Subtraction ( DateTime, DateTime ) Method ........................................ 59DateTime.op_Subtraction ( DateTime, TimeSpan ) Method........................................ 61DateTime.Parse Method................................................................................................ 61DateTime.Parse ( String ) Method ................................................................................ 62DateTime.Parse ( String, IFormatProvider ) Method.................................................... 63DateTime.Parse ( String, IFormatProvider, DateTimeStyles ) Method........................ 64DateTime.ParseExact Method....................................................................................... 65DateTime.ParseExact ( String, String, IFormatProvider ) Method............................... 66DateTime.ParseExact ( String, String, IFormatProvider, DateTimeStyles ) Method ... 67DateTime.ParseExact ( String, String[], IFormatProvider, DateTimeStyles ) Method. 68DateTime.SpecifyKind ( DateTime, DateTimeKind ) Method..................................... 70DateTime.Subtract Method........................................................................................... 71DateTime.Subtract ( DateTime ) Method ..................................................................... 71DateTime.Subtract ( TimeSpan ) Method..................................................................... 72DateTime.ToFileTime () Method.................................................................................. 73DateTime.ToFileTimeUtc () Method............................................................................ 74DateTime.ToLocalTime () Method............................................................................... 74DateTime.ToLongDateString () Method....................................................................... 75DateTime.ToLongTimeString () Method...................................................................... 77DateTime.ToShortDateString () Method ...................................................................... 77DateTime.ToShortTimeString () Method ..................................................................... 78DateTime.ToString Method .......................................................................................... 79DateTime.ToString () Method ...................................................................................... 79
  3. 3. Chapter 14 Scripting Quicktest Professional Page 3Dani Vainstein DotNetFactory Page 3 of 151DateTime.ToString ( IFormatProvider ) Method.......................................................... 82DateTime.ToString ( String ) Method........................................................................... 83DateTime.ToString ( String, IFormatProvider ) Method .............................................. 85DateTime.ToUniversalTime () Method ........................................................................ 86DateTime.TryParse Method.......................................................................................... 86DateTime.TryParse ( String, DateTime ) Method......................................................... 87DateTime.TryParse ( String, IFormatProvider, DateTimeStyles, DateTime ) Method 88DateTime.TryParseExact Method................................................................................. 89DateTime.TryParse ( String, String, IFormatProvider, DateTimeStyles, DateTime )Method .......................................................................................................................... 89DateTime.TryParse ( String, String[], IFormatProvider, DateTimeStyles, DateTime )Method .......................................................................................................................... 90SYSTEM.TIMESPAN STRUCTURE ............................................................................................. 92SYSTEM.TIMESPAN CONTRUCTORS .................................................................................... 92DateTime.TimeSpan ( int64 ) Constructor.................................................................... 92DateTime.TimeSpan ( int32, int32, int32 ) Constructor ............................................... 94DateTime.TimeSpan ( int32, int32, int32, int32 ) Constructor..................................... 95DateTime.TimeSpan ( int32, int32, int32, int32, int32 ) Constructor........................... 96SYSTEM.TIMESPAN FIELDS ................................................................................................. 98TimeSpan.MaxValue Field ........................................................................................... 98TimeSpan.MinValue Field............................................................................................ 99TimeSpan.TicksPerDay Field ....................................................................................... 99TimeSpan.TicksPerHour Field...................................................................................... 99TimeSpan.TicksPerMillisecond Field......................................................................... 100TimeSpan.TicksPerMinute Field ................................................................................ 100TimeSpan.TicksPerSecond Field ................................................................................ 100TimeSpan.Zero Field................................................................................................... 100TIMESPAN PROPERTIES ..................................................................................................... 100TimeSpan.Days Property ............................................................................................ 101TimeSpan.Hours Property........................................................................................... 103TimeSpan.Milliseconds Property................................................................................ 104TimeSpan.Minutes Property ....................................................................................... 104TimeSpan.Seconds Property ....................................................................................... 105TimeSpan.Ticks Property............................................................................................ 105TimeSpan.TotalDays Property.................................................................................... 105TimeSpan.TotalHours Property .................................................................................. 106TimeSpan.TotalMilliseconds Property........................................................................ 106TimeSpan.TotalMinutes Property............................................................................... 107TimeSpan.TotalSeconds Property............................................................................... 107TIMESPAN METHODS ........................................................................................................ 107TimeSpan.Add ( TimeSpan ) Method......................................................................... 109DateTime.Compare ( TimeSpan, TimeSpan ) Method ............................................... 110TimeSpan.CompareTo ( TimeSpan ) Method............................................................. 112TimeSpan.Duration ( ) Method................................................................................... 113TimeSpan.Equals Method........................................................................................... 114TimeSpan.Equals ( TimeSpan ) Method..................................................................... 114TimeSpan.Equals ( TimeSpan, TimeSpan ) Method................................................... 115TimeSpan.FromDays ( Double ) Method.................................................................... 115TimeSpan.FromHours ( Double ) Method.................................................................. 117TimeSpan.FromMilliseconds ( Double ) Method ....................................................... 119TimeSpan.FromMinutes ( Double ) Method............................................................... 121
  4. 4. Chapter 14 Scripting Quicktest Professional Page 4Dani Vainstein DotNetFactory Page 4 of 151TimeSpan.FromSeconds ( Double ) Method............................................................... 122TimeSpan.FromTicks ( Long ) Method ...................................................................... 123TimeSpan.GetHashCode ( ) Method........................................................................... 124TimeSpan.Negate ( ) Method...................................................................................... 125TimeSpan.op_Addition ( TimeSpan, TimeSpan ) Method ......................................... 126TimeSpan.op_Equality ( TimeSpan, TimeSpan ) Method.......................................... 128TimeSpan.op_GreaterThan ( TimeSpan, TimeSpan ) Method ................................... 130TimeSpan.op_GreaterThanOrEqual ( TimeSpan, TimeSpan ) Method...................... 130TimeSpan.op_Inequality ( TimeSpan, TimeSpan ) Method ....................................... 130TimeSpan.op_LessThan ( TimeSpan, TimeSpan ) Method........................................ 131TimeSpan.op_LessThanOrEqual ( TimeSpan, TimeSpan ) Method .......................... 131TimeSpan.op_Subtraction ( TimeSpan, TimeSpan ) Method..................................... 132TimeSpan.op_UnaryNegation ( ) Method................................................................... 132TimeSpan.op_UnaryPlus ( ) Method .......................................................................... 133TimeSpan.Parse ( String ) Method.............................................................................. 133TimeSpan.Subtract ( TimeSpan ) Method................................................................... 135TimeSpan.ToString ( String ) Method ........................................................................ 136TimeSpan.TryParse ( String, TimeSpan ) Method...................................................... 136DOTNETFACTORY TASKS ...................................................................................................... 137WORLD CALENDARS ......................................................................................................... 137SYSTEM.COLLECTIONS.ARRAYLIST ................................................................................. 140CALLCHAIN USING SYSTEM.COLLECTIONS.STACK .......................................................... 141APPENDIX 14.A – ENUMERATIONS ........................................................................................ 144System.DateTimeKind Enumeration .......................................................................... 145System.DayOfWeek Enumeration .............................................................................. 145Standard DateTime Format Strings............................................................................. 145Custom DateTime Format Strings .............................................................................. 146System.Globalization.DateTimeStyles Enumeration.................................................. 150DotNetFactoryThe DotNetFactory ObjectEnables you to create an instance of a .NET object, and access its methods andproperties.You can use this object to access the static methods and properties of a class thatdoes not have an instance constructor, for example, System.Environment, as well asa class that does.CreateInstance MethodReturns a COM interface for a .NET object
  5. 5. Chapter 14 Scripting Quicktest Professional Page 5Dani Vainstein DotNetFactory Page 5 of 151If you want to use a .NET object as an argument for a method in QuickTest, youmust first create a COM interface for the .NET object using the CreateInstancemethod. Then you pass that interface as the method argument.Set var_CreateInstance =DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])Parameter DescriptionTypeNameThe full name of the object type, for example,System.Windows.Forms.Form.AssemblyOptional. If the assembly is preloaded in the registry, you do not need toenter it. Otherwise, you should enter the full path name, for example,System.Windows.Forms. If you want to create an instance of a type in theGAC (Global Assembly Cache), you can enter the short name, for example,Forms.Note: If you do not pass this argument, QuickTest assumes that theassembly is resident in memory. If QuickTest does not find the assembly,an error message is displayed during the run session.argsOptional. The required arguments, if any, for the specified TypeNameand/or AssemblyA Variant value. Returns the defined instance of the .NET object.QTP DotNetFactoryWhen QTP version 9.0 was released. I have noticed that a new utility object was added,theDotNetFactory object.Since, that period of time, I was working on a web application, I thought myself , thatDotNetFactory is a utility to work with .NET applications, like the DOT.NET ExtensibilityIn QTP Version 9.2, I so the following example in the QTP helpSet var_CreateInstance = _DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")var_CreateInstance.Showwait 2var_CreateInstance.CloseAnd alsoSet var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")msgbox var_CreateInstance.CurrentDirectoryThe first example display an empty windows form. I started to think, why I need to displaya form , during a test run. The second example catch my eye, and when I tried it in qtp, Igot the following result :
  6. 6. Chapter 14 Scripting Quicktest Professional Page 6Dani Vainstein DotNetFactory Page 6 of 151"wow!!" I said to my self, nice to know that I can have every single environment value ofthe system, especially SystemDirectory property. The others values, can be retrieved usingstandard VBScript objects and QTP Environment object. So, again … I did not paid attentionand full research for the dot.net factory.One month later, I add an issue when testing a financial application.The application ( web based ) shows the interests to pay for each month. Because theapplication is a bank system application, I cant show screenshots. But a web table wasdisplayed in the following format :Date AmountTue, 12 Sep 2006 2500$Thu, 12 Oct 2006 2490$Sun, 12 Nov 2006 2475$Tue, 12 Dec 2006 2466$
  7. 7. Chapter 14 Scripting Quicktest Professional Page 7Dani Vainstein DotNetFactory Page 7 of 151Fri, 12 Jan 2007 2390$Mon, 12 Feb 2007 2285$My problem here, were the dates. VBScript doesnt able to convert formats, to the specificformat I needed, and beside this, any user can change the display format to : mm/dd/yyyyor mmddyy or ddmmyy etc.dteDate = Cdate( "Tue, 12 Sep 2006" )Because the CDate conversion error, in pure vbscript I need a function like thefollowsOption ExplicitDim arr1, arr2, MyDate, nMonth, dteDateMyDate = Browser("B").Page("P").WebTable("rates").GetCellData(1,1)arr1 = Split( MyDate, "," )arr2 = Split( arr1(1), " " )Select Case arr2(2)Case "Jan" : nMonth = 1Case "Feb" : nMonth = 2Case "Mar" : nMonth = 3Case "Apr" : nMonth = 4Case "May" : nMonth = 5Case "Jun" : nMonth = 6Case "Jul" : nMonth = 7Case "Aug" : nMonth = 8Case "Sep" : nMonth = 9Case "Oct" : nMonth = 10Case "Nov" : nMonth = 11Case "Dec" : nMonth = 12End SelectdteDate = DateSerial(arr2(3), nMonth, arr2(1))msgbox dteDateThis process only to retrieve the first date, than, I have to use the DateAdd function, andanother function to convert the new date, to the desired format.As you can see, this is a lot of work, beside, that the user can change the formats.
  8. 8. Chapter 14 Scripting Quicktest Professional Page 8Dani Vainstein DotNetFactory Page 8 of 151The application has hundreds of date fields, and dates fields are very critical for theapplication.From this moment I start to make a research, to find a simplest and elegant solution.I found the System.DateTime object in the MSDN DOT.NET help, and rememberimmediately of the QTP example about the System.Environment objectSo I tried the follow :Option ExplicitDim DateTimeSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )A little more research, using the MSDN help I got the ultimate date handling functionalityOption ExplicitDim DateTime, SystemDateTime, i, StrSet SystemDateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set DateTime = SystemDateTime.Parse( "Tue, 12 Sep 2006" )For i = 1 To 12
  9. 9. Chapter 14 Scripting Quicktest Professional Page 9Dani Vainstein DotNetFactory Page 9 of 151Str = Str & DateTime.AddMonths(i).ToString( "ddd, dd MMM yyyy" ) & vbNewLineNextMsgbox StrSet SystemDateTime = Nothing : Set DateTime = NothingSo, the conclusion of all my research, is that you can use almost any DOT.NET objectsupported by your Dot.Net Framework ( today is version 3 ) , so this chapter ofDotNetFactory will demonstrate only the System.DateTime and System.TimeSpanclasses. In some examples I use The System.Text.TextBuilder class,System.Globalization.CultureInfo class, System.DateTimeKind Enumerator,System.Globalization.Calendar and moreSystem.DateTime StructureRepresents an instant in time, typically expressed as a date and time of day.The DateTime value type represents dates and times with values ranging from 12:00:00midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December31, 9999 A.D. (C.E.)Time values are measured in 100-nanosecond units called ticks, and a particular date is thenumber of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in theGregorianCalendar calendar. For example, a ticks value of 31241376000000000Lrepresents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value isalways expressed in the context of an explicit or default calendar.More information can be found in the following link :http://msdn2.microsoft.com/en-us/library/system.datetime.aspxSystem.DateTime FieldsName DescriptionMaxValue Represents the largest possible value of DateTime. This field is read-only.MinValue Represents the smallest possible value of DateTime. This field is read-only
  10. 10. Chapter 14 Scripting Quicktest Professional Page 10Dani Vainstein DotNetFactory Page 10 of 151DateTime.MaxValue FieldRepresents the largest possible value of DateTime. This field is read-onlyThe value of this constant is equivalent to 00:00:00.0000000, January 1, 0001.DateTime.MinValue FieldRepresents the smallest possible value of DateTime. This field is read-onlyThe value of this constant is equivalent to 23:59:59.9999999, December 31, 9999,exactly one 100-nanosecond tick before 00:00:00, January 1, 10000.System.DateTime ContructorsInitializes a new instance of the DateTime structure.Name DescriptionDateTime (Int64)Initializes a new instance of the DateTime structureto a specified number of ticks.DateTime (Int64, DateTimeKind)Initializes a new instance of the DateTime structureto a specified number of ticks and to CoordinatedUniversal Time (UTC) or local time.DateTime (Int32, Int32, Int32)Initializes a new instance of the DateTime structureto the specified year, month, and day.DateTime (Int32, Int32, Int32,Calendar)Initializes a new instance of the DateTime structureto the specified year, month, and day for thespecified calendar.DateTime (Int32, Int32, Int32,Int32, Int32, Int32)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute, andsecond.DateTime (Int32, Int32, Int32,Int32, Int32, Int32, Calendar)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute, andsecond for the specified calendar.DateTime (Int32, Int32, Int32,Int32, Int32, Int32, DateTimeKind)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute,second, and Coordinated Universal Time (UTC) orlocal time.DateTime (Int32, Int32, Int32,Int32, Int32, Int32, Int32)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute,second, and millisecond.DateTime (Int32, Int32, Int32,Int32, Int32, Int32, Int32,Calendar)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute,second, and millisecond for the specified calendar.DateTime (Int32, Int32, Int32, Initializes a new instance of the DateTime structure
  11. 11. Chapter 14 Scripting Quicktest Professional Page 11Dani Vainstein DotNetFactory Page 11 of 151Int32, Int32, Int32, Int32,DateTimeKind)to the specified year, month, day, hour, minute,second, millisecond, and Coordinated Universal Time(UTC) or local time.DateTime (Int32, Int32, Int32,Int32, Int32, Int32, Int32,Calendar, DateTimeKind)Initializes a new instance of the DateTime structureto the specified year, month, day, hour, minute,second, millisecond, and Coordinated Universal Time(UTC) or local time for the specified calendar.DateTime.DateTime( int64 ) ConstructorInitializes a new instance of the DateTime structure to a specified number of ticks.Set object = DotNetFactory.CreateInstance( "System.DateTime", , ticks )Parameter Descriptionticks A date and time expressed in 100-nanosecond units.System.DateTime objectThe Kind property is initialized to Unspecified.ArgumentOutOfRangeException - ticks is less than MinValue or greater thanMaxValue.The following code example demonstrates one of the DateTime constructorsOption ExplicitDim SDT, dtMax, dtMin, dtCustomDim formatDim SB, CI, ticksformat = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}{3}"Set SDT = DotNetFactory.CreateInstance( "System.DateTime" ) ** Create a DateTime for the maximum date and time using ticksSet dtMax = DotNetFactory.CreateInstance( "System.DateTime", , SDT.MaxValue.Ticks ) ** Create a DateTime for the minimum date and time using ticks.Set dtMin = DotNetFactory.CreateInstance( "System.DateTime", , SDT.MinValue.Ticks ) ** Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a calendar based on the "en-US" culture, and ticks.Set CI = DotNetFactory.CreateInstance( _"System.Globalization.CultureInfo", _"System", "en-US", False _)Set ticks = DotNetFactory.CreateInstance( _"System.DateTime", ,1979, 7, 28, 22, 35, 5, CI.Calendar _
  12. 12. Chapter 14 Scripting Quicktest Professional Page 12Dani Vainstein DotNetFactory Page 12 of 151).TicksSet dtCustom = DotNetFactory.CreateInstance( "System.DateTime", , ticks ) ** ReportingSet SB = DotNetFactory.CreateInstance( "System.Text.StringBuilder" )SB.AppendFormat format, 1, "maximum", dtMax, vbNewLineSB.AppendFormat format, 2, "minimum", dtMin, vbNewLineSB.AppendFormat format, 3, "custom", dtCustom, vbNewLineSB.AppendFormat "The custom datetime is created from {0:N0} ticks.", ticksMsgbox SB.ToString(), vbOkOnly, "DateTime( ticks )" ** CleaningSet SB = Nothing : Set CI = NothingSet dtCustom = Nothing : Set ticks = NothingSet dtMin = Nothing : Set dtMax = Nothing : Set SDT = NothingDateTime.DateTime ( int64, DateTimeKind ) ConstructorInitializes a new instance of the DateTime structure to a specified number of ticks andto Coordinated Universal Time (UTC) or local time.Set object =DotNetFactory.CreateInstance( "System.DateTime", , ticks, kind )Parameter Descriptionticks A date and time expressed in 100-nanosecond units.kindOne of the DateTimeKind values that indicates whether ticks specifies alocal time, Coordinated Universal Time (UTC), or neither.System.DateTime objectArgumentOutOfRangeException - ticks is less than MinValue or greater thanMaxValue.ArgumentException - Kind is not one of the DateTimeKind values.The following code example uses the SpecifyKind method to demonstrate how the Kindproperty influences the ToLocalTime and ToUniversalTime conversion methods.
  13. 13. Chapter 14 Scripting Quicktest Professional Page 13Dani Vainstein DotNetFactory Page 13 of 151Option ExplicitConst DATE_PATTERN = "M/d/yyyy hh:mm:ss tt"Dim DateTime, saveNow, saveUtcNow, myDtDim DateTimeKindPrivate Sub DisplayNow( ByVal title, ByRef inputDt )Dim dtStringdtString = inputDt.ToString( DATE_PATTERN )Print title & " " & dtString & ", Kind = " & inputDt.KindEnd SubPublic Sub Display( ByVal title, ByRef inputDt )Dim dispDt, dtStringSet dispDt = inputDt ** Display the original DateTime.dtString = dispDt.ToString( DATE_PATTERN )Print title & " " & dtString & ", Kind = " & dispDt.Kind ** Convert inputDt to local time and display the result. ** If inputDt.Kind is DateTimeKind.Utc, the conversion is performed. ** If inputDt.Kind is DateTimeKind.Local, the conversion is not performed. ** If inputDt.Kind is DateTimeKind.Unspecified, the conversion is ** performed as if inputDt was universal time.Set dispDt = inputDt.ToLocalTime()dtString = dispDt.ToString( DATE_PATTERN )Print "ToLocalTime: " & dtString & ", Kind = " & dispDt.Kind ** Convert inputDt to universal time and display the result. ** If inputDt.Kind is DateTimeKind.Utc, the conversion is not performed. ** If inputDt.Kind is DateTimeKind.Local, the conversion is performed. ** If inputDt.Kind is DateTimeKind.Unspecified, the conversion is ** performed as if inputDt was local time.Set dispDt = inputDt.ToUniversalTime()dtString = dispDt.ToString( DATE_PATTERN )Print "ToUniversalTime: " & dtString & ", Kind = " & dispDt.Kind & vbNewLineEnd Sub DisplaySet DateTime = DotNetFactory.CreateInstance( "System.DateTime" ) ** Get the date and time for the current moment, adjusted to the local time zone.Set saveNow = DateTime.Now ** Get the date and time for the current moment expressed as coordinated universal time (UTC).Set saveUtcNow = DateTime.UtcNow ** Display the value and Kind property of the current moment expressed as UTC and local time.Call DisplayNow( "UtcNow: ..........", saveUtcNow )Call DisplayNow( "Now: .............", saveNow ) ** Change the Kind property of the current moment to DateTimeKind.Utc and display the result.Set DateTimeKind = DotNetFactory.CreateInstance( "System.DateTimeKind" )
  14. 14. Chapter 14 Scripting Quicktest Professional Page 14Dani Vainstein DotNetFactory Page 14 of 151Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Utc )Call Display( "Utc: .............", myDt ) ** Change the Kind property of the current moment to DateTimeKind.Local and display the result.Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Local )Call Display( "Local: ...........", myDt ) ** Change the Kind property of the current moment to DateTimeKind.Unspecified and display the result.Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Unspecified )Call Display( "Unspecified: .....", myDt )Set myDt = Nothing : Set DateTimeKind = Nothing : Set DateTime = NothingSet saveNow = Nothing : Set saveUtcNow = NothingDateTime.DateTime(Int32, Int32, Int32) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, andday.Set object =DotNetFactory.CreateInstance( "System.DateTime", , year, month, day )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).System.DateTime object
  15. 15. Chapter 14 Scripting Quicktest Professional Page 15Dani Vainstein DotNetFactory Page 15 of 151ArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.ArgumentException - The specified parameters evaluate to less than MinValue ormore than MaxValue.The following code example uses the SpecifyKind method to demonstrate how the Kindproperty influences the ToLocalTime and ToUniversalTime conversion methods.Option ExplicitDim DateTimeSet DateTime = DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28)MsgBox DateTime.ToString()Set DateTime = NothingDateTime.DateTime(Int32, Int32, Int32, Calendar)ConstructorInitializes a new instance of the DateTime structure to the specified year, month, andday for the specified calendar.Set object = DotNetFactory.CreateInstance("System.DateTime", , year, month, day, calendar )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).Day The day (1 through the number of days in month).calendar The Calendar that applies to this DateTime.System.DateTime objectArgumentNullException - calendar is a null reference (Nothing in Visual Basic).
  16. 16. Chapter 14 Scripting Quicktest Professional Page 16Dani Vainstein DotNetFactory Page 16 of 151ArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.ArgumentException - The specified parameters evaluate to less than MinValue ormore than MaxValue.The time of day for the resulting DateTime is midnight (00:00:00). The Kindproperty is initialized to UnspecifiedThe allowable values for year, month, and day depend on calendar. An exception isthrown if the specified date and time cannot be expressed using calendar.The System.Globalization namespace provides several calendars includingGregorianCalendar and JulianCalendar.The following code example uses the SpecifyKind method to demonstrate how the Kindproperty influences the ToLocalTime and ToUniversalTime conversion methods.Option ExplicitDim DateTimeSet DateTime = DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28)MsgBox DateTime.ToString()Set DateTime = NothingDateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, and second.Set object = DotNetFactory.CreateInstance("System.DateTime", , year, month, day, hour, minute, second )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).
  17. 17. Chapter 14 Scripting Quicktest Professional Page 17Dani Vainstein DotNetFactory Page 17 of 151minute The minutes (0 through 59).second The seconds (0 through 59).System.DateTime objectArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.ArgumentException - The specified parameters evaluate to less than MinValue ormore than MaxValue.The Kind property is initialized to Unspecified.The following code example demonstrates one of the DateTime constructors.Option ExplicitDim DateTimeSet DateTime = _DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28, 12, 23, 32 )Print DateTime.ToStringPrint DateTime.ToString( "F" )Print DateTime.ToString( "R" )Print DateTime.ToString( "G" )Set DateTime = NothingDateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, Calendar ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, and second for the specified calendar.Set object = DotNetFactory.CreateInstance(
  18. 18. Chapter 14 Scripting Quicktest Professional Page 18Dani Vainstein DotNetFactory Page 18 of 151"System.DateTime", , year, month, day, hour, minute, second, calendar )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).calendar The Calendar that applies to this DateTime.System.DateTime objectArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.ArgumentException - The specified parameters evaluate to less than MinValue ormore than MaxValue.ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).The Kind property is initialized to Unspecified.The allowable values for year, month, and day depend on calendar. An exception isthrown if the specified date and time cannot be expressed using calendar.The System.Globalization namespace provides several calendars includingGregorianCalendar and JulianCalendar.The following code example demonstrates one of the DateTime constructors.Option ExplicitConst HEBREW_CAL = "System.Globalization.HebrewCalendar"Dim Datetime, calSet cal = DotNetFactory.CreateInstance( HEBREW_CAL, "System" )Set DateTime = DotNetFactory.CreateInstance( _"System.DateTime", , 5767, 3, 14, 4, 10, 5, cal )MsgBox DateTime.ToString( "F" )Set DateTime = Nothing: Set cal = Nothing
  19. 19. Chapter 14 Scripting Quicktest Professional Page 19Dani Vainstein DotNetFactory Page 19 of 151DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, DateTimeKind ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, second, and Coordinated Universal Time (UTC) or local time.Set object = DotNetFactory.CreateInstance("System.DateTime", , year, month, day, hour, minute, second, kind )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).kindOne of the DateTimeKind values that indicates whether year, month,day, hour, minute and second specify a local time, CoordinatedUniversal Time (UTC), or neither.System.DateTime objectArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.ArgumentExceptionThe specified parameters evaluate to less than MinValue or more thanMaxValue.Kind is not one of the DateTimeKind values.
  20. 20. Chapter 14 Scripting Quicktest Professional Page 20Dani Vainstein DotNetFactory Page 20 of 151DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, Int32 ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, second and millisecondSet object =DotNetFactory.CreateInstance( "System.DateTime", , _year, month, day, hour, minute, second, millisecond )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).millisecond The milliseconds (0 through 999).System.DateTime objectArgumentOutOfRangeException.year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.millisecond is less than 0 or greater than 999.ArgumentExceptionThe specified parameters evaluate to less than MinValue or more thanMaxValue.DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, Int32, Calendar ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, second, and millisecond for the specified calendar.
  21. 21. Chapter 14 Scripting Quicktest Professional Page 21Dani Vainstein DotNetFactory Page 21 of 151Set object = DotNetFactory.CreateInstance( "System.DateTime", , _year, month, day, hour, minute, second, millisecond, calendar )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).millisecond The milliseconds (0 through 999).calendar The Calendar that applies to this DateTime.System.DateTime objectArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.millisecond is less than 0 or greater than 999.ArgumentException - The specified parameters evaluate to less than MinValue ormore than MaxValue.ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).The Kind property is initialized to Unspecified.The allowable values for year, month, and day depend on calendar. An exception isthrown if the specified date and time cannot be expressed using calendar.The System.Globalization namespace provides several calendars includingGregorianCalendar and JulianCalendar.DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, Int32, DateTimeKind ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or localtime.
  22. 22. Chapter 14 Scripting Quicktest Professional Page 22Dani Vainstein DotNetFactory Page 22 of 151Set object = DotNetFactory.CreateInstance( "System.DateTime", , _year, month, day, hour, minute, second, millisecond, kind )Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).millisecond The milliseconds (0 through 999).kindOne of the DateTimeKind values that indicates whether year, month,day, hour, minute, second, and millisecond specify a local time,Coordinated Universal Time (UTC), or neither.System.DateTime objectArgumentOutOfRangeException .year is less than 1 or greater than 9999month is less than 1 or greater than 12.day is less than 1 or greater than the number of days in month.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.millisecond is less than 0 or greater than 999.ArgumentExceptionThe specified parameters evaluate to less than MinValue or more thanMaxValue.Kind is not one of the DateTimeKind values.DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,Int32, Int32, Calendar, DateTimeKind ) ConstructorInitializes a new instance of the DateTime structure to the specified year, month, day,hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or localtime for the specified calendar.Set object = DotNetFactory.CreateInstance( "System.DateTime", , _year, month, day, hour, minute, second, millisecond, calendar, kind )
  23. 23. Chapter 14 Scripting Quicktest Professional Page 23Dani Vainstein DotNetFactory Page 23 of 151Parameter Descriptionyear The year (1 through 9999).month The month (1 through 12).day The day (1 through the number of days in month).hour The hours (0 through 23).minute The minutes (0 through 59).second The seconds (0 through 59).millisecond The milliseconds (0 through 999).calendar The Calendar object that applies to this DateTime.kindOne of the DateTimeKind values that indicates whether year, month,day, hour, minute, second, and millisecond specify a local time,Coordinated Universal Time (UTC), or neither.System.DateTime objectArgumentOutOfRangeException .year is not in the range supported by calendar.month is less than 1 or greaterthan 12.month is less than 1 or greater than the number of months in calendar.day is less than 1 or greater than the number of days in month.hour is less than0 or greater than 23.hour is less than 0 or greater than 23.minute is less than 0 or greater than 59.second is less than 0 or greater than 59.millisecond is less than 0 or greater than 999.ArgumentExceptionThe specified parameters evaluate to less than MinValue or more than MaxValue.kind is not one of the DateTimeKind values.ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).The allowable values for year, month, and day parameters depend on the calendarparameter. An exception is thrown if the specified date and time cannot beexpressed using calendar.The System.Globalization namespace provides several calendars includingGregorianCalendar and JulianCalendar.DateTime PropertiesName DescriptionDate Gets the date component of this instance.Day Gets the day of the month represented by this instance.DayOfWeek Gets the day of the week represented by this instance.
  24. 24. Chapter 14 Scripting Quicktest Professional Page 24Dani Vainstein DotNetFactory Page 24 of 151DayOfYear Gets the day of the year represented by this instance.Hour Gets the hour component of the date represented by this instance.KindGets a value that indicates whether the time represented by this instance isbased on local time, Coordinated Universal Time (UTC), or neither.Millisecond Gets the milliseconds component of the date represented by this instance.Minute Gets the minute component of the date represented by this instance.Month Gets the month component of the date represented by this instance.NowGets a DateTime object that is set to the current date and time on thiscomputer, expressed as the local time.Second Gets the seconds component of the date represented by this instance.Ticks Gets the number of ticks that represent the date and time of this instance.TimeOfDay Gets the time of day for this instance.Today Gets the current date.UtcNowGets a DateTime object that is set to the current date and time on thiscomputer, expressed as the Coordinated Universal Time (UTC).Year Gets the year component of the date represented by this instance.DateTime.Date PropertyGets the date component of this instance.object.DateA new DateTime with the same date as this instance, and the time value set to 12:00:00midnight (00:00:00).The following example returns the Date value of Now methodOption ExplicitDim DateTimeDim oToday, oFutureSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set oToday = DateTime.Today()Set oFuture = oToday.AddDays( 7 )Print "Today : " & oToday.Date()Print "Future + 7 : " & oFuture.Date() ** Cleaning objectsSet DateTime = NothingSet oToday = Nothing : Set oFuture = Nothing
  25. 25. Chapter 14 Scripting Quicktest Professional Page 25Dani Vainstein DotNetFactory Page 25 of 151DateTime.Day PropertyGets the day of the month represented by this instance.Value = object.DateThe day component, expressed as a value between 1 and 31.The following example returns the Date value of Now methodOption ExplicitDim DateTimeDim oToday, oFutureSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set oToday = DateTime.Today()Set oFuture = oToday.AddHours( 24 )Print "Today : " & oToday.DayPrint "Future + 24h : " & oFuture.Day ** Cleaning objectsSet DateTime = NothingSet oToday = Nothing : Set oFuture = NothingDateTime.DayOfWeek PropertyGets the day of the week represented by this instance.Value = object.DayOfWeek
  26. 26. Chapter 14 Scripting Quicktest Professional Page 26Dani Vainstein DotNetFactory Page 26 of 151A DayOfWeek enumerated constant that indicates the day of the week. This propertyvalue ranges from zero, indicating Sunday, to six, indicating Saturday.The following example returns the Date value of Now methodOption ExplicitDim DateTimeDim oToday, oFuture, iSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set oToday = DateTime.Today()For i = 1 To 7Set oFuture = oToday.AddDays( i )Print oFuture.DayOfWeek.GetHashCode & " --> " & oFuture.DayOfWeekNext ** Cleaning objectsSet DateTime = NothingSet oToday = Nothing : Set oFuture = NothingDateTime.DayOfYear PropertyGets the day of the year represented by this instanceobject.DayOfYearThe day of the year, expressed as a value between 1 and 366.The following example returns the Day of The year for TodayMsgbox DotNetFactory.CreateInstance( "System.DateTime" ).Today.DayOfYear
  27. 27. Chapter 14 Scripting Quicktest Professional Page 27Dani Vainstein DotNetFactory Page 27 of 151DateTime.Hour PropertyGets the hour component of the date represented by this instance.object.HourThe hour component, expressed as a value between 0 and 23.The following code example demonstrates the Hour property.Option ExplicitDim momentSet moment = DotNetFactory.CreateInstance( _"System.DateTime",, 1999, 1, 13, 3, 57, 32, 11 _)Print "Year --> " & moment.Year ** Year gets 1999.Print "Month --> " & moment.Month ** Month gets 1 (January).Print "Day --> " & moment.Day ** Day gets 13.Print "Hour --> " & moment.Hour ** Hour gets 3.Print "Minute --> " & moment.Minute ** Minute gets 57.Print "Second --> " & moment.Second ** Second gets 32.Print "Millisecond --> " & moment.Millisecond ** Millisecond gets 11.Set moment = NothingDateTime.Kind Property
  28. 28. Chapter 14 Scripting Quicktest Professional Page 28Dani Vainstein DotNetFactory Page 28 of 151Gets a value that indicates whether the time represented by this instance is based onlocal time, Coordinated Universal Time (UTC), or neither.object.KindOne of the DateTimeKind values. The default is Unspecified.The following example uses Item to retrieve the FolderItem object representing theWindows folder and filtering the contentOption ExplicitDim saveNow, saveUtcNow, myDtDim DateTimeKindSet DateTimeKind = DotNetFactory.CreateInstance( "System.DateTimeKind" )Set saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).NowPrint "saveNow = " & saveNow.Kind.GetHashCode & " --> " & saveNow.KindSet saveUtcNow = DotNetFactory.CreateInstance( "System.DateTime" ).UtcNowPrint "saveUtcNow = " & saveUtcNow.Kind.GetHashCode & " --> " & saveUtcNow.KindSet myDt = _DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _saveNow, DateTimeKind.Utc _)Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.KindSet myDt = DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _saveNow, DateTimeKind.Local _)Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.KindSet myDt = DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _saveNow, DateTimeKind.Unspecified _)Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.Kind ** Cleaning objectsSet DateTimeKind = Nothing : Set saveNow = NothingSet saveUtcNow = Nothing : Set myDt = Nothing
  29. 29. Chapter 14 Scripting Quicktest Professional Page 29Dani Vainstein DotNetFactory Page 29 of 151DateTime.Millisecond PropertyGets the milliseconds component of the date represented by this instance.Value = object.MillisecondThe milliseconds component, expressed as a value between 0 and 999.The following code example demonstrates the Millisecond property.see : DateTime.Hour PropertyDateTime.Minute PropertyGets the minute component of the date represented by this instance.Value = object.MinuteThe minute component, expressed as a value between 0 and 59.The following code example demonstrates the Minute property.see : DateTime.Hour PropertyDateTime.Month PropertyGets the month component of the date represented by this instanceValue = object.MonthThe month component, expressed as a value between 1 and 12.The following code example demonstrates the Minute property.see : DateTime.Hour PropertyDateTime.Now PropertyGets a DateTime object that is set to the current date and time on this computer,
  30. 30. Chapter 14 Scripting Quicktest Professional Page 30Dani Vainstein DotNetFactory Page 30 of 151expressed as the local time.Value = object.NowA DateTime whose value is the current local date and time.The following example returns the Now property.Set oNow = DotNetFactory.CreateInstance( "System.DateTime" ).NowDateTime.Second PropertyGets the seconds component of the date represented by this instance.Value = object.SecondThe seconds, between 0 and 59.The following code example demonstrates the Second property.see : DateTime.Hour PropertyDateTime.Ticks PropertyGets the number of ticks that represent the date and time of this instanceValue = object.TicksThe number of ticks that represent the date and time of this instance. The value isbetween MinValue and MaxValue.DateTime.TimeOfDay PropertyGets the time of day for this instance.Value = object.TimeOfDay
  31. 31. Chapter 14 Scripting Quicktest Professional Page 31Dani Vainstein DotNetFactory Page 31 of 151A TimeSpan that represents the fraction of the day that has elapsed since midnight.The following example uses Item to retrieve the FolderItem object representing theWindows folder and filtering the contentOption ExplicitDim saveNow, timeSpanSet saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).NowPrint "saveNow = " & saveNowSet timeSpan = saveNow.TimeOfDayPrint "Time since midnight -> Hours : " & _timeSpan.Hours & ", Minutes : " & _timeSpan.Minutes & ", Seconds : " & timeSpan.SecondsSet saveNow = Nothing : Set timeSpan = NothingDateTime.Today PropertyGets the current date..Value = object.TodayA DateTime set to todays date, with the time component set to 00:00:00.The following example returns the Today property.Set oToday = DotNetFactory.CreateInstance( "System.DateTime" ).TodayDateTime.UtcNow PropertyGets a DateTime object that is set to the current date and time on this computer,expressed as the Coordinated Universal Time (UTC).Value = object.UtcNowA DateTime whose value is the current UTC date and time.
  32. 32. Chapter 14 Scripting Quicktest Professional Page 32Dani Vainstein DotNetFactory Page 32 of 151Starting with the .NET Framework version 2.0, the return value is a DateTime whoseKind property returns Utc.The following example returns the UtcNow property. DateTime.DateTime( int64,DateTimeKind ) ConstructorDateTime.Year PropertyGets the year component of the date represented by this instance.Value = object.YearThe year, between 1 and 9999The following code example demonstrates the Year property.see : DateTime.Hour PropertyDateTime MethodsName DescriptionAddAdds the value of the specified TimeSpan to the value of thisinstanceAddDays Adds the specified number of days to the value of this instance.AddHours Adds the specified number of hours to the value of this instance.AddMillisecondsAdds the specified number of milliseconds to the value of thisinstance.AddMinutesAdds the specified number of minutes to the value of thisinstance.AddMonthsAdds the specified number of months to the value of thisinstance.AddSecondsAdds the specified number of seconds to the value of thisinstance.AddTicks Adds the specified number of ticks to the value of this instance.AddYears Adds the specified number of years to the value of this instance.CompareCompares two instances of DateTime and returns an indication oftheir relative values.CompareToOverloaded. Compares this instance to a specified object or valuetype and returns an indication of their relative values.DaysInMonth Returns the number of days in the specified month and year.Equals Overloaded. Returns a value indicating whether two DateTimeobjects, or a DateTime instance and another object or DateTime
  33. 33. Chapter 14 Scripting Quicktest Professional Page 33Dani Vainstein DotNetFactory Page 33 of 151are equal.FromBinaryDeserializes a 64-bit binary value and recreates an originalserialized DateTime object.FromFileTimeConverts the specified Windows file time to an equivalent localtime.FromFileTimeUtcConverts the specified Windows file time to an equivalent UTCtime.GetTimeFormatsOverloaded. Converts the value of this instance to all the stringrepresentations supported by the standard DateTime formatspecifiers.GetHashCode Returns the hash code for this instance.GetTypeCode Returns the TypeCode for value type DateTime.IsDaylightSavingTimeIndicates whether this instance of DateTime is within theDaylight Saving Time range for the current time zoneIsLeapYear Returns an indication whether the specified year is a leap year.op_AdditionAdds a specified time interval to a specified date and time,yielding a new date and time.op_EqualityDetermines whether two specified instances of DateTime areequal.op_GreaterThanDetermines whether one specified DateTime is greater thananother specified DateTime.op_GreaterThanOrEqualDetermines whether one specified DateTime is greater than orequal to another specified DateTime.op_InequalityDetermines whether two specified instances of DateTime are notequal.op_LessThanDetermines whether one specified DateTime is less than anotherspecified DateTime.op_LessThanOrEqualDetermines whether one specified DateTime is less than or equalto another specified DateTime.op_SubtractionOverloaded. Subtracts a specified DateTime or TimeSpan froma specified DateTime.ParseOverloaded. Converts the specified string representation of a dateand time to its DateTime equivalent.ParseExactOverloaded. Converts the specified string representation of a dateand time to its DateTime equivalent. The format of the stringrepresentation must match a specified format exactly.SpecifyKindCreates a new DateTime object that represents the same time asthe specified DateTime, but is designated in either local time,Coordinated Universal Time (UTC), or neither, as indicated by thespecified DateTimeKind value.SubtractOverloaded. Subtracts the specified time or duration from thisinstance.ToBinarySerializes the current DateTime object to a 64-bit binary valuethat subsequently can be used to recreate the DateTime object.ToFileTimeConverts the value of the current DateTime object to a Windowsfile time.
  34. 34. Chapter 14 Scripting Quicktest Professional Page 34Dani Vainstein DotNetFactory Page 34 of 151ToFileTimeUtcConverts the value of the current DateTime object to a Windowsfile time.ToLocalTime Converts the value of the current DateTime object to local time.ToLongDateStringConverts the value of the current DateTime object to itsequivalent long date string representation.ToLongTimeStringConverts the value of the current DateTime object to itsequivalent long time string representation.ToShortDateStringConverts the value of the current DateTime object to itsequivalent short date string representation.ToShortTimeStringConverts the value of the current DateTime object to itsequivalent short time string representation.ToStringOverloaded. Overridden. Converts the value of the currentDateTime object to its equivalent string representation.ToUniversalTimeConverts the value of the current DateTime object toCoordinated Universal Time (UTC).TryParseOverloaded. Converts the specified string representation of a dateand time to its DateTime equivalent.TryParseExactOverloaded. Converts the specified string representation of a dateand time to its DateTime equivalent. The format of the stringrepresentation must match a specified format exactly.DateTime.Add ( TimeSpan ) MethodAdds the value of the specified TimeSpan to the value of this instance.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.Set object = instance.Add( value )Parameter Descriptionvalue A TimeSpan that contains the interval to add.A DateTime whose value is the sum of the date and time represented by this instanceand the time interval represented by value.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.The following code example demonstrates the Add method. It calculates the day of theweek that is 36 days (864 hours) from this moment.
  35. 35. Chapter 14 Scripting Quicktest Professional Page 35Dani Vainstein DotNetFactory Page 35 of 151Option ExplicitDim saveNow, duration, answerSet saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).NowSet duration = DotNetFactory.CreateInstance( "System.TimeSpan", ,36, 0, 0, 0 )Set answer = saveNow.Add( duration )MsgBox answer.ToString( "dddd" )Set saveNow = Nothing : Set duration = Nothing : Set answer = NothingDateTime.AddDays ( Double ) MethodAdds the specified number of days to the value of this instance.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.The fractional part of value is the fractional part of a day. For example, 4.5 isequivalent to 4 days, 12 hours, 0 minutes, 0 seconds, 0 milliseconds, and 0 ticks.The value parameter is rounded to the nearest millisecond.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.Set dateTime = instance.AddDays( days )Parameter DescriptiondaysA number of whole and fractional days. The value parameter can benegative or positiveA DateTime whose value is the sum of the date and time represented by this instanceand the number of days represented by daysThe following code example demonstrates the AddDays methodOption ExplicitDim saveNowSet saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
  36. 36. Chapter 14 Scripting Quicktest Professional Page 36Dani Vainstein DotNetFactory Page 36 of 151Print "Today is --> " & saveNow.ToString( "D" )Print "Tomorrow --> " & saveNow.AddDays( 1 ).ToString( "D" )Print "Yesterday --> " & saveNow.AddDays( -1 ).ToString( "D" )Set saveNow = NothingDateTime.AddHours ( Double ) MethodAdds the specified number of hours to the value of this instance.Set dateTime = instance.AddHours( hours )Parameter Descriptionhoursnumber of whole and fractional hours. The value parameter can benegative or positive.A DateTime whose value is the sum of the date and time represented by this instanceand the number of hours represented by hours.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.The fractional part of value is the fractional part of an hour. For example, 4.5 isequivalent to 4 hours, 30 minutes, 0 seconds, 0 milliseconds, and 0 ticks..The value parameter is rounded to the nearest millisecond.DateTime.AddMilliseconds ( Double ) MethodAdds the specified number of milliseconds to the value of this instance.Set object = instance.AddMilliseconds( value )Parameter Description
  37. 37. Chapter 14 Scripting Quicktest Professional Page 37Dani Vainstein DotNetFactory Page 37 of 151valueA number of whole and fractional milliseconds. The value parameter canbe negative or positive. Note that this value is rounded to the nearestinteger.A DateTime whose value is the sum of the date and time represented by this instanceand the number of milliseconds represented by value.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.This method does not change the value of this DateTime. Instead, a newDateTime is returned whose value is the result of this operation.The fractional part of value is the fractional part of a millisecond. For example, 4.5 isequivalent to 4 milliseconds, and 5000 ticks, where one millisecond = 10000 ticks.The value parameter is rounded to the nearest millisecond.DateTime.AddMinutes ( Double ) MethodAdds the specified number of minutes to the value of this instance.Set object = instance.AddMinutes( minutes )Parameter DescriptionminutesA number of whole and fractional minutes. The value parameter can benegative or positive.A DateTime whose value is the sum of the date and time represented by this instanceand the number of minutes represented by minutes.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.The fractional part of value is the fractional part of a minute. For example, 4.5 isequivalent to 4 minutes, 30 seconds, 0 milliseconds, and 0 ticks.The value parameter is rounded to the nearest millisecond.DateTime.AddMonths ( Integer ) MethodAdds the specified number of months to the value of this instance.
  38. 38. Chapter 14 Scripting Quicktest Professional Page 38Dani Vainstein DotNetFactory Page 38 of 151Set object = instance.AddMonths( months )Parameter Descriptionmonths A number of months. The months parameter can be negative or positive.A DateTime whose value is the sum of the date and time represented by this instanceand months.ArgumentOutOfRangeExceptionmonths is less than -120,000 or greater than 120,000.The resulting DateTime is less than MinValue or greater than MaxValue.This method does not change the value of this DateTime. Instead, a newDateTime is returned whose value is the result of this operation.The AddMonths method calculates the resulting month and year, taking intoaccount leap years and the number of days in a month, then adjusts the day part ofthe resulting DateTime object. If the resulting day is not a valid day in the resultingmonth, the last valid day of the resulting month is used. For example, March 31st +1 month = April 30th. The time-of-day part of the resulting DateTime objectremains the same as this instance.DateTime.AddSeconds ( Double ) MethodAdds the specified number of seconds to the value of this instance.Set object = instance.AddSeconds( seconds )Parameter DescriptionsecondsA number of whole and fractional seconds. The value parameter can benegative or positive.A DateTime whose value is the sum of the date and time represented by this instanceand the number of seconds represented by seconds.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.
  39. 39. Chapter 14 Scripting Quicktest Professional Page 39Dani Vainstein DotNetFactory Page 39 of 151A The fractional part of value is the fractional part of a second. For example, 4.5 isequivalent to 4 seconds, 500 milliseconds, and 0 ticks.The value parameter is rounded to the nearest millisecond.DateTime.AddTicks ( Long ) MethodAdds the specified number of ticks to the value of this instance.Set object = instance.AddTicks( ticks )Parameter DescriptionticksA number of 100-nanosecond ticks. The value parameter can be positiveor negative.A DateTime whose value is the sum of the date and time represented by thisinstance and the time represented by ticks.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.DateTime.AddYears ( Integer ) MethodAdds the specified number of years to the value of this instance.Set object = instance.AddYears( years )Parameter Descriptionyears A number of years. The value parameter can be negative or positive.A DateTime whose value is the sum of the date and time represented by this instanceand the number of years represented by years.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.
  40. 40. Chapter 14 Scripting Quicktest Professional Page 40Dani Vainstein DotNetFactory Page 40 of 151This method does not change the value of this DateTime. Instead, a new DateTimeis returned whose value is the result of this operation.The AddYears method calculates the resulting year taking into account leap years.The month and time-of-day part of the resulting DateTime object remains the sameas this instance.DateTime.Compare ( DateTime, DateTime ) MethodCompares two instances of DateTime and returns an indication of their relative values.returnValue = instance.Compare( dt1, dt2 )Parameter Descriptiondt1 The first DateTime.dt2 The second DateTime.A signed number indicating the relative values of dt1 and dt2Less than zero - dt1 is less than dt2.Zero - dt1 equals dt2Greater than zero - dt1 is greater than dt2.Before comparing DateTime objects, insure that the objects represent times in thesame time zone.The following code example demonstrates Compare.Option ExplicitDim dt1, dt2, DateTimeSet dt1 = DotNetFactory.CreateInstance( "System.DateTime", ,100 )Set dt2 = DotNetFactory.CreateInstance( "System.DateTime", ,300 )Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )If DateTime.Compare( dt1, dt2 ) > 0 ThenPrint "dt1 > dt2"End IfIf DateTime.Compare( dt1, dt2 ) = 0 ThenPrint "dt1 = dt2"End IfIf DateTime.Compare( dt1, dt2 ) < 0 ThenPrint "dt1 < dt2"End IfDateTime.CompareTo ( DateTime ) Method
  41. 41. Chapter 14 Scripting Quicktest Professional Page 41Dani Vainstein DotNetFactory Page 41 of 151Compares this instance to a specified DateTime object and returns an indication of theirrelative values.instance.CompareTo( value )Parameter Descriptionvalue A DateTime object to compare.A signed number indicating the relative values of this instance and the value parameter.Less than zero - This instance is less than valueZero - This instance is equal to value.Greater than zero - This instance is greater than value.This method implements the System.IComparable interface and performs slightlybetter than the DateTime.CompareTo method because it does not have to convertthe value parameter to an object.Before comparing DateTime objects, insure that the objects represent times in thesame time zone.The following code example demonstrates the CompareTo method.Option ExplicitDim DateTime, thDayDim compareValueSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set thDay = DotNetFactory.CreateInstance( _System.DateTime", , DateTime.Today.Year, 7, 28)compareValue = Cint( thDay.CompareTo( DateTime.Today ) )If compareValue < 0 ThenPrint thDay.ToString( "d" ) & " is in the past."ElseIf compareValue = 0 ThenPrint thDay.ToString( "d" ) & " is today!"ElsePrint thDay.ToString( "d" ) & " has not come yet."End IfDateTime.DaysInMonth ( Integer, Integer ) MethodReturns the number of days in the specified month and year.This method implements the System.IComparable interface and performs slightlybetter than the DateTime.CompareTo method because it does not have to convertthe value parameter to an object.
  42. 42. Chapter 14 Scripting Quicktest Professional Page 42Dani Vainstein DotNetFactory Page 42 of 151Before comparing DateTime objects, insure that the objects represent times in thesame time zone.returnValue = instance.DaysInMonth( year, month )Parameter Descriptionyear The year.month The month (a number ranging from 1 to 12).The number of days in month for the specified year. For example, if month equals 2for February, the return value is 28 or 29 depending upon whether year is a leapyear.ArgumentOutOfRangeExceptionmonth is less than 1 or greater than 12.year is less than 1 or greater than 9999.The following code example demonstrates the DaysInMonth method.Option ExplicitConst CULTURE_INFO = "System.Globalization.CultureInfo"Dim DateTime, InfoDim arrInfo, i, nMonthPrivate Sub PrintData( ByVal info, ByRef DateTime, ByVal monthIndex )Const FMT = "{0} - {1} --> {2} has {3} Days."Dim monthStr, engName, nativeName, daysInMonDim sbmonthStr= info.DateTimeFormat.MonthNames.GetValue( monthIndex - 1 )engName = info.EnglishNamenativeName = info.NativeNamedaysInMon= DateTime.DaysInMonth( DateTime.Today.Year, monthIndex )Set sb = DotNetFactory.CreateInstance( "System.Text.StringBuilder" )sb.AppendFormat FMT, engName, nativeName, monthStr, daysInMonPrint sb.ToStringSet sb = NothingEnd SubSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )arrInfo = Array( "es-AR", "hi-IN", "de-DE", "fi-FI" )For i = LBound( arrInfo ) To UBound( arrInfo )Set info = DotNetFactory.CreateInstance( CULTURE_INFO, "System", arrInfo( i ) )For nMonth = 1 To 12Call PrintData( info, DateTime, nMonth )NextNext
  43. 43. Chapter 14 Scripting Quicktest Professional Page 43Dani Vainstein DotNetFactory Page 43 of 151Set Info = Nothing : Set DateTime = Nothing
  44. 44. Chapter 14 Scripting Quicktest Professional Page 44Dani Vainstein DotNetFactory Page 44 of 151
  45. 45. Chapter 14 Scripting Quicktest Professional Page 45Dani Vainstein DotNetFactory Page 45 of 151DateTime.Equals ( DateTime ) MethodReturns a value indicating whether this instance is equal to the specified DateTimeinstance.returnValue = instance.Equals( value )Parameter Descriptionvalue A DateTime instance to compare to this instance.true if the value parameter equals the value of this instance; otherwise, false.This method implements the System.IEquatable interface, and performs slightlybetter than the Equals method because the value parameter does not have to beconverted to an object.The following code example demonstrates the Equals method.Option ExplicitDim one, two, threeDim resultSet one = DotNetFactory.CreateInstance( "System.DateTime" ).UtcNowSet two = DotNetFactory.CreateInstance( "System.DateTime" ).NowSet three = oneresult = one.Equals(two)Print "The result of comparing DateTime object one and two is: " & resultresult = one.Equals(three)Print "The result of comparing DateTime object one and three is: " & resultSet one = Nothing : Set two = Nothing : Set three = NothingDateTime.Equals ( DateTime, DateTime ) MethodReturns a value indicating whether two instances of DateTime are equal.ReturnValue = instance.Equals( t1, t2 )
  46. 46. Chapter 14 Scripting Quicktest Professional Page 46Dani Vainstein DotNetFactory Page 46 of 151Parameter Descriptiont1 The first DateTime instance.t2 The second DateTime instance.true if the two DateTime values are equal; otherwise, false.This method implements the System.IEquatable interface, and performsslightly better than the Equals method because the value parameter doesnot have to be converted to an object.The following code example demonstrates the Equals method.Option ExplicitDim today1, today2, tomorrow, DateTimeDim todayEqualsToday, todayEqualsTomorrowSet DateTime = DotNetFactory.CreateInstance("System.DateTime")Set today1 = DotNetFactory.CreateInstance("System.DateTime",, DateTime.Today.Ticks )Set today2 = DotNetFactory.CreateInstance("System.DateTime",, DateTime.Today.Ticks )Set tomorrow = DotNetFactory.CreateInstance( "System.DateTime",, _DateTime.Today.AddDays(1).Ticks _) ** todayEqualsToday gets true.todayEqualsToday = DateTime.Equals( today1, today2 ) ** todayEqualsTomorrow gets false.todayEqualsTomorrow = DateTime.Equals(today1, tomorrow)Set today1 = Nothing : Set today2 = Nothing : Set tomorrow = NothingSet DateTime = NothingDateTime.FromBinary ( Long ) MethodDeserializes a 64-bit binary value and recreates an original serialized DateTime objectinstance.FromBinary( dateData )Parameter DescriptiondateDataA 64-bit signed integer that encodes the Kind property in a 2-bit fieldand the Ticks property in a 62-bit fieldA DateTime object that is equivalent to the DateTime object that was serialized bythe ToBinary method
  47. 47. Chapter 14 Scripting Quicktest Professional Page 47Dani Vainstein DotNetFactory Page 47 of 151ArgumentException - dateData is less than MinValue or greater than MaxValue.Use the ToBinary method to convert the value of the current DateTime object to abinary value. Subsequently, use the binary value and the FromBinary method torecreate the original DateTime object.A local time, which is a Coordinated Universal Time adjusted to the local time zone,is represented by a DateTime structure whose Kind property has the value Local. Ifa local DateTime object is serialized in one time zone by the ToBinary method anddeserialized in a different time zone by the FromBinary method, the local timerepresented by the resulting DateTime object is automatically adjusted to thesecond time zone.For example, consider a DateTime object that represents a local time of 3 P.M. Anapplication executing in a western time zone uses the ToBinary method to convertthat DateTime object to a binary value, then another application executing in a timezone three hours east of the original one uses the FromBinary method to convertthe binary value to a new DateTime object. The value of the new DateTime objectis 6 P.M., which represents the same point in time as the original 3 P.M. value, but isadjusted to local time in the eastern time zone.DateTime.FromFileTime ( Long ) MethodConverts the specified Windows file time to an equivalent local time.Set object = instance.FromFileTime( fileTime )Parameter DescriptionfileTime A Windows file time expressed in ticks.A DateTime object that represents a local time equivalent to the date and timerepresented by the fileTime parameter.ArgumentOutOfRangeException - fileTime is less than 0 or represents a time greaterthan MaxValue.A Windows file time is a 64-bit value that represents the number of 100-nanosecondintervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.)Coordinated Universal Time (UTC). Windows uses a file time to record when anapplication creates, accesses, or writes to a file.The fileTime parameter specifies a file time expressed in 100-nanosecond ticks.Starting with the .NET Framework version 2.0, the return value is a DateTimewhose Kind property is Local.The following code example demonstrates the FromFileTime method.Option Explicit
  48. 48. Chapter 14 Scripting Quicktest Professional Page 48Dani Vainstein DotNetFactory Page 48 of 151Dim dteNow, DateTimeDim fCreationTime, fAge, LongNumSet LongNum = DotNetFactory.CreateInstance( "System.Int64" )Set LongNum = LongNum.Parse( "126879894987978697" )Set dteNow = DotNetFactory.CreateInstance( "System.DateTime" ).NowSet DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set fCreationTime = DateTime.FromFileTime( LongNum )Set fAge = dteNow.Subtract( fCreationTime )Print fAge.Days & _" Days, " & fAge.Hours & " Hours, and " & fAge.Minutes & " Minutes."Print "TotalDays --> " & fAge.TotalDaysSet fAge = Nothing : Set fCreationTime = Nothing : Set dteNow = NothingSet LongNum = NothingDateTime.FromFileTimeUtc ( Long ) MethodConverts the specified Windows file time to an equivalent UTC time.Set object = instance.FromFileTimeUtc( fileTime )Parameter DescriptionfileTime A Windows file time expressed in ticks.A DateTime object that represents a UTC time equivalent to the date and timerepresented by the fileTime parameterArgumentOutOfRangeException - fileTime is less than 0 or represents a time greaterthan MaxValue.A Windows file time is a 64-bit value that represents the number of 100-nanosecondintervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.)Coordinated Universal Time (UTC). Windows uses a file time to record when anapplication creates, accesses, or writes to a file.The fileTime parameter specifies a file time expressed in 100-nanosecond ticks.Starting with the .NET Framework version 2.0, the return value is a DateTimewhose Kind property is Utc.
  49. 49. Chapter 14 Scripting Quicktest Professional Page 49Dani Vainstein DotNetFactory Page 49 of 151DateTime.GetTimeFormats MethodName DescriptionGetTimeFormats()Converts the value of this instance to all the stringrepresentations supported by the standard DateTimeformat specifiers.DateTime.GetDateTimeFormats(Char)Converts the value of this instance to all the stringrepresentations supported by the specified standardDateTime format specifier.DateTime.GetDateTimeFormats(IFormatProvider)Converts the value of this instance to all the stringrepresentations supported by the standard DateTimeformat specifiers and the specified culture-specificformatting information.DateTime.GetDateTimeFormats(Char, IFormatProvider)Converts the value of this instance to all the stringrepresentations supported by the specified standardDateTime format specifier and culture-specificformatting information.DateTime.GetTimeFormats () MethodConverts the value of this instance to all the string representations supported by thestandard DateTime format specifiers.Set objectArray = instance.GetTimeFormats()A string array where each element is the representation of the value of this instanceformatted with one of the standard DateTime formatting specifiers.Each element of the return value is formatted using information from the currentculture. For more information about culture-specific formatting information for thecurrent culture, see CultureInfo.CurrentCulture.For For more information about the standard formatting specifiershttp://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspxThe following code example demonstrates the GetDateTimeFormats method.Option ExplicitDim july28Formats, july28Dim nFormatSet july28 = DotNetFactory.CreateInstance( _"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _)Set july28Formats = july28.GetDateTimeFormats() ** Print out july28 in all DateTime formats using the default culture.
  50. 50. Chapter 14 Scripting Quicktest Professional Page 50Dani Vainstein DotNetFactory Page 50 of 151For nFormat = 0 To july28Formats.Length - 1Print july28Formats.GetValue( CLng( nFormat ) )NextSet july28Formats = Nothing: Set july28 = NothingDateTime.GetTimeFormats ( Char ) MethodConverts the value of this instance to all the string representations supported by thespecified standard DateTime format specifier.Set objectArray = instance.GetTimeFormats( format )Parameter Descriptionformat A Standard DateTime format string or a Custom DateTime Format String
  51. 51. Chapter 14 Scripting Quicktest Professional Page 51Dani Vainstein DotNetFactory Page 51 of 151A string array where each element is the representation of the value of this instanceformatted with the format standard DateTime formatting specifier.Each element of the return value is formatted using information from the currentculture. For more information about culture-specific formatting information for thecurrent culture, see CultureInfo.CurrentCulture.For For more information about the standard formatting specifiershttp://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspxThe following code example demonstrates the GetDateTimeFormats method.Option ExplicitDim july28, sysCharDim nFormatSet july28 = DotNetFactory.CreateInstance( _"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _)Set sysChar = DotNetFactory.CreateInstance( "System.Char" ).Parse( "R" ) ** Get the RFC1123 date formatsSet July28Formats = july28.GetDateTimeFormats( sysChar ) ** Print out july28 in various RFC1123 formatsFor nFormat = 0 To July28Formats.Length - 1Print July28Formats.GetValue( CLng( nFormat ) )NextSet July28Formats = Nothing : Set july28 = Nothing : Set sysChar = NothingDateTime.GetTimeFormats ( IFormatProvider ) MethodConverts the value of this instance to all the string representations supported by thestandard DateTime format specifiers and the specified culture-specific formattinginformation.Set objectArray = instance.GetTimeFormats( provider )Parameter DescriptionproviderAn IFormatProvider that supplies culture-specific formattinginformation about this instance.
  52. 52. Chapter 14 Scripting Quicktest Professional Page 52Dani Vainstein DotNetFactory Page 52 of 151A string array where each element is the representation of the value of this instanceformatted with one of the standard DateTime formatting specifiers.Each element of the return value is formatted using culture-specific informationsupplied by provider.For For more information about the standard formatting specifiershttp://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspxThe following code example demonstrates the GetDateTimeFormats method.Option ExplicitConst CULTURE_INFO = "System.Globalization.CultureInfo"Dim arabicJuly28Formats, july28, cultureDim nFormatSet july28 = DotNetFactory.CreateInstance( _"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _)Set culture = DotNetFactory.CreateInstance( CULTURE_INFO, "System", "ar-EG", True ) ** Get the short date formats using the "ar-EG" culture.Set arabicJuly28Formats = july28.GetDateTimeFormats( culture )Print "Starting DateTiume Formats for --> " & _culture.EnglishName & ", " & culture.NativeNameFor nFormat = 0 To arabicJuly28Formats.Length – 1 Step 2Print arabicJuly28Formats.GetValue( CLng( nFormat ) )NextSet arabicJuly28Formats = Nothing : Set july28 = Nothing : Set culture = Nothing
  53. 53. Chapter 14 Scripting Quicktest Professional Page 53Dani Vainstein DotNetFactory Page 53 of 151DateTime.GetTimeFormats ( Char, IFormatProvider )MethodConverts the value of this instance to all the string representations supported by thestandard DateTime format specifiers and the specified culture-specific formattinginformation.Set objectArray = instance.GetTimeFormats( format, provider )Parameter Descriptionformat A Standard DateTime format string or a Custom DateTime Format StringproviderAn IFormatProvider that supplies culture-specific formattinginformation about this instance.A string array where each element is the representation of the value of this instanceformatted with one of the standard DateTime formatting specifiers.Each element of the return value is formatted using culture-specific informationsupplied by provider.For For more information about the standard formatting specifiers
  54. 54. Chapter 14 Scripting Quicktest Professional Page 54Dani Vainstein DotNetFactory Page 54 of 151http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspxThe following code example demonstrates the GetDateTimeFormats method.Option ExplicitConst CULTURE_INFO = "System.Globalization.CultureInfo"Dim frenchJuly28Formats, july28, culture, sysCharDim nFormatSet july28 = DotNetFactory.CreateInstance( _"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _)Set sysChar = DotNetFactory.CreateInstance( "System.Char" ).Parse( "f" )Set culture = DotNetFactory.CreateInstance( CULTURE_INFO, "System", "fr-FR", True ) ** Get the short date formats using the "fr-FR" culture.Set frenchJuly28Formats = july28.GetDateTimeFormats( sysChar, culture ) ** Print out july28 in various formats using "fr-FR" culture.Print "Starting fr-FR formats..."For nFormat = 0 To frenchJuly28Formats.Length - 1Print frenchJuly28Formats.GetValue( CLng( nFormat ) )NextSet frenchJuly28Formats = Nothing : Set july28 = NothingDateTime.GetHashCode () MethodReturns the hash code for this instance.returnValue = instance.GetHashCode()
  55. 55. Chapter 14 Scripting Quicktest Professional Page 55Dani Vainstein DotNetFactory Page 55 of 151A 32-bit signed integer hash code.The following code example demonstrates the GetHashCode method.Option ExplicitDim SystemTimeSet SystemTime = DotNetFactory.CreateInstance( "System.DateTime" ).TodayPrint "GetTypeCode --> " & SystemTime.GetTypeCodePrint "GetType --> " & SystemTime.GetTypePrint "GetHashCode.GetType --> " & SystemTime.GetHashCode.GetTypePrint "GetHashCode --> " & SystemTime.GetHashCodeSet SystemTime = NothingDateTime.GetTypeCode () MethodReturns the TypeCode for value type DateTime.instance.GetTypeCode()The enumerated constant, TypeCode.DateTime.The following code example demonstrates the GetTypeCode method.DateTime.GetHashCode() MethodDateTime.IsDaylightSavingTime () MethodIndicates whether this instance of DateTime is within the Daylight Saving Time rangefor the current time zone.instance.IsDaylightSavingTime ()true if Kind is Local or Unspecified and the value of this instance of DateTime iswithin the Daylight Saving Time range for the current time zone. false if Kind is Utc.
  56. 56. Chapter 14 Scripting Quicktest Professional Page 56Dani Vainstein DotNetFactory Page 56 of 151DateTime.IsLeapYear ( Integer ) MethodReturns an indication whether the specified year is a leap year.instance.IsLeapYear( year )Parameter Descriptionyear A 4-digit year.true if year is a leap year; otherwise, false.ArgumentOutOfRangeException - year is less than 1 or greater than 9999.year is specified as a 4-digit base 10 number; for example, 1996.DateTime.op_Addition ( DateTime, TimeSpan ) MethodAdds a specified time interval to a specified date and time, yielding a new date and time.instance.op_Addition( d, t )Parameter Descriptiond A DateTime objectt A TimeSpan objectA DateTime that is the sum of the values of d and t.ArgumentOutOfRangeException - The resulting DateTime is less than MinValue orgreater than MaxValue.The following code example demonstrates the addition operator.Option ExplicitDim dTime, tSpan, result, DateTimeSet dTime = DotNetFactory.CreateInstance( "System.DateTime",,1980, 8, 5 ) ** tSpan is 17 days, 4 hours, 2 minutes and 1 second.
  57. 57. Chapter 14 Scripting Quicktest Professional Page 57Dani Vainstein DotNetFactory Page 57 of 151Set tSpan = DotNetFactory.CreateInstance( "System.TimeSpan",,17, 4, 2, 1 ) ** Result gets 8/22/1980 4:02:01 AM.Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )Set result = DateTime.op_Addition( dTime, tSpan )Msgbox result.ToString( "G" )Set result = Nothing : Set tSpan = Nothing : Set dTime = NothingDateTime.op_Equality ( DateTime, DateTime ) MethodDetermines whether two specified instances of DateTime are equal.instance.op_Equality( d1, d2 )Parameter Descriptiond1 A DateTime objectd2 A DateTime objecttrue if d1 and d2 represent the same date and time; otherwise, false.The following code example demonstrates the equality operator.Option ExplicitDim april19, otherDateDim areEqualSet april19 = DotNetFactory.CreateInstance( "System.DateTime",,2001, 4, 19 )Set otherDate = DotNetFactory.CreateInstance( "System.DateTime",,1991, 6, 5 ) ** areEqual gets false.areEqual = DotNetFactory.CreateInstance( _"System.DateTime").op_Equality( april19, otherDate )Set otherDate = DotNetFactory.CreateInstance( "System.DateTime",,2001, 4, 19) ** areEqual gets true.areEqual = DotNetFactory.CreateInstance( _"System.DateTime").op_Equality( april19, otherDate )Set otherDate = Nothing : Set april19 = NothingDateTime.op_GreaterThan ( DateTime, DateTime ) Method

×