Combo box to reflect date

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Jmac2501
Pro Scripter
Posts: 76
Joined: Tue Nov 15, 2005 8:11 pm

Combo box to reflect date

Post by Jmac2501 » Thu Apr 23, 2009 5:28 pm

Hey I have a script that I need help on. I want to make the combo boxs defalt to the date. for example msComboBox1 is the month and it always starts at 1, I would like it to change with the date like say its april, I would want it to defalt to 4 instead of 1. is there a way to do that?

Thanks

Code: Select all

Dialog>Dialog1
   Caption=Outlook Appointment Maker
   Width=381
   Height=296
   Top=461
   Left=356
   ComboBox=msComboBox1,80,24,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12
   ComboBox=msComboBox2,160,24,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12%CRLF%13%CRLF%14%CRLF%15%CRLF%16%CRLF%17%CRLF%18%CRLF%19%CRLF%20%CRLF%21%CRLF%22%CRLF%23%CRLF%24%CRLF%25%CRLF%26%CRLF%27%CRLF%28%CRLF%29%CRLF%30%CRLF%31
   ComboBox=msComboBox3,248,24,73,1:00%CRLF%1:30%CRLF%2:00%CRLF%2:30%CRLF%3:00%CRLF%3:30%CRLF%4:00%CRLF%4:30%CRLF%5:00%CRLF%5:30%CRLF%6:00%CRLF%6:30%CRLF%7:00%CRLF%7:30%CRLF%8:00%CRLF%8:30%CRLF%9:00%CRLF%9:30%CRLF%10:00%CRLF%10:30%CRLF%11:00%CRLF%11:30%CRLF%12:00%CRLF%12:30%CRLF%13:00%CRLF%13:30%CRLF%14:00%CRLF%14:30%CRLF%15:00%CRLF%15:30%CRLF%16:00%CRLF%16:30%CRLF%17:00%CRLF%17:30%CRLF%18:00%CRLF%18:30%CRLF%19:00%CRLF%19:30%CRLF%20:00%CRLF%20:30%CRLF%21:00%CRLF%21:30%CRLF%22:00%CRLF%22:30%CRLF%23:00%CRLF%23:30%CRLF%24:00
   ComboBox=msComboBox4,80,72,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12
   ComboBox=msComboBox5,160,72,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12%CRLF%13%CRLF%14%CRLF%15%CRLF%16%CRLF%17%CRLF%18%CRLF%19%CRLF%20%CRLF%21%CRLF%22%CRLF%23%CRLF%24%CRLF%25%CRLF%26%CRLF%27%CRLF%28%CRLF%29%CRLF%30%CRLF%31
   ComboBox=msComboBox6,248,72,73,1:00%CRLF%1:30%CRLF%2:00%CRLF%2:30%CRLF%3:00%CRLF%3:30%CRLF%4:00%CRLF%4:30%CRLF%5:00%CRLF%5:30%CRLF%6:00%CRLF%6:30%CRLF%7:00%CRLF%7:30%CRLF%8:00%CRLF%8:30%CRLF%9:00%CRLF%9:30%CRLF%10:00%CRLF%10:30%CRLF%11:00%CRLF%11:30%CRLF%12:00%CRLF%12:30%CRLF%13:00%CRLF%13:30%CRLF%14:00%CRLF%14:30%CRLF%15:00%CRLF%15:30%CRLF%16:00%CRLF%16:30%CRLF%17:00%CRLF%17:30%CRLF%18:00%CRLF%18:30%CRLF%19:00%CRLF%19:30%CRLF%20:00%CRLF%20:30%CRLF%21:00%CRLF%21:30%CRLF%22:00%CRLF%22:30%CRLF%23:00%CRLF%23:30%CRLF%24:00
   Edit=msEdit1,80,120,257,
   Edit=msEdit2,80,152,257,
   Edit=msEdit3,80,184,257,
   Label=Start Time,24,24,true
   Label=End Time,24,72,true
   Button=Post Appointment,88,216,97,25,2
   Button=Exit,232,216,89,25,1
   Label=Month,80,8,true
   Label=Date,160,8,true
   Label=Time,248,8,true
   Label=Month,80,56,true
   Label=Date,160,56,true
   Label=Time,248,56,true
   Label=Subject,24,120,true
   Label=Location,24,152,true
   Label=Message,24,184,true
EndDialog>Dialog1
   EndDialog>Dialog1

Label>MainLoop
Show>Dialog1,result
If>result=1,End
If>result=2,1
Goto>MainLoop

label>1
VBSTART

