Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class def. WinHTTP.WinHTTPRequest.5 is not found on XP
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01323708
Message ID:
01324095
Views:
29
I tried the following code but then no IP is returned. Please advise.
LOCAL lcMsg, lcRetVal, loIE, loDoc, lnTimeOut, lnTSec, lnST, lnFH, lcFL, ;
	lnX, lcIP, lnCtr


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


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

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

loIE.navigate2("http://whatismyip.com/automation/n09230945.asp")

lnCtr = 0


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

_Sleep(20)


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
	lcMsg = "Detecting Internet IP address (" + ALLTRIM(STR(lnCtr)) + ") ..."

	WAIT WINDOW lcMsg NOWAIT


	_Sleep(50)
ENDDO


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)
*** the text returned should be the IP
			lcFL = UPPER(FGETS(lnFH))
			MESSAGEBOX(lcFL)

			*!*				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)


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


RETURN lcRetVal
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform