Calendar drop-down box

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Calendar drop-down box

Post by tony_smith » Wed Aug 18, 2004 2:39 pm

Anyone out there know how to make a calendar selection box with VB? I don't know VB very well, but I have used some canned VB routines within my MSched scripts.

I am using the input> command to have the user enter a date field and then a time field, these are then used as arguments in running an application through Run Program>. The job fails if these inputs do not conform exactly to the local settings, so I want to take away some kestrokes from the user and make the application more friendly.

Thanks for any help you can give.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Aug 18, 2004 4:26 pm

No time to look now, but I would bet that you can find a free command line popup calendar tool.

Try to Google for "calendar tool" vbscript or "date picker" vbscript. Include vbscript with each phrase to help filter out some java script tools (unless you want to use java scripts).
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Lumumba

Post by Lumumba » Wed Aug 18, 2004 6:43 pm

On the other hand you can check the registry for that local settings and validate the input against it e.g. 18/08/2004 20:27:01

Position>/, ...
Position>:, ...

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Wed Aug 18, 2004 9:46 pm

Thanks Bob; I will search the net.

Thanks Lumumba; rather than trapping a user, I would rather trap the error... so giving them a GUI selection box prevents them from falling down.

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Date Picker

Post by kpassaur » Sun Aug 26, 2007 2:47 pm

Did anyone ever find a suitable date picker that works with MS? And if so do you have a sampe to view. I have looked and they all seem to be either Java based or ASP with vbscript. Which would make for a funny looking interface as you would be in an MS Dialog and then Internet Explorer would open to get a date.

It would be nice to have this built into MS in a Dialog box or as a standalone function like the Input box.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Aug 27, 2007 12:12 am

There is a date picker/calendar utility that I have used for years. It may not have the interface you want, but you can check it out.

TClockEx is freeware, available at: http://www.rcis.co.za/dale/tclockex/
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Mon Aug 27, 2007 1:01 am

exactly to the local settings
Tony,
By local settings do you mean the end user PC? If so, why not the
GetDate> & GetTime> commands at runtime?

I must not be understanding you correctly.

Ed

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Date Picker

Post by kpassaur » Mon Aug 27, 2007 7:10 am

Bob,

Thanks for the link, nifty little progam there but not what I had in mind. I just want to bring up a calendar, allow the user to go forward and backward and select a date.

Currently the user has to enter the date manually, and as you now different people enter them differently 01/01/2007, 01/01/07, 1/1/07 etc. If I had a calendar/date picker they would all be in the the same format. So, I quess you could say I am just looking for consistancy in the format.

Any other ideas?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 27, 2007 9:24 am

How about this little custom dialog I just knocked up. This code creates a "Date Picker" dialog. You could have a button on your dialog run this code. You then have the date the user selected in nDay, nMon and nYear.

Code: Select all

VBSTART
VBEND