Sub CreateAppointment (strSubject, strStart, strEnd, strLocation, strMsg)
   Set outlookApp = CreateObject("Outlook.Application")
   Set oItems = outlookApp.CreateItem(1)  'olAppointmentItem=1
   oItems.Subject = strSubject
   oItems.Start = strStart
   oItems.End = strEnd
   oItems.Location = strLocation
   oItems.Body = strMsg
   'Remove next line to stop appointment appearing on screen
   oItems.Display
   oItems.Save
   'Uncomment next line to close (commented out for demo)
   'outlookApp.Quit

   '** Other properties available
   '** oItems.ReminderSet = TRUE|FALSE
   '** oItems.ReminderMinutesBeforeStart = numMins
   '** oItems.RequiredAttendees = strAttendees
   '** send to recipients
   '** oItems.Send

End Sub

VBEND

Let>subject=%Dialog1.msEdit1%
Let>location=%Dialog1.msEdit2%
Let>start=%Dialog1.msComboBox1%/%Dialog1.msComboBox2%/2009 %Dialog1.msComboBox3%
Let>end=%Dialog1.msComboBox4%/%Dialog1.msComboBox5%/2009 %Dialog1.msComboBox6%
Let>msg=%Dialog1.msEdit3%

VBRun>CreateAppointment,%subject%,%start%,%end%,%location%,%msg%

label>End


User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Apr 23, 2009 5:55 pm

Use the Month> Day> Year> Hour> min> Sec> functions to get current time then set the Dialog.mscombobox.itemindex variables based on the functions' output.

Here's the first month combo box done for you. ItemIndex is zero based counting so you will need to subtract 1 from each date function result. With time functions you might need to get more elaborate but the concept is the same, preset the Dialog.mscombobox.itemindex variable

Code: Select all

Month>mm
Sub>mm,1
Let>dialog1.mscombobox1.itemindex=mm

Dialog>Dialog1
   Caption=Outlook Appointment Maker
   Width=381
   Height=296
   Top=461
   Left=356
   ComboBox=msComboBox1,80,24,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12
   ComboBox=msComboBox2,160,24,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12%CRLF%13%CRLF%14%CRLF%15%CRLF%16%CRLF%17%CRLF%18%CRLF%19%CRLF%20%CRLF%21%CRLF%22%CRLF%23%CRLF%24%CRLF%25%CRLF%26%CRLF%27%CRLF%28%CRLF%29%CRLF%30%CRLF%31
   ComboBox=msComboBox3,248,24,73,1:00%CRLF%1:30%CRLF%2:00%CRLF%2:30%CRLF%3:00%CRLF%3:30%CRLF%4:00%CRLF%4:30%CRLF%5:00%CRLF%5:30%CRLF%6:00%CRLF%6:30%CRLF%7:00%CRLF%7:30%CRLF%8:00%CRLF%8:30%CRLF%9:00%CRLF%9:30%CRLF%10:00%CRLF%10:30%CRLF%11:00%CRLF%11:30%CRLF%12:00%CRLF%12:30%CRLF%13:00%CRLF%13:30%CRLF%14:00%CRLF%14:30%CRLF%15:00%CRLF%15:30%CRLF%16:00%CRLF%16:30%CRLF%17:00%CRLF%17:30%CRLF%18:00%CRLF%18:30%CRLF%19:00%CRLF%19:30%CRLF%20:00%CRLF%20:30%CRLF%21:00%CRLF%21:30%CRLF%22:00%CRLF%22:30%CRLF%23:00%CRLF%23:30%CRLF%24:00
   ComboBox=msComboBox4,80,72,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12
   ComboBox=msComboBox5,160,72,73,1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7%CRLF%8%CRLF%9%CRLF%10%CRLF%11%CRLF%12%CRLF%13%CRLF%14%CRLF%15%CRLF%16%CRLF%17%CRLF%18%CRLF%19%CRLF%20%CRLF%21%CRLF%22%CRLF%23%CRLF%24%CRLF%25%CRLF%26%CRLF%27%CRLF%28%CRLF%29%CRLF%30%CRLF%31
   ComboBox=msComboBox6,248,72,73,1:00%CRLF%1:30%CRLF%2:00%CRLF%2:30%CRLF%3:00%CRLF%3:30%CRLF%4:00%CRLF%4:30%CRLF%5:00%CRLF%5:30%CRLF%6:00%CRLF%6:30%CRLF%7:00%CRLF%7:30%CRLF%8:00%CRLF%8:30%CRLF%9:00%CRLF%9:30%CRLF%10:00%CRLF%10:30%CRLF%11:00%CRLF%11:30%CRLF%12:00%CRLF%12:30%CRLF%13:00%CRLF%13:30%CRLF%14:00%CRLF%14:30%CRLF%15:00%CRLF%15:30%CRLF%16:00%CRLF%16:30%CRLF%17:00%CRLF%17:30%CRLF%18:00%CRLF%18:30%CRLF%19:00%CRLF%19:30%CRLF%20:00%CRLF%20:30%CRLF%21:00%CRLF%21:30%CRLF%22:00%CRLF%22:30%CRLF%23:00%CRLF%23:30%CRLF%24:00
   Edit=msEdit1,80,120,257,
   Edit=msEdit2,80,152,257,
   Edit=msEdit3,80,184,257,
   Label=Start Time,24,24,true
   Label=End Time,24,72,true
   Button=Post Appointment,88,216,97,25,2
   Button=Exit,232,216,89,25,1
   Label=Month,80,8,true
   Label=Date,160,8,true
   Label=Time,248,8,true
   Label=Month,80,56,true
   Label=Date,160,56,true
   Label=Time,248,56,true
   Label=Subject,24,120,true
   Label=Location,24,152,true
   Label=Message,24,184,true
