Getting MonthCalendar Date in Desktop Windows Applications

Applies to TestComplete 15.69, last modified on November 13, 2024

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.

To obtain the data currently selected in the MonthCalendar control you can use the wDate and wEndDate properties of the Win32MonthCalendar object which is automatically associated with MonthCalendar controls whose class names are listed in theObject Mapping options of your project.

If the MonthCalendar control does not support multi-selection, wDate returns the selected date. If the month calendar supports multi-selection, the wDate property returns the earliest date and the wEndDate property returns the last date in the range selected in the MonthCalendar control (for more information, see the Selecting Multiple Dates in MonthCalendar Controls in Desktop Windows Applications topic).

The following example demonstrates how you can obtain the date selected in the MonthCalendar:

JavaScript, JScript

function main()
{
  var MonthCalendar, d, e;
   
  // Obtain the MonthCalendar control
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar");
   
  // Get the value of wDate
  d = MonthCalendar.wDate;
   
  // Get the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    Log.Message(d);
  }
    
  // Get the first and the last date of the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else 
  {
    e = MonthCalendar.wEndDate;
    Log.Message(d);
    Log.Message(e);
  }
}

Python

def Main():
   
  # Obtain the MonthCalendar control
  MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")
   
  # Get the value of wDate
  d = MonthCalendar.wDate
   
  # Get the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if not MonthCalendar.wMultiSelect:
    Log.Message(d)
    
  # Get the first and the last date of the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else:
    e = MonthCalendar.wEndDate
    Log.Message(d)
    Log.Message(e)

VBScript

Sub main
  Dim MonthCalendar, d, e
   
  ' Obtain the MonthCalendar control
  Set MonthCalendar= Sys.Process("Project1").Window("TForm1", "Form1").Window("TMonthCalendar")

  ' Get the value of wDate
  d = MonthCalendar.wDate
    
  ' Get the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  If MonthCalendar.wMultiSelect=False Then
    Log.Message d

    ' Get the first and the last date of the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  Else 
    e = MonthCalendar.wEndDate
    Log.Message d
    Log.Message e
  End If 
End Sub

DelphiScript

procedure main;
var MonthCalendar, d, e;
begin

  // Obtain the MonthCalendar control
  MonthCalendar := Sys.Process('Project1').Window('TForm1', 'Form1').Window('TMonthCalendar');
   
  // Get the value of wDate
  d := MonthCalendar.wDate;
   
  // Get the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect=false) then
    begin
      Log.Message(d);
    end
    
  // Get the first and the last date of the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
    begin
      e := MonthCalendar.wEndDate;
      Log.Message(d);
      Log.Message(e);
    end 
end;

C++Script, C#Script

function main()
{
  var MonthCalendar, d, e;
   
  // Obtain the MonthCalendar control
  MonthCalendar = Sys["Process"]("Project1")["Window"]("TForm1", "Form1")["Window"]("TMonthCalendar");
   
  // Get the value of wDate
  d = MonthCalendar["wDate"];
   
  // Get the date if the MonthCalendar control does not support multi-selection of dates (wMultiSelect returns False)
  if (MonthCalendar.wMultiSelect==false)
  {
    Log.Message(d);
  }
   
  // Get the first and the last date of the range of dates if the MonthCalendar control supports multi-selection of dates (wMultiSelect returns True)
  else
  {
    e = MonthCalendar["wEndDate"];
    Log.Message(d);
    Log.Message(e);
  }
}

See Also

Working With MonthCalendar Controls in Desktop Windows Applications
wDate Property (Calendar Controls)
wEndDate Property (MonthCalendar Controls)
Selecting Multiple Dates in MonthCalendar Controls in Desktop Windows Applications

Highlight search results