WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

COMCONTROL
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Holiday Sample Dialog using COM

 Keywords:  Dialog COM Holiday Day Date Event DropListbox MSScriptControl.ScriptControl WinHttp.WinHttpRequest.5.1 Web Service www.holidaywebservice.com

The script is for newcomers to WB dialogs and use of COM. It builds a very basic dialog, populates two drop-downs allowing the user to select a US Special Day / Holiday for a given year, then displays the specific day for the selection.

The dialog is 6.2; the script uses WinHttp.WinHttpRequest.5.1 and MSScriptControl.ScriptControl to gather and parse the date the event falls on. Again, very basic and for beginners.

HR>

;Winbatch 2011A - very simple web service example
;
;
;Returns date for Special Days/Holidays for the United States
;Web Service provided by http://www.holidaywebservice.com/
;and contains other holiday codes for other countries
;
;build codes and year for dropdowns on a basic WB dialog.
;Then uses a little Vbscript to return a formatted date
;
;This example uses a basic WB dialog without a Callback procedure.
;Since the user might wish to look up more than one date, using
;the basic dialog requires a little extra variable manipulation
;in order to be reused.
;I plan to post this script using a Callback for comparison.
;
;Stan Littlefield - November 30, 2011
;///////////////////////////////////////////////////////////////////////////
GoSub udfs
IntControl(73,1,0,0,0)

;build drop-down selections for holiday codes and years
codes="NEW-YEARS-DAY-ACTUAL|New Year's Day;NEW-YEARS-DAY-OBSERVED|New Year's Day;MARTIN-LUTHER-KING-BIRTHDAY-ACTUAL|Martin Luther King's Birthday;"
codes=codes:"MARTIN-LUTHER-KING-BIRTHDAY-OBSERVED|Martin Luther King's Birthday;GROUNDHOG-DAY|Groundhog Day;LINCOLN-BIRTHDAY|Abraham Lincoln's Birthday;"
codes=codes:"VALENTINES-DAY|Valentine's Day;WASHINGTON-BIRTHDAY|George Washington's Birthday;PRESIDENTS-DAY|President's Day;EASTER|Easter;"
codes=codes:"GOOD-FRIDAY|Good Friday;SHROVE-TUESDAY|Shrove Tuesday (Fat Tuesday);ASH-WEDNESDAY|Ash Wednesday;ST-PATRICKS-DAY|St. Patrick's Day;"
codes=codes:"APRIL-FOOLS|April Fools Day;EARTH-DAY|Earth Day;MOTHERS-DAY|Mother's Day;MEMORIAL-DAY|Memorial Day;CINCO-DE-MAYO|Cinco de Mayo;"
codes=codes:"FATHERS-DAY|Father's Day;FLAG-DAY|Flag Day;INDEPENDENCE-DAY-ACTUAL|Independence Day;INDEPENDENCE-DAY-OBSERVED|Independence Day;"
codes=codes:"LABOR-DAY|Labor Day;PATRIOT-DAY|Patriot Day;COLUMBUS-DAY|Columbus Day;HALLOWEEN|Halloween;VETERANS-DAY-ACTUAL|Veteran's Day;"
codes=codes:"VETERANS-DAY-OBSERVED|Veteran's Day;THANKSGIVING|Thanksgiving;BLACK-FRIDAY|Black Friday;CHRISTMAS-ACTUAL|Christmas;"
codes=codes:"CHRISTMAS-OBSERVED|Christmas;NEW-YEARS-EVE|New Year's Eve"
codes=StrReplace(codes,";",@TAB)
years=""

;feel free to try a different date range
y=2000
For i=1 To 50
   years=years:y:@TAB
   y=y+1
Next

;create the initial selected items
code=ItemExtract(1,codes,@TAB)
year=ItemExtract(1,years,@TAB)

;this is necessary as the dialog does not have a callback function
;but will be reused
savecodes=codes
saveyears=years

;create dialog with a goto point
:start
HFormat=`WWWDLGED,6.2`