EndDialog>Dialog1
   EndDialog>Dialog1

Label>MainLoop
Show>Dialog1,result
If>result=1,End
If>result=2,1
Goto>MainLoop

label>1
VBSTART

Sub CreateAppointment (strSubject, strStart, strEnd, strLocation, strMsg)
   Set outlookApp = CreateObject("Outlook.Application")
   Set oItems = outlookApp.CreateItem(1)  'olAppointmentItem=1
   oItems.Subject = strSubject
   oItems.Start = strStart
   oItems.End = strEnd
   oItems.Location = strLocation
   oItems.Body = strMsg
   'Remove next line to stop appointment appearing on screen
   oItems.Display
   oItems.Save
   'Uncomment next line to close (commented out for demo)
   'outlookApp.Quit

   '** Other properties available
   '** oItems.ReminderSet = TRUE|FALSE
   '** oItems.ReminderMinutesBeforeStart = numMins
   '** oItems.RequiredAttendees = strAttendees
   '** send to recipients
   '** oItems.Send

End Sub

VBEND

Let>subject=%Dialog1.msEdit1%
Let>location=%Dialog1.msEdit2%
Let>start=%Dialog1.msComboBox1%/%Dialog1.msComboBox2%/2009 %Dialog1.msComboBox3%
Let>end=%Dialog1.msComboBox4%/%Dialog1.msComboBox5%/2009 %Dialog1.msComboBox6%
Let>msg=%Dialog1.msEdit3%

VBRun>CreateAppointment,%subject%,%start%,%end%,%location%,%msg%

label>End

Jmac2501
Pro Scripter
Posts: 76
Joined: Tue Nov 15, 2005 8:11 pm

Post by Jmac2501 » Thu Apr 23, 2009 5:59 pm

yeah thanks I got it working by using

Code: Select all

month>x
day>y
let>x=x-1
let>Dialog1.msComboBox1.ItemIndex=%x%
let>Dialog1.msComboBox2.ItemIndex=%y%
let>Dialog1.msComboBox4.ItemIndex=%x%
let>Dialog1.msComboBox5.ItemIndex=%y%
let>Dialog1.msComboBox3.ItemIndex=22
let>Dialog1.msComboBox6.ItemIndex=22
it was the let>Dialog1.msComboBox.ItemIndex that was holding me up.

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Apr 23, 2009 6:04 pm

it was the let>Dialog1.msComboBox.ItemIndex that was holding me up.
Yeah, I suspected you'd only need that nudge. Still, I need to make the explanation more elaborate for the guy who reads this next year and doesn't quite have your level of experience.

I want to point out one more thing I noticed about your script. The "X" in the upper right hand corner of a dialog is a button. Clicking that button produces a result of "2". You have created an "Exit" and a "Post..." button with results of 1 and 2 respectively. The problem occurs if someone clicks the upper right "X". The user expects that click will close the process and instead it will run the process. You should either set the dialog "close" variable to 1 (a line in the dialog block that is close=1) or more preferably, set your exit button result to 2 and your Post Appointment button result to 3 or any number other than 2.

Hope this makes sense,
Dick

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Apr 24, 2009 1:57 am

Hi Jmac2501,

Just to backup what JRL mentioned about using a value of 2 for your dialog Exit button... here's what the Help File says about it...
'Dialog' topic in Help File wrote:The result of a dialog (returned by the Show and GetDialogAction commands) is set to the modal result value of the button that was pressed. If a Dialog is closed without a button being pressed, e.g. the user pressed the close button, the result will be set to 2. Modal result 2 means the dialog was canceled. Bear this in mind when assigning modal result values to buttons. It is advisable to use anything other than 2. 1 is commonly used for OK.
Just something that we have to remember... take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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