Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 DTPicker

Posted on 1999-06-22
7
Medium Priority
?
1,767 Views
Last Modified: 2008-03-10
Is there a bug in the DTPicker Control.
It doesn't seem to accept the .MinDate and the .MaxDate being set together. It only accepts one. If both set, then the one set first is actioned:-

DTPicker.MinDate="12/06/99"
DTPicker.MaxDate="19/06/99"

ie pick a date in one week only

if you Debug.? .MinDate and .MaxDate you get the right answer, BUT the control will let you pick a date after .MaxDate.

Is this a bug or am I doing something wrong
0
Comment
Question by:broadbent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
SLE earned 200 total points
ID: 1518927
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1518928
aha
0
 
LVL 4

Author Comment

by:broadbent
ID: 1518929
Microsoft wouldn't let me in
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:SLE
ID: 1518930
SYMPTOMS
When you programmatically set the DateTimePicker's MinDate property, any current setting for the MaxDate property is lost. Conversely, setting the MaxDate property causes a loss of the MinDate's setting.



CAUSE
When an attempt is made to set either the MinDate or MaxDate properties, a SendMessage API call is made to send the "DTM_SETRANGE" message to the control to inform it of the new date range settings. This message can be used to set the date range in one of three ways:

Establish a minimum date with no maximum date.


Establish a maximum date with no minimum date.


Establish both a minimum and maximum date.


The MinDate and MaxDate properties that are exposed to the Visual Basic programmer correspond directly to the first two methods. The DateTimePicker control does not offer any property that directly corresponds to the third method, thus leaving no way to set both a MinDate and a MaxDate at the same time through the control's object model.

This problem does not affect setting the MinDate and MaxDate properties at design time.



RESOLUTION
Because there is no exposed property or method for setting MinDate and MaxDate at the same time, a direct call to the SendMessage API must be made to manually send the "DTM_SETRANGE" message with the appropriate information.

The parameters for this message consist of setting wParam to represent the part(s) of the date range you are setting; "GDTR_MIN" for the minimum date, "GDTR_MAX" for the maximum date, or the combination of both constants for setting the minimum and maximum dates at the same time. The lParam must be set to point to a two element array of SYSTEMTIME structures. The first element is for specifying the minimum date information and the second element is for the maximum date information.



0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1518931
...and how does that translate to actual VB code?
0
 
LVL 2

Expert Comment

by:SLE
ID: 1518932
Steps to Reproduce Behavior
Create a new Standard EXE project. Form1 is created by default.


From the Project menu, choose References, select "Microsoft Windows Common Controls - 2 6.0", and then click OK.


Add a DTPicker control to Form1.


Add five command buttons to Form1.


Paste the following code into Form1's Code window:


   Option Explicit

   Private Sub Command1_Click()
      ' Set DTPicker MinDate through normal means.
      Me.DTPicker1.MinDate = "1/10/99"
   End Sub

   Private Sub Command2_Click()
      'Set DTPicker MaxDate through normal means.
      Me.DTPicker1.MaxDate = "1/17/99"
   End Sub

   Private Sub Command3_Click()
      Dim TimeArray(1) As SYSTEMTIME
      Dim result As Long

      ' Define first element of SYSTEMTIME Array to be minimum date.
      TimeArray(0).wDay = 10
      TimeArray(0).wMonth = 1
      TimeArray(0).wYear = 1999

      ' Call API to send message to control to set MinDate.
      result = SendMessage(Me.DTPicker1.hwnd, DTM_SETRANGE, _
         GDTR_MIN, TimeArray(0))
   End Sub

   Private Sub Command4_Click()
      Dim TimeArray(1) As SYSTEMTIME
      Dim result As Long

      ' Define second element of SYSTEMTIME Array to be maximum date.
      TimeArray(1).wDay = 17
      TimeArray(1).wMonth = 1
      TimeArray(1).wYear = 1999

      ' Call API to send message to control to set MaxDate.
      result = SendMessage(Me.DTPicker1.hwnd, DTM_SETRANGE, _
         GDTR_MAX, TimeArray(0))
   End Sub

   Private Sub Command5_Click()
      Dim TimeArray(1) As SYSTEMTIME
      Dim result As Long

      ' Define first element of SYSTEMTIME Array to be minimum date.
      TimeArray(0).wDay = 10
      TimeArray(0).wMonth = 1
      TimeArray(0).wYear = 1999

      ' Define second element of SYSTEMTIME Array to be maximum date.
      TimeArray(1).wDay = 17
      TimeArray(1).wMonth = 1
      TimeArray(1).wYear = 1999

      ' Call API to send message to control to set MinDate and MaxDate.
      result = SendMessage(Me.DTPicker1.hwnd, DTM_SETRANGE, _
         GDTR_MIN + GDTR_MAX, TimeArray(0))
   End Sub

   Private Sub Form_Load()
      Me.Command1.Caption = "Set DTPicker MinDate Normally"
      Me.Command2.Caption = "Set DTPicker MaxDate Normally"
      Me.Command3.Caption = "Set DTPicker MinDate Via API"
      Me.Command4.Caption = "Set DTPicker MaxDate Via API"
      Me.Command5.Caption = "Set DTPicker Min and MaxDate Via API"
   End Sub
From the Project menu, choose Add Module and add a standard Module to the project.


Paste the following code into the module:


      Option Explicit

      Public Type SYSTEMTIME
         wYear As Integer
         wMonth As Integer
         wDayOfWeek As Integer
         wDay As Integer
         wHour As Integer
         wMinute As Integer
         wSecond As Integer
         wMilliseconds As Integer
      End Type

      Public Declare Function SendMessage Lib "user32" Alias _
         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
         ByVal wParam As Long, lParam As Any) As Long

      Public Const DTM_SETRANGE = &H1004&
      Public Const GDTR_MIN = 1
      Public Const GDTR_MAX = 2

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1518933
Thanks - I hope broadbent rewards you properly!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question