HCaption=`US Special Days/Holidays`
HX=034
HY=093
HWidth=216
HHeight=076
HNumControls=005
HProcedure=`DEFAULT`
HFont=`DEFAULT`
HTextColor=`DEFAULT`
HBackground=`DEFAULT,DEFAULT`
HConfig=0

H001=`009,057,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT`
H002=`169,055,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",2,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
H003=`005,005,158,058,DROPLISTBOX,"Holidays",codes,%code%,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
H004=`171,005,036,060,DROPLISTBOX,"HYears",years,%year%,DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
H005=`009,025,158,026,STATICTEXT,"StaticText_1",DEFAULT,"Select Code and corresponding year, then click OK to calculate the exact date from a web service.",DEFAULT,50,DEFAULT,"Microsoft Sans Serif|6656|70|34","0|0|0",DEFAULT`

BP=Dialog("H")

If BP==2 Then Exit

;grab current values and reset dropdowns
code=codes
code1=ItemExtract(1,code,"|")
code2=ItemExtract(2,code,"|")
year=years
years=saveyears
codes=savecodes

;open the web service
cURL='http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx/GetHolidayDate?countryCode=UnitedStates&holidayCode=%code1%&year=%year%'
oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open("GET", cURL, @FALSE)
oHTTP.send()
oHTTP.WaitForResponse()
cResp=oHTTP.ResponseText
oHTTP = 0
;check for valid date return
n=StrIndex(cResp,"T00",0,@FWDSCAN)
If n>1
   date=StrSub(cResp,n-10,10)
   ;format the date with VbScript
   oS = CreateObject("MSScriptControl.ScriptControl")
   oS.Language = "VBScript"
   oS.AllowUI = @FALSE
   date=oS.Eval(: 'FormatDateTime(cDate("%date%"),1)')
   oS = 0
   Message("",code2:" for year ":year:@CRLF:"falls on ":date)
Else
   Display(2,"Sorry...","Date Could Not Be Calculated")
EndIf

;return to start point with last selection in focus
Goto start

:WBERRORHANDLER
oHTTP=0
ErrorProcessing(1,1,0,0)
Exit

:udfs
#DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array)
If VarType(Err_Array) ==256
   WbError = Err_Array[0]
   wberrorhandlerline = Err_Array[1]
   wberrorhandleroffset = Err_Array[2]
   wberrorhandlerassignment = Err_Array[3]
   wberrorhandlerfile = Err_Array[4]
   wberrortextstring = Err_Array[5]
   wberroradditionalinfo = Err_Array[6]
   wberrorinsegment = Err_Array[7]
Else
   WbError = LastError()
EndIf
WbTextcode = WbError
If WbError==1668||WbError==2669||WbError==3670
   WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":")
   WbTextcode = -1
EndIf
WbErrorString = IntControl(34,WbTextcode,0,0,0)
WbErrorDateTime = TimeYmdHms()
If deleteIni
   WbErrorFile = StrCat(ShortCutDir( 'AppData', 0, 0 ),'\WinBatch\Settings\')
   If ! DirExist(WbErrorFile) Then WbErrorFile = DirWindows(0)
   WbErrorFile = StrCat(WbErrorFile,"WWWBATCH.INI")
   FileDelete(WbErrorFile)
   IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorValue"   ,WbError                 ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorString"  ,WbErrorString           ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptLine"   ,WbErrorHandlerLine      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset    ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile)
   IniWritePvt("","","",WbErrorFile)
EndIf
WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF)
;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF)
If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN"
WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF)
If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF)
If logfile
   cSep = StrCat(StrFill("=",50),@CRLF)
   cLogFile = StrCat(DirScript(),"log.err")
   If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep))
   FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep))
   Display(2,"An Error Occured",StrCat("written to ",cLogFile))
Else
   If showerr
      WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF)
      Message("An Error Was Encountered",WbErrorMsgText)
   EndIf
EndIf
Return(1)
#EndSubRoutine

Return
;///////////////////////////////////////////////////////////////////////////////////////////////



Article ID:   W17702
Filename:   Holiday Sample Dialog using COM .txt
File Created: 2011:12:01:10:45:32
Last Updated: 2011:12:01:10:45:32