Dialog>dlgDatePicker
   Caption=Date Picker
   Width=303
   Height=290
   Top=225
   Left=172
   Min=0
   Max=0
   Resize=0

   Button=x,16,72,17,25,10
   Button=x,56,72,17,25,11
   Button=x,96,72,17,25,12
   Button=x,136,72,17,25,13
   Button=x,176,72,17,25,14
   Button=x,216,72,17,25,15
   Button=x,256,72,17,25,16
   Button=x,16,104,17,25,17
   Button=x,56,104,17,25,18
   Button=x,96,104,17,25,19
   Button=x,136,104,17,25,20
   Button=x,176,104,17,25,21
   Button=x,216,104,17,25,22
   Button=x,256,104,17,25,23
   Button=x,16,136,17,25,24
   Button=x,56,136,17,25,25
   Button=x,96,136,17,25,26
   Button=x,136,136,17,25,27
   Button=x,176,136,17,25,28
   Button=x,216,136,17,25,29
   Button=x,256,136,17,25,30
   Button=x,16,168,17,25,31
   Button=x,56,168,17,25,32
   Button=x,96,168,17,25,33
   Button=x,136,168,17,25,34
   Button=x,176,168,17,25,35
   Button=x,216,168,17,25,36
   Button=x,256,168,17,25,37
   Button=x,16,200,17,25,38
   Button=x,56,200,17,25,39
   Button=x,96,200,17,25,40
   Button=x,136,200,17,25,41
   Button=x,176,200,17,25,42
   Button=x,216,200,17,25,43
   Button=x,256,200,17,25,44
   Button=x,16,234,17,25,45
   Button=x,56,234,17,25,46
   Button=x,96,234,17,25,47
   Button=x,136,234,17,25,48
   Button=x,176,234,17,25,49
   Button=x,216,234,17,25,50
   Button=x,256,234,17,25,51

   Button=->,240,16,33,25,502
   Button=<-,16,16,33,25,501

   Edit=txtYear,160,16,65,
   Edit=txtMonth,64,16,89,
   Label=M ,16,48,true
   Label=T ,56,48,true
   Label=W ,96,48,true
   Label=Th,136,48,true
   Label=F,176,48,true
   Label=Sa,216,48,true
   Label=Su,256,48,true
EndDialog>dlgDatePicker

//Define month name array
Let>mName[1]=January
Let>mName[2]=February
Let>mName[3]=March
Let>mName[4]=April
Let>mName[5]=May
Let>mName[6]=June
Let>mName[7]=July
Let>mName[8]=August
Let>mName[9]=September
Let>mName[10]=October
Let>mName[11]=November
Let>mName[12]=December

//Initialise
Year>nYear
Month>nMon
Let>nMon=nMon-0

Show>dlgDatePicker
GoSub>ResetButtons
Label>dpLoop

  GetDialogAction>dlgDatePicker,r
  If>r=501
    Let>nMon=nMon-1
	If>nMon=0
	  Let>nYear=nYear-1
	  Let>nMon=12
	Endif
	GoSub>ResetButtons
  Endif
  If>r=502
    Let>nMon=nMon+1
	If>nMon=13
	  Let>nYear=nYear+1
	  Let>nMon=1
	Endif
	GoSub>ResetButtons
  Endif
  If>r=2
    //User cancelled
	Let>cancelled=TRUE
    Goto>allDone
  Endif

  If>{(%r% > 9) AND (%r% < 67)}
     //A day button was clicked
	 Let>ndx=r-10
	 Let>daySelected=dlgDatePicker.msButton%ndx%
	 If>daySelected<>x
	   Let>nDay=daySelected
	   Let>cancelled=FALSE
	   Goto>allDone
	 Endif
  Endif

  Wait>0.3
Goto>dpLoop

Label>allDone
If>cancelled=FALSE
  MessageModal>User selected day %nDay% of Month %nMon% of Year %nYear%
Else
  MessageModal>User Cancelled
Endif


SRT>ResetButtons
  Let>dlgDatePicker.txtYear=%nYear%
  Let>txtMonth=mName[%nMon%]
  Let>dlgDatePicker.txtMonth=%txtMonth%

  //what day does the 1st of nMon fall on?
  VBEval>WeekDay(DateSerial(%nYear%,%nMon%,1)),nDay1

  //how many days in month
  VBEval>Day(DateAdd("d", -1, DateAdd("m", 1, "%nYear% - %nMon% -1"))),NumDays

  //blank out all buttons
  Let>k=0
  Repeat>k
    Let>dlgDatePicker.msButton%k%=x
	Let>k=k+1
  Until>k=40

  //If starts on Sunday
  If>nDay1=1
    Let>nDay1=8
  Endif

  //Set day numbers on appropriate buttons
  Let>NumDays=NumDays+1
  Let>btnStart=nDay1-2
  Let>k=btnStart
  Let>d=1
  Repeat>d
    Let>dlgDatePicker.msButton%k%=%d%
    Let>k=k+1
	Let>d=d+1
  Until>d=NumDays

  //Reset and redraw dialog
  ResetDialogAction>dlgDatePicker
