Sign in to follow this  
Followers 0
foster74

Is there a away to shorten this code?

4 posts in this topic

#1 ·  Posted (edited)

It will have over 20 for loops, anyway to make it simple? I can not think of anything =(

For $i1 = 1 to $ArrayLINKS[0]
    _IENavigate($oIE, $ArrayLINKS[$i1])
    $ArrayLINKS1 = _GetLinks()
    $ArraySIZES1 = _GetSize()
    If $ArrayLINKS1[0] > 0 Then
;;;
        For $i2 = 1 to $ArrayLINKS1[0]
            _IENavigate($oIE, $ArrayLINKS1[$i2])
            $ArrayLINKS2 = _GetLinks()
            $ArraySIZES2 = _GetSize()
            If $ArrayLINKS2[0] > 0 Then
        ;;;
                For $i3 = 1 to $ArrayLINKS2[0]
                    _IENavigate($oIE, $ArrayLINKS2[$i3])
                    $ArrayLINKS3 = _GetLinks()
                    $ArraySIZES3 = _GetSize()
                    If $ArrayLINKS3[0] > 0 Then
                ;;;
                    EndIf       
                    _Collect($ArraySIZES2[$i3])
                Next
        ;;;
            EndIf       
            _Collect($ArraySIZES1[$i2])
        Next
;;;
    EndIf
    _Collect($ArraySIZES[$i1])
Next

edit: typo

Edited by foster74

Share this post


Link to post
Share on other sites



This might work:

...untested of course - posting a working script is easier to debug etc

For $i = 0 to 19;this will loop 20 times
    If $i = 0 Then $i = ""
    For $j = 1 to Execute("$ArrayLINKS" & $i & "[0]")
        _IENavigate($oIE, Execute("$ArrayLINKS" & $i & "[" & $j & "]")
        Assign("ArrayLINKS" & $i + 1,_GetLinks())
        Assign("ArraySIZES" & $i + 1,_GetSize())
        _Collect(Execute("$ArraySIZES" & $i & "[" & $j & "]"))
        If Execute("$ArrayLINKS" & $i + 1 & "[0]") = 0 Then ExitLoop 2
    Next
Next

You will get a LOT of "$var is not declared" errors using Execute() and Assign(), so make sure you have declared all your vars and arrays somewhere beforehand.


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites

There certainly is! However, you'll need to delve in to the depths of recursion and AFAIR, AutoIt isn't fantastically well suited to recursion. Google is your friend here or search the forums for recursive functions.

WBD

Share this post


Link to post
Share on other sites

Could take forever to run ... I hope _GetLinks() doesn't follow off-site links! Something like this perhaps?

Func _FollowAllLinks()
    Local $aLinks = _GetLinks(), $aSizes = _GetSize(), $i
    If $aLinks[0] > 0 Then
        For $i = 1 To $aLinks[0]
            _IENavigate($oIE, $aLinks[$i])
            _FollowAllLinks()
            _Collect($aSizes[$i])
        Next
    EndIf
EndFunc

WBD

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  
Followers 0