Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
It ends in hundreds of IE windows, till resources runs out
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
It ends in hundreds of IE windows, till resources runs out
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows 2000 SP4
Divers
Thread ID:
01258328
Message ID:
01258328
Vues:
45
Hi all

I have, with help from all the guru's here, a method to get the Internet IP address of my computer. This code is working so-so when there is a permanent internet connection, cause there are times when the code fails at IF TYPE() and/or IF VARTYPE() command.

This probably is the reason when on a computer where the internet (ADSL with limited bandwidth, thus disconnected from ISP) is not permanently online. At times the method or rather the automation of IE goes crazy and it starts opening lots and lots of IE windows until the resources run out for creating more windows. Then after a while the same app and code will run OK without any problems or IE windows.

Please help me solve this odd problem. The code follows. Please note the odd IF TYPE("loIE.DOCUMENT") = "O" AND TYPE("loIE.DOCUMENT.NAME") = "C" condition. I have tried to replace it with a VARTYPE() as well as try them individually but it at times returns a true and code later fails.

Thanks.
LOCAL lcRetVal, loIE, loDoc, lnTimeOut, lnTSec, lnST, lnFH, lcFL, ;
	lnX, lcIP, lnCtr


WAIT WINDOW "Detecting Internet IP address ..." NOWAIT


DECLARE Sleep IN kernel32 INTEGER millisec


loIE        = CREATEOBJECT('internetexplorer.application')
loIE.Silent = .T.			&& no dialogs

lcIP      = ""
lnTimeOut = 20
lnTSec    = SECONDS()

loIE.navigate2("www.whatismyip.com")

lnCtr = 0


*--------------------------------------------
*  wait until complete
*--------------------------------------------
lnST = SECONDS()

Sleep(50)


DO WHILE .T.
	IF NOT VERSION(5) = 700
		*** In 7.0, the DoEvents behavior changed to stop and wait for event.
		*** In 8.0, the behavior was changed back to 6.0 behavior.
		DOEVENTS
	ENDIF


	DO CASE
		CASE loIE.ReadyState = 4 AND NOT loIE.Busy
			EXIT

		CASE loIE.ReadyState = 3 AND SECONDS() - lnST > 5
			EXIT

		CASE SECONDS() - lnST > lnTimeOut
			EXIT
	ENDCASE


	lnCtr = lnCtr + 1

	WAIT WINDOW "Detecting Internet IP address (" + ALLTRIM(STR(lnCtr)) + ") ..." NOWAIT
	

	Sleep(50)
ENDDO


****
**** This IF condition is a major cause of the problem, I have tried VARTYPE() also as well as the below conditions independently, no joy
****
IF TYPE("loIE.DOCUMENT") = "O" AND TYPE("loIE.DOCUMENT.NAME") = "C"
	*** 21/02/2007 put in a TRY-CATCH for when object is created
	***            but innertext is invalid
	TRY
		loDoc = loIE.DOCUMENT

		*** now you have your doc. object in loDoc
		MyString = loDoc.Body.InnerText &&& now you have a string with the contents
		MyHTML   = loDoc.Body.InnerHTML &&& same, but in HTML

		STRTOFILE(MyString, "InnerText.txt")
		STRTOFILE(MyHTML  , "InnerHTML.htm")


		lnFH = FOPEN("InnerText.txt")

		DO WHILE NOT FEOF(lnFH)
			lcFL = UPPER(FGETS(lnFH))


			DO CASE
				CASE lcFL = UPPER("Your IP is ")
					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Your IP is "), ""))
					EXIT

				CASE lcFL = UPPER("Your IP - ")
					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Your IP - "), ""))
					EXIT

				CASE lcFL = UPPER("Bookmark Your IP - ")
					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Bookmark Your IP - "), ""))
					EXIT

				CASE lcFL = UPPER("Bookmark Your IP Is ")
					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Bookmark Your IP Is "), ""))
					EXIT
			ENDCASE
		ENDDO

		= FCLOSE(lnFH)


		DELETE FILE InnerText.txt
		DELETE FILE InnerHTML.htm


	CATCH
		lcIP = ""
	ENDTRY
ENDIF


lcRetVal = IIF(EMPTY(lcIP), "Not detected", lcIP)


WAIT WINDOW "Internet IP address: " + lcRetVal + " ..." NOWAIT


CLEAR DLLS Sleep


RETURN lcRetVal
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform