Jump to content
xiantez

Variable must be of type "Object" in For Loop

Recommended Posts

xiantez
Posted (edited)

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
JLogan3o13

You need to make sure that $ipaddress has the information that you expect it to. If you output to the console right before you for loop, is $ipaddress what you would expect it to be?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
xiantez

It appears to return an array

msgbox.png

Share this post


Link to post
Share on other sites
jchd

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
xiantez
Posted (edited)

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
jchd

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
xiantez

Ran the code above...

image.png.9376914133812c05a4b50e1179054102.png

Share this post


Link to post
Share on other sites
JLogan3o13
14 hours ago, xiantez said:

It appears to return an array

msgbox.png

And what does an _ArrayDisplay on $ipaddress look like?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
LisHawj

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
JLogan3o13

Wow, it is almost like someone suggested that very course of action above! :lmao:


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
xiantez

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
JLogan3o13

You'll have to work your way backward up the logic chain. Is $getIPAddress returning what you would expect?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
xiantez

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
jchd

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
xiantez

Welp... This worked flawlessly and only 4 lines of code lol... I guess ill just stick with it

 

#include <Inet.au3>
#include <MsgBoxConstants.au3>

Local $sPublicIP = _GetIP()
MsgBox($MB_SYSTEMMODAL, "", "Your external IP address is: " & $sPublicIP)

 

Share this post


Link to post
Share on other sites
mLipok

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 begining - comunication 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 *

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: 2018-10-31

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

    • vati1011
      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
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • genius257
      By genius257
      I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
      Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
      If I've forgotten to add credit, please let me know
      Example:
      #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples
      Version: 2.0.0
      AutoItObject_Internal.au3
      Documentation
      Edit2 (19th March 2017):
      First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
      So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    • Xandy
      By Xandy
      I'm listing the error message strings, and roughly matching the error code
      Is this how to do error reporting?  Is there a more simple way I don't know about?
      I realise I might not need to trap @error inside $error.  I like it this way b/c I have no fear of overwriting @error now; I don't even use it.
      Func Send_Connect($address, $port)     $socket = TCPConnect($address, $port)     $error = @error     If $error <> 0 Then         Local $aError[4] = ["-2 not connected.", _                             "1 IPAddr is incorrect.", _                             "2 port is incorrect."]         $aError[3] = "10060 Connection timed out."         If $error < 0 Then $error = 0         If $error > 2 Then $error = 3         MsgBox(0, "TCP Connect Error", $aError[$error], 0)         $socket = 0     EndIf     Return $socket EndFunc
×