Setting MonthCalendar Date in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

While testing MonthCalendar controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

MonthCalendar controls can support multi-selection of dates or not. To determine whether the MonthCalendar control supports multi-selection use the wMultiSelect property of the Win32MonthCalendar object. During the test run, this object is associated with all MonthCalendar controls whose class names are listed in the project’s Object Mapping options. For more information on using thewMultiSelect property, see the Selecting Multiple Dates in MonthCalendar Controls in Desktop Windows Applications topic.

If the MonthCalendar control does not support multi-selection, use the wDate property to set the date. If the month calendar control supports multi-selection, the range of selected dates can be specified by the wDate and the wEndDate properties. In this case, the wDate property specifies the earliest date and the wEndDate property specifies the latest date in the range of selected dates in the month calendar control. This properties belong to the Win32MonthCalendar object.

You can assign a value to these properties using a string or date value.

If you use a string to specify the date value, then the string must contain the date in the format that corresponds to the Regional Settings used on your computer.

The following example demonstrates how you can determine whether the MonthCalendar control support multi-selection of dates and set the date or range of dates in the MonthCalendar control:

JavaScript, JScript

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar");

  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    MonthCalendar.wDate = "11/27/2007";
  }
     
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else 
  {
    MonthCalendar.wDate = "11/28/2007";
    MonthCalendar.wEndDate = "11/30/2007";
  }
}

Python

def Main():

  # Obtain the MonthCalendar control 
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")

  # Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if not MonthCalendar.wMultiSelect:
    MonthCalendar.wDate = "11/27/2007"
     
  # Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else :
    MonthCalendar.wDate = "11/28/2007"
    MonthCalendar.wEndDate = "11/30/2007"

VBScript

Sub main
  Dim MonthCalendar

  ' Obtain the MonthCalendar control
  Set MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")
    
  ' Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  If MonthCalendar.wMultiSelect=False Then
    MonthCalendar.wDate = "11/27/2007"

    ' Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  Else 
    MonthCalendar.wDate = "11/28/2007"
    MonthCalendar.wEndDate = "11/30/2007"
  End If
End Sub

DelphiScript

procedure Main;
var MonthCalendar;
begin

  // Obtain the MonthCalendar control
  MonthCalendar := Sys.Process('Project1').Window('TForm1', 'Form1').Window('TMonthCalendar');
     
  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect=false) then
  begin
    MonthCalendar.wDate := '11/27/2007';
  end
     
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
  begin
    MonthCalendar.wDate := '11/28/2007';
    MonthCalendar.wEndDate := '11/30/2007';
  end 
end;

C++Script, C#Script

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar = Sys["Process"]("Project1")["Window"]("TForm1", "Form1")["Window"]("TMonthCalendar");

  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    MonthCalendar["wDate"] = "11/27/2007";
  }
    
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
  {
    MonthCalendar["wDate"] = "11/28/2007";
    MonthCalendar["wEndDate"] = "11/30/2007";
  }
}

You can assign values to wDate and wEndDate using the SetDateElements method of the aqDateTime object. This method returns a date value formed from the given year, month and day.

Here is an example how you can perform this operation:

JavaScript, JScript

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar");

  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 27);
  }
    
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else 
  {
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 28);
    MonthCalendar.wEndDate = aqDateTime.SetDateElements(2007, 11, 30);
  }
}

Python

def Main():

  # Obtain the MonthCalendar control 
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")

  # Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if not MonthCalendar.wMultiSelect:
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 27)
    
  # Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else:
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 28)
    MonthCalendar.wEndDate = aqDateTime.SetDateElements(2007, 11, 30)

VBScript

Sub main
  Dim MonthCalendar

  ' Obtain the MonthCalendar control
  Set MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")
    
  ' Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  If MonthCalendar.wMultiSelect=False Then
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 27)

  ' Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  Else 
    MonthCalendar.wDate = aqDateTime.SetDateElements(2007, 11, 28)
    MonthCalendar.wEndDate = aqDateTime.SetDateElements(2007, 11, 30)
  End If
End Sub

DelphiScript

