Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
#DefineFunction hBrowseHidden() ; first see if the data file is there, if not exit... hpath = "c:\Program Files\HTMLExtender\" filename = StrCat(hpath, "hdata.txt") Terminate(!FileExist(filename), "Debug", "Browser Data File Missing.") ; read the data, paint the hidden screen... html = "" ih = FileOpen(filename, "read") While @TRUE line = FileRead(ih) If line == "*EOF*" Then Break html = StrCat(html, line) EndWhile FileClose(ih) Browser = ObjectOpen("InternetExplorer.Application") browser.visible = @FALSE url = "C:\Test\Blank.html" browser.navigate(url) ; setup the document object... browserDoc = Browser.Document browserdoc.writeln(html) ObjectClose(browserdoc) ; get a list of variable names and their values... hvarnamelist = processHTML(browser, 1) hvarvaluelist = processHTML(browser, 2) hpath = "c:\Program Files\HTMLExtender\" filename = StrCat(hpath, "hvarnamelist.txt") oh = FileOpen(filename, "write") FileWrite(oh, hvarnamelist) FileClose(oh) filename = StrCat(hpath, "hvarvaluelist.txt") oh = FileOpen(filename, "write") FileWrite(oh, hvarvaluelist) FileClose(oh) ObjectClose(browser) Return #EndSubRoutine #DefineFunction hEndBrowse(browser) ;, html) ; close the browser and the OLE object... browser.quit ObjectClose(browser) ; setup a hidden browser and write out the last snapshot of data... hBrowseHidden() #EndFunction #DefineFunction hGetHTML(browser) ; an extra function usuable if you for some reason need to save the page's HTML, ; it will save the changes made by the user...(if any)...I used this for debugging... ;;;;; if !hGetURL(browser) then return ; <--- check the URL and make sure it's valid ; I was forced to keep the above line commented otherwise I'd get the NESTING OF ; STRUCTURES TOO COMPLEX error message. ; setup a reference to the browser's document... browserdoc = browser.document ; retrieve the HTML collection... bcoll = browserdoc.getElementsByTagName("HTML") ; reference the first member of the collection... bitem = bcoll.item(0) ; reference the actual HTML... bHTML = bitem.outerHTML ; <--- use OUTER html to get everything... ; close the OLE objects... ObjectClose(bitem) ObjectClose(bcoll) ObjectClose(browserdoc) ; <HTML><HEAD></HEAD><BODY></BODY></HTML> If !StrIndexNC(bHTML, "The page you are looking for is currently unavailable", 1, @FWDSCAN) && StrReplace(bHTML, @CRLF, "") <> "<HTML><HEAD></HEAD><BODY></BODY></HTML>" hpath = "c:\Program Files\HTMLExtender\" filename = StrCat(hpath, "hdata.txt") oh = FileOpen(filename, "write") FileWrite(oh, bHTML) FileClose(oh) Return(1) Else Return(0) EndIf #EndFunction #DefineFunction hGetURL(browser) ; check to see if the current locationURL contains the error message ; from a non-existant page... Return(hGetHTML(browser)) #EndFunction #DefineFunction hSetupEnvironment() ; this is a private function called when the first hBrowse is used... hpath = "c:\Program Files\HTMLExtender\" If !DirExist(hpath) Then DirMake(hpath) Return #EndFunction #DefineFunction hBrowse(action, url, flags) ; make some preliminary checks for correct arguments... Terminate(url == "", "Debug", "No URL...exiting program.") Terminate(action < 1 || action > 2 || !IsNumber(action), "Debug", "ACTION argument invalid.") ; set up the environment to handle the data... hSetupEnvironment() Select @TRUE Case action == 1 ; start the normal browser... hbr = startMSIE(url) Break Case action == 2 ; start the browser, but remove navigation buttons if the "2" flag is specified... hbr = startMSIE(url) If StrIndexNC(flags, "2", 1, @FWDSCAN) hbr.addressbar = @FALSE hbr.statusbar = @FALSE hbr.menubar = @FALSE hbr.toolbar = @FALSE EndIf ; remove the nav buttons and the close buttons if the "4" flag is specified... If StrIndexNC(flags, "4", 1, @FWDSCAN) Then hbr.fullscreen = @TRUE Break EndSelect ; once navigation is complete, show the browser... hbr.visible = @TRUE ; return a reference to the browser object for other functions... Return(hbr) #EndFunction #DefineFunction startMSIE(url) ; internal function, starts the browser and navigates to specified URL... Browser = ObjectOpen("InternetExplorer.Application") browser.visible = @FALSE browser.navigate(url) While Browser.busy || Browser.readystate <> 4 TimeDelay(0.5) EndWhile ; return a reference to the browser object... Return(browser) #EndFunction #DefineFunction hGetVarNames() ; find the folder where the variable list is located... hpath = "c:\Program Files\HTMLExtender\" filename = StrCat(hpath, "hvarnamelist.txt") Terminate(!FileExist(filename), "Debug", "Variable File Missing.") ; retrieve it and return it to the user... hvlist = "" ih = FileOpen(filename, "read") While @TRUE line = FileRead(ih) If line == "*EOF*" Then Break hvlist = StrCat(hvlist, line) EndWhile FileClose(ih) Return(hvlist) #EndFunction #DefineFunction hGetVarValue(variable, DEFAULT) ; find the folder where the variable values are stored... hpath = "c:\Program Files\HTMLExtender\" filename = StrCat(hpath, "hvarvaluelist.txt") Terminate(!FileExist(filename), "Debug", "Variable Value File Missing.") hvarnamelist = hGetVarNames() ; build the list and process it... hvarvaluelist = "" ih = FileOpen(filename, "read") While @TRUE line = FileRead(ih) If line == "*EOF*" Then Break hvarvaluelist = StrCat(hvarvaluelist, line) EndWhile FileClose(ih) ; check to see if the variable specified is in the var list... hpos = ItemLocate(variable, hvarnamelist, @TAB) ; if it is, get it's value, otherwise return the default value specified... If hpos hval = StrTrim(ItemExtract(hpos, hvarvaluelist, @TAB)) Return(hval) Else ; note: that if your variable is present, but has no value (eg, "") it will return "", ; not the default text, as per the original function. Return(DEFAULT) EndIf #EndFunction #DefineFunction processHTML(browser, option) ; internal function that "inventories" the HTML page... ; first make sure the arguments are valid... Terminate(option <> 1 && option <> 2, "Debug", "processHTML...OPTION argument invalid.") ; setup a reference to the document object... browserdoc = browser.document ; initialize the list vars... hvlist = "" hvvalues = "" ; list of tags that users can supply input to on an HTML page... htaglist = "INPUT,SELECT,TEXTAREA" For y = 1 To ItemCount(htaglist, ",") tag = ItemExtract(y, htaglist, ",") ; check for this tag in the document... vartags = browserdoc.getElementsByTagName(tag) For x = 0 To vartags.length-1 ; loop thru them one by one and get their corresponding values thistag = vartags.item(x) If thistag > 0 ; avoid "nameless" objects and those already on the list... If thistag.name <> "" && !ItemLocate(thistag.name, hvlist, @TAB) ; check the tag types... Select @TRUE Case tag == "INPUT" || tag == "TEXTAREA" ; look for a radio or checkbox... If thistag.type == "radio" || thistag.type == "checkbox" If thistag.checked ; don't place it in the variable list until checked, if it's left unchecked ; it won't appear in the list and hGetVar() will return the default value... hvlist = ItemInsert(thistag.name, -1, hvlist, @TAB) hvvalues = ItemInsert(thistag.value, -1, hvvalues, @TAB) EndIf Else ; normal INPUT object, get the value... hvlist = ItemInsert(thistag.name, -1, hvlist, @TAB) If thistag.value == "" ; have to insert a SPACE for blank INPUTs, don't worry the return value gets STRTRIM() in hGetVar() and returns ""... hvvalues = ItemInsert(" ", -1, hvvalues, @TAB) Else data = StrReplace(thistag.value, @TAB, " ") hvvalues = ItemInsert(data, -1, hvvalues, @TAB) EndIf EndIf Break ; SELECT tags are special... Case tag == "SELECT" hvlist = ItemInsert(thistag.name, -1, hvlist, @TAB) selOptions = thistag.Options hvvalues = ItemInsert(selOptions.selectedIndex, -1, hvvalues, @TAB) ObjectClose(selOptions) Break EndSelect EndIf ObjectClose(thistag) EndIf Next ObjectClose(vartags) Next ObjectClose(browserdoc) ; return either a list of variable names, or the list of values based on the argument... If option == 1 Return(hvlist) Else Return(hvvalues) EndIf #EndFunction ; Marty was kind enough to send me the source code for the HTML extender ; and I went thru it and expected to discover the secret way the C code ; was determining that a button on the browser had been pushed and I was ; going to somehow translate that into Winbatch code. My surprise was that ; the C source did no such thing, it just simply looked to see if the URL ; was blank, much like the HTML Dialog help file. Marty had once mentioned ; to me that working with the browser wasn't too arcane and of course he ; was right. So like good little Borg I adapted and it lead me to inspect ; the .locationURL property and I found that when an HTML form/page is ; submitted locally the text "ignored" appears in the .locationURL, and ; it's that simple. As the saying goes, the rest is... ; I had to modify a few functions slightly and I added some PRIVATE FUNCTIONS ; which the code uses and are transparent to the coder. ; hBrowse() -- no longer closes the window (see above) and mimics *most* of the ; original's functions. Try it and see what works for you. ; New is hEndBrowse() -- which closes the browser (yes you could ; simply issue the .quit method, but this helps the non-MSIE/OLE people a bit). ; hGetURL() -- a function which examines the current URL of the browser to check ; if it's valid. This was necessary to make sure the page was still part of the ; document, so that the variable list and they're corresponding values weren't ; lost if the document closed before the "inventory" was complete (which happened ; constantly at first during testing). ; hGetVarNames() -- roughly the same as the original, behind the scenes -- much ; different. ; hGetVarValue() -- roughly the same as the original, behind the scenes -- much ; different. ; hGetHTML() -- is a private function, needed to place the page's HTML into a ; file, so it can be read later to give an accurate reading of what the user ; had submitted. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; You don't have to use forms on the page anymore since these functions ; "inventory" the entire page for input objects. Make sure you NAME each ; object though with the standard: name="MyName" so that your variable gets ; recorded. AVOID using the same name multiple times. ; ; unchecked checkboxes will not show up on the hVarNames, so if you query ; one for the value, you'll get the default value you specify returned to you. ; see below. also read the comments inside the function PROCESSHTML(). ; ; some variables can return an empty string "", such as TEXTAREAs that are ; left blank. this is different than a variable that is NOT THERE, so these ; WON'T RETURN A DEFAULT VALUE. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Notes: I had to use text files since functions kept variables separate ; and I wanted to keep as much as possible TRANSPARENT to the user. ; I tried using WSC but that would force a combination of #INCLUDE with ; these functions plus using the WSC file, which seemed a waste. I s'pose ; a better option would be a WSC file with it all in there, but I prefer ; to code in Winbatch where possible. :) ; BTW -- file paths are hardcoded since using DIRGET() is problematic ; due to the fact that the script could change folders or drives and the ; functions would then miss data. ;The page you are looking for is currently unavailable ;. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.
#Include "c:\test\html functions.wbt" ; This is a beta version of the HTML Extender for MSIE using OLE. ; I'd appreciate it if you could test it and see how it works. This ; is the 3rd version I've done on my own and is the most consistent. ; Please feel free to make suggestions or complaints, I'd be interested ; in what you find out. Best thing is you can re-code for your own ; needs. ; I'm using Winbatch 2002G, MSIE 6. ; Marty was kind enough to send me the source code for the HTML extender ; and I went thru it and expected to discover the secret way the C code ; was determining that a button on the browser had been pushed and I was ; going to somehow translate that into Winbatch code. My surprise was that ; the C source did no such thing, it just simply looked to see if the URL ; was blank, much like the HTML Dialog help file. Marty had once mentioned ; to me that working with the browser wasn't too arcane and of course he ; was right. So like good little Borg I adapted and it lead me to inspect ; the .locationURL property and I found that when an HTML form/page is ; submitted locally the text "ignored" appears in the .locationURL, and ; it's that simple. As the saying goes, the rest is... ; I had to modify a few functions slightly and I ADDED SOME PRIVATE FUNCTIONS ; which the code uses and are transparent to the coder. ; hBrowse() -- no longer closes the window and mimics *most* of the ; original's functions. Try it and see what works for you. ; New is hEndBrowse() -- which closes the browser (yes you could ; simply issue the .quit method, but this helps the non-MSIE/OLE people a bit). ; hGetURL() -- a function which examines the current URL of the browser to check ; if it's valid. This was necessary to make sure the page was still part of the ; document, so that the variable list and they're corresponding values weren't ; lost if the document closed before the "inventory" was complete (which happened ; constantly during testing). ; hGetVarNames() -- roughly the same as the original, behind the scenes -- much ; different. ; hGetVarValue() -- roughly the same as the original, behind the scenes -- much ; different. ; hGetHTML() -- is a private function, needed to place the page's HTML into a ; file, so it can be read later to give an accurate reading of what the user ; had submitted, otherwise the program dropped variables and values. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; You don't have to use forms on the page anymore since these functions ; "inventory" the ENTIRE page for input objects. Make sure you NAME each ; object though with the standard: name="MyName" so that your variable gets ; recorded. AVOID using the same name multiple times. ; ; unchecked checkboxes will not show up on the hVarNames(), so if you query ; one for the value, you'll get the default value you specify returned to you. ; (see next paragraph) also read the comments inside the function PROCESSHTML(). ; ; some variables can return an empty string "", such as TEXTAREAs that are ; left blank. this is different than a variable that is NOT THERE, so these ; WON'T RETURN A DEFAULT VALUE if you specify one. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Notes: I had to use text files since functions kept variables separate ; and I wanted to keep as much as possible TRANSPARENT to the user. ; I tried using WSC but that would force a combination of #INCLUDE with ; these functions plus using the WSC file, which seemed superfluous. I s'pose ; a better option would be a WSC file with it all in there, but I prefer ; to code in Winbatch where possible. :) ; BTW -- file paths are hardcoded since using DIRGET() is problematic ; due to the fact that the script could change folders or drives and the ; functions would then miss the data. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; sample code follows... ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; webpage = "C:\Test\xml3\hGetVarNames.html" br = hBrowse(2, webpage, "2") ; <--- return a reference to the browser object... While hGetURL(br) ; <--- while the URL is valid, loop... TimeDelay(0.5) EndWhile hEndBrowse(br) ; <--- close the browser window... ; get the values needed... myformvarlist = hGetVarNames() shoesize = hGetVarValue("shoesize", "99") txtarea = hGetVarValue("TextBox", "Wasn't on the page") manual = hGetVarValue("manual", "99") first = hGetVarValue("first", "None") last = hGetVarValue("last", "None") age = hGetVarValue("under21", "Unknown") msgtxt = StrCat("First: ", first, @CRLF, "Last: ", last, @CRLF, "Shoe Size: ", shoesize, @CRLF, "Under 21?: ", age, @CRLF, "Manual: ", manual, @CRLF, "Text Area: ", txtarea) Message(myformvarlist, msgtxt) ; <--- show the values and the variable name list... ;display(2, "Open OLE Objects", intcontrol(77, 60, 0, 0, 0)) ;gosub ShowOLE Return Exit :ShowOLE varlist = IntControl(77, 12, 0, 0, 0) olelist = "" For vv = 1 To ItemCount(varlist, @TAB) thisvar = ItemExtract(vv, varlist, @TAB) If VarType(%thisvar%) == 17 Then olelist = ItemInsert(thisvar, -1, olelist, @TAB) Next Message("OLE", olelist) Return
<html> <head> <title>hGetVarValue Example</title> <!--This is the hGetVarNames.html file For the hGetVarNames Example--> </head> <body> <h1 align="center">hGetVarValue Example</h1> <h2 align="center">Please enter the following information:</h2> <form action="ignored" method="POST"> <div align="center"><center><table border="5" cellpadding="5" cellspacing="5"> <tr> <th align="right">First Name:</th> <td><input type="text" size="20" name="first"></td> </tr> <tr> <th align="right">Last Name:</th> <td><input type="text" size="20" name="last"></td> </tr> <tr> <th align="right">Shoe size:</th> <td><Select name="shoesize" size="1"> <option>1</option> <option>1 1/2</option> <option>2</option> <option>2 1/2</option> <option>3</option> <option>3 1/2</option> <option>4</option> <option>4 1/2</option> <option>5</option> <option>5 1/2</option> <option>6</option> <option>6 1/2</option> <option>7</option> <option>7 1/2</option> <option selected>8</option> <option>8 1/2</option> <option>9</option> <option>9 1/2</option> <option>10</option> <option>10 1/2</option> <option>11</option> <option>11 1/2</option> <option>12</option> <option>12 1/2</option> <option>13</option> <option>13 1/2</option> </Select></td> </tr> <tr> <th align="right">Age CHECK:</th> <td><input type="checkbox" name="under21" value="1">Under 21?</td> </tr> <tr> <th align="right">Manual CHECK:</th> <td><input type="radio" checked name="manual" value="1">Read manual<br> <input type="radio" name="manual" value="2">Scanned manual<br> <input type="radio" name="manual" value="3">Remember seeing manual<br> <input type="radio" name="manual" value="4">Lost manual</td> </tr> <tr> <th align="right">Manual CHECK:</th> <td><textarea name="TextBox" cols=55, ROWS=6 style="overlow:auto;" wrap="physical"></textarea></td> </tr> </table> </center></div><p align="center"> <input type="submit" name="ignored" value="Submit"> <input type="reset" name="Clear" value="Clear"> </p> </form> </body> </html>
Article ID: W17247
File Created: 2007:07:03:14:28:58
Last Updated: 2007:07:03:14:28:58