Jump to content
Sign in to follow this  
icu

InetGet [background] parameter error?

Recommended Posts

icu

Dear AutoIt Community,

I'm having trouble understanding the difference between the following code snippets:

#include <Array.au3>

$sURL = "http://www.autoitscript.com"
; Attempt to download the URL passed by $sURL
$hInetGet = InetGet($sURL, @ScriptDir & "\InetGet.txt", 1, 0)
; Check the information from InetGet()
$aInetGetInfo = InetGetInfo($hInetGet)
; Fire off _ArrayDisplay to see what's there
_ArrayDisplay($aInetGetInfo)
; Close the handle to release resources
InetClose($hInetGet)
Exit

And this:

#include <Array.au3>

$sURL = "http://www.autoitscript.com"
; Attempt to download the URL passed by $sURL
$hInetGet = InetGet($sURL, @ScriptDir & "\InetGet.txt", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hInetGet, 2) ; Check if the download is complete.
$aInetGetInfo = InetGetInfo($hInetGet)
; Fire off _ArrayDisplay to see what's there
_ArrayDisplay($aInetGetInfo)
; Close the handle to release resources
InetClose($hInetGet)
Exit

According to the AutoIt Help file the background parameter for InetGet does the following:

 

[optional] 0 = (default) Wait until the download is complete before continuing.
1 = return immediately and download in the background (see remarks).

 

To me this would mean that when the background parameter is set to "0" (or not set at all and thus default) control flow would stop and wait until the download is completed before continuing.

To me this would mean that _ArrayDisplay in the first code snippet would fire off.  However it does not, and it seems that this line does not work:

$aInetGetInfo = InetGetInfo($hInetGet)

If I try to refer to an element like $aInetGetInfo[1] from the first code snippet I get the following error in Scite: "Subscript used with non-Array variable."

This makes no sense to me.  If the function waited until the download is complete before continuing (as per the help file) then this wouldn't be a problem.

Why then does the second code snippet work.  In that example using "1" as the background parameter to download the file in the background and return control flow immediately only to then use "Do... Until" to force the script to wait until the file downloaded.

The second script actually fires off _ArrayDisplay and will allow for reference to an array element in $aInetGetInfo.

Any and all help is greatly appreciated.

Many thanks,

icu

Edited by icu

Share this post


Link to post
Share on other sites
DW1

The reasoning here, I imagine, is that the information gained from InetGetInfo is pointless if the download was told to wait, and not run in the background.  I can only imagine needing the information in InetGetInfo InetGet was running in the background.  For example if I was waiting for the "bytes read so far" (Array[0]) to equal "the size of the download" (Array[1]), or if I wanted to wait for Array(2) to tell me the download is complete, and to check Array(3) to see if the download was successful.

That information can really only be useful if you have a background InetGet running.  Otherwise, if you were not running InetGet in the background, you would just check @error to know if the download was successful or not, and you already know it has completed as it's a blocking function, and you can get the size from FileGetSize for the downloaded file, or InetGetSize for the remote file.

I hope that clears it up.

Edited by danwilli

Share this post


Link to post
Share on other sites
BrewManNH

InetGetInfo doesn't return an array unless you use -1 as the second parameter. If you don't use -1 you have to use one of the index numbers to get the information needed. The help file example for this function in the current release (not beta) is written wrong.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
DW1

InetGetInfo doesn't return an array unless you use -1 as the second parameter. If you don't use -1 you have to use one of the index numbers to get the information needed. The help file example for this function in the current release (not beta) is written wrong.

Right, but it defaults to -1 if not provided it seems.  He calls InetGetInfo in both snippets with only a single parameter.  The one where InetGet() was called with background = 0 (wait) does not show InetGetInfo return an array, but the one called with background = 1 does show InetGetInfo return an array.  I assume this is for the reasons in my post above, no?

Share this post


Link to post
Share on other sites
BrewManNH

It appears that it does return an array with no parameter for index. That wasn't mentioned in the 3.3.8.1 help file but appears to be there in the beta help file. Mea Culpa


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
icu

Thank you danwilli and BrewManNH for your replies.

This was driving me mad for hours trying to figure out where the bug was in my code and when I narrowed it down it made no sense when I read the documentation.

I take it that the help document be updated/revised when the beta becomes incorporated into a release?

Kind regards,

icu

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
Sign in to follow this  

×