End>ResetButtons
Paste the code into a new macro and run it to test it out. Will display the date you selected.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Date Picker for MS

Post by kpassaur » Mon Aug 27, 2007 10:11 am

Marcus,

Thank you, works great

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 27, 2007 10:46 am

Here's a version which hides the unused buttons. Much neater:

Code: Select all

VBSTART
VBEND

Dialog>dlgDatePicker
   Caption=Date Picker
   Width=303
   Height=290
   Top=225
   Left=172
   Min=0
   Max=0
   Resize=0

   Button=x,16,72,17,25,10
   Button=x,56,72,17,25,11
   Button=x,96,72,17,25,12
   Button=x,136,72,17,25,13
   Button=x,176,72,17,25,14
   Button=x,216,72,17,25,15
   Button=x,256,72,17,25,16
   Button=x,16,104,17,25,17
   Button=x,56,104,17,25,18
   Button=x,96,104,17,25,19
   Button=x,136,104,17,25,20
   Button=x,176,104,17,25,21
   Button=x,216,104,17,25,22
   Button=x,256,104,17,25,23
   Button=x,16,136,17,25,24
   Button=x,56,136,17,25,25
   Button=x,96,136,17,25,26
   Button=x,136,136,17,25,27
   Button=x,176,136,17,25,28
   Button=x,216,136,17,25,29
   Button=x,256,136,17,25,30
   Button=x,16,168,17,25,31
   Button=x,56,168,17,25,32
   Button=x,96,168,17,25,33
   Button=x,136,168,17,25,34
   Button=x,176,168,17,25,35
   Button=x,216,168,17,25,36
   Button=x,256,168,17,25,37
   Button=x,16,200,17,25,38
   Button=x,56,200,17,25,39
   Button=x,96,200,17,25,40
   Button=x,136,200,17,25,41
   Button=x,176,200,17,25,42
   Button=x,216,200,17,25,43
   Button=x,256,200,17,25,44
   Button=x,16,234,17,25,45
   Button=x,56,234,17,25,46
   Button=x,96,234,17,25,47
   Button=x,136,234,17,25,48
   Button=x,176,234,17,25,49
   Button=x,216,234,17,25,50
   Button=x,256,234,17,25,51

   Button=->,240,16,33,25,502
   Button=<-,16,16,33,25,501

   Edit=txtYear,160,16,65,
   Edit=txtMonth,64,16,89,
   Label=M ,16,48,true
   Label=T ,56,48,true
   Label=W ,96,48,true
   Label=Th,136,48,true
   Label=F,176,48,true
   Label=Sa,216,48,true
   Label=Su,256,48,true
EndDialog>dlgDatePicker

//Define month name array
Let>mName[1]=January
Let>mName[2]=February
Let>mName[3]=March
Let>mName[4]=April
Let>mName[5]=May
Let>mName[6]=June
Let>mName[7]=July
Let>mName[8]=August
Let>mName[9]=September
Let>mName[10]=October
Let>mName[11]=November
Let>mName[12]=December

//Initialise
Year>nYear
Month>nMon
Let>nMon=nMon-0

Show>dlgDatePicker
GoSub>ResetButtons
Label>dpLoop

  GetDialogAction>dlgDatePicker,r
  If>r=501
    Let>nMon=nMon-1
	If>nMon=0
	  Let>nYear=nYear-1
	  Let>nMon=12
	Endif
	GoSub>ResetButtons
  Endif
  If>r=502
    Let>nMon=nMon+1
	If>nMon=13
	  Let>nYear=nYear+1
	  Let>nMon=1
	Endif
	GoSub>ResetButtons
  Endif
  If>r=2
    //User cancelled
	Let>cancelled=TRUE
    Goto>allDone
  Endif

  If>{(%r% > 9) AND (%r% < 67)}
     //A day button was clicked
	 Let>ndx=r-10
	 Let>daySelected=dlgDatePicker.msButton%ndx%
	 If>daySelected<>x
	   Let>nDay=daySelected
	   Let>cancelled=FALSE
	   Goto>allDone
	 Endif
  Endif

  Wait>0.02