procedure Main;
var MonthCalendar;
begin

  // Obtain the MonthCalendar control
  MonthCalendar := Sys.Process('Project1').Window('TForm1', 'Form1').Window('TMonthCalendar');
    
  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect=false) then
  begin
    MonthCalendar.wDate := aqDateTime.SetDateElements(2007, 11, 27);
  end
    
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
  begin
    MonthCalendar.wDate := aqDateTime.SetDateElements(2007, 11, 28);
    MonthCalendar.wEndDate := aqDateTime.SetDateElements(2007, 11, 30);
  end 
end;

C++Script, C#Script

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar = Sys["Process"]("Project1")["Window"]("TForm1", "Form1")["Window"]("TMonthCalendar");

  // Set the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    MonthCalendar["wDate"] = aqDateTime["SetDateElements"](2007, 11, 27);
  }
   
  // Set the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
  {
    MonthCalendar["wDate"] = aqDateTime["SetDateElements"](2007, 11, 28);
    MonthCalendar["wEndDate"] = aqDateTime["SetDateElements"](2007, 11, 30);
  }
}

If you assign a value to wDate and it is greater than wEndDate, the MonthCalendar control will assign the value specified by wEndDate to wDate and select only this date. To avoid such confusion you can use the SetSelection action of the Win32MonthCalendar object.

This action specifies the range of dates in the MonthCalendar control. The first parameter of the SetSelection action specifies the first date of the range and the second parameter specifies the last date of the range. If the control does not support multi-selection, SetSelection selects only one date which is specified by the first parameter and the second parameter is ignored. If the MonthCalendar control supports multi-selection, this action selects the range of dates in the calendar.

If the first parameter of SetSelection is greater than the second parameter the MonthCalendar control will interchange their values and then select the range.

The selected range is not change if the first or the second parameter is less than wMinDate or greater than wMaxDate or if the specified range is wider than the maximum range set for the MonthCalendar control.

The following example demonstrates how you can use the SetSelection action to set the range of dates in the MonthCalendar which supports multi-selection or set one date in the control which does not support multi-selection:

JavaScript, JScript

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar");

  // Set the range of dates or one date (specified by the first parameter) if the MonthCalendar control does not support multi-selection
  MonthCalendar.SetSelection ("11/24/2007", "11/28/2007");
}

Python

def Main():

  # Obtain the MonthCalendar control 
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")

  # Set the range of dates or one date (specified by the first parameter) if the MonthCalendar control does not support multi-selection 
  MonthCalendar.SetSelection ("11/24/2007", "11/28/2007")

VBScript

Sub main
  Dim MonthCalendar

  ' Obtain the MonthCalendar control
  Set MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")
   
  ' Set the range of dates or one date (specified by the first parameter) if the MonthCalendar control does not support multi-selection
  MonthCalendar.SetSelection "11/24/2007", "11/28/2007"
End Sub

DelphiScript

procedure Main;
var MonthCalendar;
begin

  // Obtain the MonthCalendar control
  MonthCalendar := Sys.Process('Project1').Window('TForm1', 'Form1').Window('TMonthCalendar');
    
  // Set the range of dates or one date (specified by the first parameter) if the MonthCalendar control does not support multi-selection
  MonthCalendar.SetSelection('11/24/2007', '11/28/2007');
end;

C++Script, C#Script

function main()
{
  var MonthCalendar;

  // Obtain the MonthCalendar control
  MonthCalendar = Sys["Process"]("Project1")["Window"]("TForm1", "Form1")["Window"]("TMonthCalendar");

  // Set the range of dates or one date (specified by the first parameter) if the MonthCalendar control does not support multi-selection
  MonthCalendar["SetSelection"]("11/24/2007", "11/28/2007");
}

See Also

Working With MonthCalendar Controls in Desktop Windows Applications
Selecting Multiple Dates in MonthCalendar Controls in Desktop Windows Applications
wMultiSelect Property (MonthCalendar Controls)
wDate Property (Calendar Controls)
wEndDate Property (MonthCalendar Controls)
SetSelection Action (MonthCalendar Controls)
wMinDate Property (Calendar Controls)
wMaxDate Property (Calendar Controls)
aqDateTime Object
SetDateElements Method

Highlight search results