How to avoid Bad DDE channel request in While loop?

Started by Jeremy Whilde, June 23, 2015, 08:14:14 AM

Previous topic - Next topic

Jeremy Whilde

I am using  the following code inside a While 1 loop as a way to wait for a particular URL to appear in a browser window, this works well except occasionally on some machines when the browser is closed we get a 3152: DDEReq: Bad channel number.

Thought the BrowserOpen = FindWindow('IEFrame') and If BrowserOpen <> "" would help but still get the occasional Bad channel error,  guess occasionally the browser is closed when this line of code has run so the DDE fails because the channel does not exist?!

Does anyone have any suggestions how can we avoid this?

Thanks JW

   ;---------------------------------------------------------------------------
   ; Check If a browser is running (wait for the browser),  IE at the moment
   ;---------------------------------------------------------------------------
   Browser = ""   ; Initialise variable just in case
   Browser = FindWindow('IEFrame')

   While Browser == ""
      Browser = FindWindow('IEFrame')
      TimeDelay(.5)
   EndWhile


   ;-------------------------------------
   ; Define browser type & check URL
   ;-------------------------------------
   
   BrowserOpen = FindWindow('IEFrame')
   If BrowserOpen <> ""
      BrowserType = ""   ; Initialise variable just in case
      BrowserType = "Iexplore"
      channel=DDEInitiate(BrowserType, "WWW_GetWindowInfo")  ;Initialize DDE
      Info = ""   ; Initialise variable just in case
      info = DDERequest( channel, "0xFFFFFFFF" )  ;<<<----Error here only some times????
      DDETerminate(channel)
        Endif

;Rest of the While loop


td

The  DDEInitiate topic example in the WIL Consolidated Help file shows one method.
Code (winbatch) Select
url = ''
If AppExist('iexplore')
   browser = 'iexplore'
   channel = DDEInitiate(browser, 'WWW_GetWindowInfo') ;Initialize DDE
   If channel != 0 ;If DDE OK Execute DDE Command
      url = DDERequest( channel,-1)
      DDETerminate(channel)
   EndIf
Else
   Pause('','No active IE browser')
   Exit
EndIf
Message('Active URL in ':browser, url)


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade