Jump to content
xiantez

Variable must be of type "Object" in For Loop

Recommended Posts

This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.

Func PublicIP() ;Post public facing IP address
    Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8'
    Local $getIPaddress = BinaryToString(InetRead($url))
    Local $sStart = 'clamp:2">'
    Local $sEnd = '</div>'
    Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd
    
    For $i In $ipaddress
        MsgBox(0, 'External IP', "Your public IP address is " & $i)
    Next
EndFunc   ;==>PublicIP

The console output shows:

"C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".:
For $i In $ipaddress
For $i In $ipaddress^ ERROR
->14:12:16 AutoIt3.exe ended.rc:1
+>14:12:16 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 9.811

:think:

Edited by xiantez
privacy

Share this post


Link to post
Share on other sites

Post the actual code you use. The one posted above can't be real as it won't run until there.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

The rest of the code is irrelevant. I have isolated that piece of code into a standalone script and the problem still occurs

 

;==============================================================================================================================
;INCLUDE ALL LIBRARIES
;==============================================================================================================================
#include <IE.au3>
#include <Inet.au3>
#include <String.au3>
#include <Array.au3>


Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8'
Local $getIPaddress = BinaryToString(InetRead($url))
Local $sStart = 'clamp:2">'
Local $sEnd = '</div>'
Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd)
MsgBox("", "", $ipaddress)

For $i In $ipaddress
Next
MsgBox(0, 'External IP', "Your public IP address is " & $i)

 

Edited by xiantez

Share this post


Link to post
Share on other sites

At least now the missing closing parenthesis at end of "Local $ipaddress = ..." is fixed!

But as you noted, there is still a slight error:

Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8'
Local $getIPaddress = BinaryToString(InetRead($url))
Local $sStart = 'clamp:2">'
Local $sEnd = '</div>'
Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd)
MsgBox("", "",  "Error = " & @error & @LF & "Result type = " & VarGetType($ipaddress))
If IsArray($ipaddress) Then
    For $i In $ipaddress
    Next
    MsgBox(0, 'External IP', "Your public IP address is " & $i)
EndIf

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Your script is not working because your $getIPaddress variable does not contain the value you are searching for in your _StringBetween line.  See my example below where I search for $sStart and it errors out.  Examine the value of $getIPaddress carefully and it should tell you what is wrong or what to change to make it work.

 

;==============================================================================================================================
;INCLUDE ALL LIBRARIES
;==============================================================================================================================
#include <IE.au3>
#include <Inet.au3>
#include <String.au3>
#include <Array.au3>


Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8'
Local $getIPaddress = BinaryToString(InetRead($url))
Local $sStart = 'clamp:2">'
Local $sEnd = '</div>'
Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd)

If StringInStr($getIPaddress, $sStart) = 0 Then MsgBox(0,"", "String is not found.")

MsgBox("", "", $ipaddress)

For $i In $ipaddress
Next
MsgBox(0, 'External IP', "Your public IP address is " & $i)

 

Share this post


Link to post
Share on other sites

Yeah you both are correct, now I am just trying to figure out "why" $getIPaddress does not have the string value i expect it to have =P

 

Thanks for all your help guys, appreciate it

Share this post


Link to post
Share on other sites

No, sure isn't. It's not returning anything when I pipe it to a msgbox, just blank... Looking into this code to make sure it still behaves the same way I think it should behave...

 

$url = 'https://www.whatismyip.com/'
 $getIPaddress = BinaryToString(InetRead($url))

 

Share this post


Link to post
Share on other sites

Just test for error(s):

$url = 'https://www.whatismyip.com/'
$result = InetRead($url)
ConsoleWrite(@error & @LF)

From this point on, no bet holds.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

When it comes to get Public IP try this:

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By mlazovjp
      I am going through the AutoIt Wiki and soaking up a lot of great information.  On the “Best Coding Practices” page at https://www.autoitscript.com/wiki/Best_coding_practices#Scopes_of_Variables there seems to be a minor detail missing.  In the “Variable Initialization” section at https://www.autoitscript.com/wiki/Best_coding_practices#Variable_Initialization , there are references to a data type $o, but in the table listing prefixes and their data types, there does not appear to be a prefix “o”.  I assume that this is for Object?
    • By BetaLeaf
      What is Rollbar?
      Rollbar provides real-time error alerting & debugging tools for developers. Learn more about it at https://rollbar.com/product/
      Demo: https://rollbar.com/demo/demo/
      Screenshot:
      Instructions: (RollbarTest.au3)
      ; Include RollbarSDK #include "RollbarSDK.au3" ;Turns on ConsoleWrite debugging override. ;Global $Rollbar_Debug=False ; Initialize RollbarSDK with the project's API key. ; Parameters ....: $__Rollbar_sToken - [Required] Go to https://rollbar.com/<User>/<ProjectName>/settings/access_tokens/ for your project. Use the token for post_server_item. _Rollbar_Init("eaa8464a4082eeabd9454465b8f0c0af") ; Write code that causes an error you want to catch, then call ; _Rollbar_Send ; Parameters ....: $__Rollbar_sErrorLevel - [Required] Must be one of the following values: Debug, Info, Warning, Error, Critical. ; $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_Send("Debug", "This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_Send("Warning", "This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_Send("Error", "This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_Send("Critical", "This is an critical message. If you received this, you were successful!", "Critical Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!") ;No Message ; Rollbar_Send's helper functions ; Parameters ....: $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_SendDebug("This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_SendInfo("This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_SendWarning("This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_SendError("This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_SendCritical("This is an critical message. If you received this, you were successful!", "Critical Message") ; Usable Example Local $sImportantFile = "C:\NOTAREALFILE_1234554321.txt" Switch FileExists($sImportantFile) Case True MsgBox(0, "Example Script", "An important file was found. Continuing...") Case Else _Rollbar_SendCritical('An important file was missing. Halting... File: "' & $sImportantFile & '"', 'Important file "' & $sImportantFile & '" is missing.') EndSwitch Notes: Please comment your feedback, advice, & suggestions below. While this is only a proof of concept, I will expand its feature set for everyone to use. 
      Right now, it is fully functional but not tested in production.
       
       
      Changelog:
      RollbarSDK.au3
      RollbarTest.au3
      v0.2
       
      v0.1.1
       
    • By ThePoro
      I have this code 
      It gets variable input from GUI to run a loop and write to a text file then copy it to the clipboard
      But the thing is code runs normally with $px and $py <100 or both > 100 or with $px <10 and $py>100 but It's wrong with 10<$px <100 and $py >100
      Can anyone tell me why?
      Func clone() Local $px = GUICtrlRead($input1) Local $py = GUICtrlRead($input2) Local $temp = "C:\temp.csv" FileDelete($temp) While $px <= $py Local $name = "P"&$px FileWrite($temp, " & $name & ""& @CRLF) $px+= 1 WEnd $a=FileRead($temp) ClipPut($a) MsgBox($MB_ICONINFORMATION,"","Copied to Clipboard") EndFunc  
    • By Dwalfware
      Hi Folks
      Can not get my head around this one.
      This function gets the DNS object s
      If you have two DNS entries fine. but if you have only one! Trouble
      $objItem.DNSServerSearchOrder[0] = Primary DNS
      $objItem.DNSServerSearchOrder[1] = Secondry DNS not always there. I need a way to return 0 if not there or the IP if its there.
      Or is there a way to tell how many objects there are in the "[?]"
      I'm terrible at WMI errors, thanks for help in advance.
      Func _GETcurrentNICinfo2() $oErrors = ObjEvent("AutoIt.Error", "Error_Handle") Local $DnsSecondry Local $objWMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\CIMV2" ) Local $query = $objWMIService.ExecQuery("SELECT DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 ) If @error Then Return 0 If NOT IsObj($query) Then Return 0 Else For $objItem In $query Return $objItem.DNSServerSearchOrder[1] next Endif EndFunc  
    • By vati1011
      Hey, guys.
      Currently, I'm using Opencv UDF and i'm  encountering issues with DLLOPEN(). it is failing and returning -1
      But, I cannot figure out why it is failing.
      I need help from people.
      I'm running windows 10 32bit.
      This's my code.
      #RequireAdmin $fileopen = DllOpen("opencv_core2413.dll") MsgBox(0,"Result",$fileopen) Example.au3opencv_core2413.dll
×
×
  • Create New...