Goto>dpLoop

Label>allDone
If>cancelled=FALSE
  MessageModal>User selected day %nDay% of Month %nMon% of Year %nYear%
Else
  MessageModal>User Cancelled
Endif


SRT>ResetButtons
  Let>dlgDatePicker.txtYear=%nYear%
  Let>txtMonth=mName[%nMon%]
  Let>dlgDatePicker.txtMonth=%txtMonth%

  //what day does the 1st of nMon fall on?
  VBEval>WeekDay(DateSerial(%nYear%,%nMon%,1)),nDay1

  //how many days in month
  VBEval>Day(DateAdd("d", -1, DateAdd("m", 1, "%nYear% - %nMon% -1"))),NumDays

  //blank out all buttons
  Let>k=0
  Repeat>k
    Let>dlgDatePicker.msButton%k%=x
	Let>h=k
	//work around handle numbering bug in older 9.1 versions
	If>MSCHED_VER<9.1.04
	  Let>h=h+1
	Endif
	Let>thisHwnd=dlgDatePicker.msButton%h%.Handle
	LibFunc>User32,ShowWindow,r,thisHwnd,0
	Let>k=k+1
  Until>k=42

  //If starts on Sunday
  If>nDay1=1
    Let>nDay1=8
  Endif

  //Set day numbers on appropriate buttons
  Let>NumDays=NumDays+1
  Let>btnStart=nDay1-2
  Let>k=btnStart
  Let>d=1
  Repeat>d
    Let>dlgDatePicker.msButton%k%=%d%
	Let>h=k
	//work around handle numbering bug in older 9.1 versions
	If>MSCHED_VER<9.1.04
	  Let>h=h+1
	Endif
	Let>thisHwnd=dlgDatePicker.msButton%h%.Handle
	LibFunc>User32,ShowWindow,r,thisHwnd,1
    Let>k=k+1
	Let>d=d+1
  Until>d=NumDays

  //Reset and redraw dialog
  ResetDialogAction>dlgDatePicker
End>ResetButtons
BTW - I seem to have discovered a bug here with the button handle variables and the way they are numbered. Don't seem to match the numbering of the button names. The above works around it. Will get that looked at for a future update. Until then the above works fine.
Last edited by Marcus Tettmar on Thu Aug 30, 2007 11:33 am, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Mon Aug 27, 2007 2:25 pm

Wow Marcus,
That is really nice work.. Thanks.

Tony,
I am still curious about capturing 'TIME' and 'DATE' from the end user.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 27, 2007 2:48 pm

Ed,

Presumably Tony needs the user to enter a date which is not necessarily today's date.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Mon Aug 27, 2007 3:36 pm

I guess I am more interested in the business process that might require an end user to match a date and a time of day for that chosen date.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 27, 2007 3:42 pm

>I guess I am more interested in the business process that
>might require an end user to match a date and a time of day
>for that chosen date.

Not sure what you mean by that.

Tony just wants a way for a user to CHOOSE a date. I can think of plenty of reasons for doing that. Our reporting tool for example, asks me to choose a start and end date for the reporting period.

The point is that using a free format field for the user to enter the date is problematic since you can't guarantee that the user will use the same format you are expecting. You'd then have to validate the input. What if the user's regional settings use mm/dd/yyyy and you're expecting dd/mm/yyyy? One obvious solution is to use a dialog that has three fields for each date MM-DD-YYYY. So the user enters each part in three fields making up one date. You would still need to test that the user entered the right number of days for the month, and didn't enter alphas, or that the right number of digits were used for the month and year etc.

Using a Date Picker like the dialog I posted removes ALL these problems. Since the user can only click a button. Once he's done that you have the date and there is no ambiguity, and no need for input validation.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts