Jump to content

assign each link unique name


Recommended Posts

i have managed to extract source link of images from a frame of a web page with this.

$oMainFrame = _IEFrameGetObjByName($oIE, "topframe") ;source frame for getting picture links
    $oImgs = _IEImgGetCollection($oMainFrame)

whats the best method of giving each of those links a unique variable name like:

$image1

$image2

$image3

$image4

etc

Link to comment
Share on other sites

How about using subscripted variables (an array) and have $image[1], $image[2], etc?

#include <IE.au3>
#include <Array.au3> ; for testing

$oIE = _IECreate ("[url="http://www.autoitscript.com/"]http://www.autoitscript.com/[/url]")
$oImgs = _IEImgGetCollection ($oIE)
Local $aImgs[@extended + 1] = [@extended], $iImg
For $oImg In $oImgs
    $iImg += 1
;   $aImgs[$iImg] = $oImg.src ; full path
    $aImgs[$iImg] = $oImg.nameprop ; filename only
Next

_ArrayDisplay($aImgs) ; for testing
Edited by Spiff59
Link to comment
Share on other sites

How about using subscripted variables (an array) and have $image[1], $image[2], etc?

#include <IE.au3>
#include <Array.au3> ; for testing

$oIE = _IECreate ("[url="http://www.autoitscript.com/"]http://www.autoitscript.com/[/url]")
$oImgs = _IEImgGetCollection ($oIE)
Local $aImgs[@extended + 1] = [@extended], $iImg
For $oImg In $oImgs
    $iImg += 1
;   $aImgs[$iImg] = $oImg.src ; full path
    $aImgs[$iImg] = $oImg.nameprop ; filename only
Next

_ArrayDisplay($aImgs) ; for testing

works like a charm

thank you very much

Link to comment
Share on other sites

found a problem with this

first time script comes to:

$aImgs[$iImg] = $oImg.src

everything goes good

but since it is in while 1 loop, second time script comes to that i get this:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aImgs[$iImg] = $oImg.src

^ ERROR

->11:54:27 AutoIT3.exe ended.rc:1

help?

Edited by dickjones007
Link to comment
Share on other sites

trace log

$oImgs = _IEImgGetCollection($TopFrame)

>Error code: 0

@@ Trace(297) : Local $aImgs[@extended + 1] = [@extended], $iImg

>Error code: 0

@@ Trace(299) : For $oImg In $oImgs

>Error code: 0

@@ Trace(301) : $iImg += 1

>Error code: 0

@@ Trace(303) : $aImgs[$iImg] = $oImg.src

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aImgs[$iImg] = $oImg.src

^ ERROR

->13:14:28 AutoIT3.exe ended.rc:1

Link to comment
Share on other sites

dickjones007,

Given that the code ran through the stmt 303 at least once we can surmise that the problem is array size exceeded. See redim in the help file ofr adding elements to an array.

Hint, redim will slow you down, one common practice is to double the array size at each redim, e.g.

redim $array[ubound($array) * 2]

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

dickjones007,

I would just be careful using the AutoIt site to test your code as it could land you in hot water, especially if you're checking for changes every 2ms. Though this is my interpretation of what you're doing as you've only mentioned about a while loop but not shown it.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

dickjones007,

You are defining $aimgs to the number of returned images + 1 (assuming the the ieimggetcollection ran successfully...you probably want to check for errors here). Therefore the array boundary (ubound) will be exceed when the loop runs more than once. You may want to re-think how you are dimensioning this array and/or what you do with the images after every loop.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

dickjones007,

Given that the code ran through the stmt 303 at least once we can surmise that the problem is array size exceeded. See redim in the help file ofr adding elements to an array.

Hint, redim will slow you down, one common practice is to double the array size at each redim, e.g.

redim $array[ubound($array) * 2]

kylomas

kylomas,

would this doubling of array have any significant impact on computer mem usage if the loop ran, lets say, a 1000 times?

Edited by dickjones007
Link to comment
Share on other sites

dickjones007,

Not really...assume 4 images are returned then...

1st loop = 4

2nd loop = 8

3rd loop = 16

4th loop = 32

5th loop = 64

as you can see the # of redims lessens as the images increase. I am assuming that you are not memory constrained???

kylomas

Edit: P.S. Showing some of YOUR code would be a lot more helpfull!!!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...