Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Change #1:
I check if MSIE is installed on the computer and give
a warning and exit if it is not.
Change #2:
Instead of putting the ChoiceButton value inside a
SPAN section, I put it inside a Hidden INPUT. This
way, it never affects the display.
Change #3:
I included the routine that creates the calendar.
This way, the user can browse form month to month.
Change #4:
I included the :WBERRORHANDLER subroutine with
IntControl(73), so the program does not crash if
the MSIE window is closed with Alt-F4 instead of
clicking on QUIT.
Change #5:
Displaying the calendar through browserdoc.writeln
was working fine, but this way, the PRINT function
would not work on all computers. On some machines,
only a blank sheet was printed! It took hours to
realize that MSIE versions lower than 5.5 were causing
the bug. Fortunately, if I put the HTML code in
a document on disk and open it in MSIE, the print
function works properly. Don't ask me why...
So I now create the file on disk and delete it
upon exiting.
Raymond
;======================================================= ;initialization ;======================================================= courant = dirget() gosub definitions if ismsieavailable() == 0 message("Error!", "This application requires Internet Explorer and it is not available...") exit endif ;======================================================= ;create the calendar for the current month ;======================================================= htmlpage = `<html><head><title>Calendrier</title>` htmlpage = strcat(htmlpage, @crlf, `<STYLE>.text {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Normal;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: Black}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.bold {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:bold;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: Black}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.titre1 {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:bold;FONT-STYLE:Normal;FONT-SIZE:14pt;COLOR: #0c9e84}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.titre2 {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:normal;FONT-STYLE:Normal;FONT-SIZE:12pt;COLOR: #0c9e84}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.dates {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Bold;FONT-STYLE:Normal;FONT-SIZE:12pt;COLOR: Black}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.blue {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Normal;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: Blue}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>.green {FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Normal;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: #0c9e84}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `<STYLE>input {border:0px;FONT-FAMILY:Arial,Helvetica,Sans-serif;FONT-WEIGHT:Normal;FONT-STYLE:Normal;FONT-SIZE:10pt;COLOR: #0c9e84}</STYLE>`) htmlpage = strcat(htmlpage, @crlf, `</head><body>`) htmlpage = strcat(htmlpage, @crlf, `<span id=entete>`, entete_html, `</span>`) htmlpage = strcat(htmlpage, @crlf, '<span id=calendar_table>', calendar(timeymdhms()), '</span>') htmlpage = strcat(htmlpage, @crlf, `<input type=HIDDEN name="ButtonChoice" value="none"></body></html>`) fileput(strcat(courant, "tempcal.htm"), htmlpage) ;======================================================= ;open the calendar ;======================================================= br = startmsie(strcat(courant, "tempcal.htm")) buttonchoice = all.buttonchoice ; <--- reference the hidden input field ButtonChoice... entete = all.entete browser.visible = @true ;======================================================= ;focus on today ;======================================================= today_day = itemextract(3, current_calendar, ":")+1-1 today_box = all.textbox%today_day% today_box.focus objectclose(today_box) ;======================================================= ;wait for a button to be clicked ;======================================================= While @true timedelay(0.5) choice = 0 intcontrol(73,2,0,0,0) choice = buttonchoice.value if choice <> 0 then buttonchoice.value = "none" intcontrol(73,0,0,0,0) if choice == 0 then break ; The browser has been closed. If choice <> "none" select @true case choice == "quit" objectclose(buttonchoice) objectclose(entete) br.quit break case choice == "previous" current_calendar = timesubtract(current_calendar, "0000:01:00:00:00:00") calendar_table = all.calendar_table calendar_table.innerhtml = calendar(current_calendar) box_1 = all.textbox1 box_1.focus objectclose(calendar_table) objectclose(box_1) break case choice == "next" current_calendar = timeadd(current_calendar, "0000:01:00:00:00:00") calendar_table = all.calendar_table calendar_table.innerhtml = calendar(current_calendar) box_1 = all.textbox1 box_1.focus objectclose(calendar_table) objectclose(box_1) break case choice == "print" ;delete buttons entete.innerhtml = "" ;print ie_header = "" ie_footer = "" errormode(@off) ie_header = regqueryvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[header]") ie_footer = regqueryvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[footer]") regsetvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[header]", "") regsetvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[footer]", "") browser.execwb(18, 0, null, null) ; Clear selection. browser.execwb(6, 2, null, null) ; PRINT, no prompt. regsetvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[header]", ie_header) regsetvalue(@regcurrent, "Software\Microsoft\Internet Explorer\PageSetup[footer]", ie_footer) errormode(@cancel) timedelay(2) ;bring back the buttons entete.innerhtml = entete_html break endselect endif EndWhile ;======================================================= ;delete the temporary file ;======================================================= filedelete(strcat(courant, "tempcal.htm")) exit ;============================================================================================================= :definitions ;============================================================================================================= null = objecttype("NULL", "") current_calendar = timeymdhms( ) ;======================================== ; #DefineSubRoutine calendar(date) day = strsub(date,9,2) month_names = "January,February,March,April,May,June,July,August,September,October,November,December" day_names = "Sunday, Monday, Tuesday,Wednesday,Thursday,Friday,Saturday" first_of_month = strcat(strsub(date,1,7), ":01:00:00:0") first_day_of_month = ((timejulianday(first_of_month)+5) mod 7)+1 month = itemextract(itemextract(2, date, ":"), month_names , ",") year = itemextract(1, date, ":") For days_in_month = 27 To 31 nextday = timeadd(first_of_month, strcat("0000:00:", days_in_month, ":00:00:00")) if strsub(first_of_month,1,7) <> strsub(nextday,1,7) then Break Next ;days_in_month holds the proper value calendrier_htm = strcat('<center><span class=titre1>', month, " ", year, '</span></center><br><br>') calendrier_htm = strcat(calendrier_htm, '<TABLE border=1 bordercolor="#0c9e84" cellspacing=0 align=center><TR>') for n=1 to 7 calendrier_htm = strcat(calendrier_htm, '<TD width=90 align="center" class=bold>', itemextract(n,day_names, ","), '</TD>') next calendrier_htm = strcat(calendrier_htm, '</tr><TR>') cal_case = 1 cal_date = 1 ;empty cells before first of the month ;===================================== while cal_case < first_day_of_month calendrier_htm = strcat(calendrier_htm, @crlf, '<td> </td>') if cal_case == 7 then calendrier_htm = strcat(calendrier_htm, @crlf, '</tr><tr>') cal_case = cal_case+1 endwhile ;cells for days of the month ;=========================== while cal_date <= days_in_month hier = cal_date-1 calendrier_htm = strcat(calendrier_htm, @crlf, `<TD width=90 height=60 valign="top" class=dates>`, cal_date) if hier <> 0 calendrier_htm = strcat(calendrier_htm, `<INPUT name=TextBox%cal_date% maxLength=15 size=10 onfocus="if (TextBox%cal_date%.value=='') {TextBox%cal_date%.value=TextBox%hier%.value;TextBox%cal_date%.select();}"><br>`) calendrier_htm = strcat(calendrier_htm, `<INPUT name=TextBox%cal_date%B maxLength=15 size=10 onfocus="if (TextBox%cal_date%B.value=='') {TextBox%cal_date%B.value=TextBox%hier%B.value;TextBox%cal_date%B.select()}"></td>`) else calendrier_htm = strcat(calendrier_htm, `<INPUT name=TextBox%cal_date% maxLength=15 size=10 onfocus="TextBox%cal_date%.select()"><br>`) calendrier_htm = strcat(calendrier_htm, `<INPUT name=TextBox%cal_date%B maxLength=15 size=10 onfocus="TextBox%cal_date%B.select()"></td>`) endif if cal_case mod 7 == 0 && cal_case <> 43 then calendrier_htm = strcat(calendrier_htm, @crlf, '</tr><tr>') cal_date = cal_date + 1 cal_case = cal_case+1 endwhile ;empty cells at the end of the month ;=================================== if cal_case <> 36 while 1 calendrier_htm = strcat(calendrier_htm, @crlf, '<TD width=90 height=75> </TD>') if cal_case mod 7 == 0 then break cal_case = cal_case+1 endwhile endif calendrier_htm = strcat(calendrier_htm, '</TR></table>') return(calendrier_htm) #EndSubRoutine ;======================================== ; entete_html = `<table width="100%%" border=0><tr><td><table border=1 cellspacing=0 cellpadding=0><tr><td>` entete_html = strcat(entete_html, `<input type="button" name="b1" tabindex="-1" value=" <<< " onclick="ButtonChoice.value='previous'" style="background: #0c9e84;color:white;Font-Weight:bold;">`) entete_html = strcat(entete_html, `</td></tr></table></td><td align=right><table border=1 cellspacing=0 cellpadding=0><tr><td>`) entete_html = strcat(entete_html, `<input type="button" name="b2" tabindex="-1" value=" print " onclick="ButtonChoice.value='print'" style="background: #0c9e84;color:white;Font-Weight:bold;">`) entete_html = strcat(entete_html, `</td></tr></table></td><td><table border=1 cellspacing=0 cellpadding=0><tr><td>`) entete_html = strcat(entete_html, `<input type="button" name="b3" tabindex="-1" value=" quit " onclick="ButtonChoice.value='quit'" style="background: #0c9e84;color:white;Font-Weight:bold;">`) entete_html = strcat(entete_html, `</td></tr></table></td><td align=right><table border=1 cellspacing=0 cellpadding=0><tr><td>`) entete_html = strcat(entete_html, `<input type="button" name="b4" tabindex="-1" value=" >>> " onclick="ButtonChoice.value='next'" style="background: #0c9e84;color:white;Font-Weight:bold;">`) entete_html = strcat(entete_html, `</td></tr></table></td></tr></table><br><br>`) ;======================================== ;======================================== #DefineSubRoutine startmsie(url) browser = objectopen("InternetExplorer.Application") browser.addressbar = @false browser.statusbar = @false browser.menubar = @false browser.toolbar = @false browser.visible = @false browser.navigate(url) WaitForPageLoad() browserdoc = browser.document all = browserdoc.all Return(browser) #EndSubRoutine #DefineSubroutine WaitForPageLoad() ; assume Browser While browser.busy || browser.readystate == 1 TimeDelay(0.5) EndWhile While browser.Document.ReadyState != "complete" TimeDelay(0.5) EndWhile return #EndSubroutine ;======================================== ;======================================== #DefineSubRoutine ismsieavailable() ie_key = `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE` if regexistvalue(@regmachine, ie_key) ie_program=regqueryvalue(@regmachine,ie_key) if fileexist(ie_program) then return(1) else return(0) endif #EndSubRoutine return :WBERRORHANDLER intcontrol(73,2,0,0,0) return ;=======================================================
Article ID: W16110
File Created: 2004:08:02:10:34:22
Last Updated: 2004:08:02:10:34:22