Sign in to follow this  
Followers 0
kimurtus

Need help with loop

13 posts in this topic

$KK = 1
$ii = 0
$XLoop = 1

$val1= "30"
$val2= "70"
$val3= "2"
$val4= "3"
$val5= "not"
$AN="x"

While $XLoop = 1
$reath= "/"&$AN&"-"&$val1
if $reath= "/"&$AN&"-"&"not_found" Then 
    $XLoop = 0
    else
EndIf
if $KK=0 then
    $XLoop = 0
Else
EndIf
;here goes another code that ends the loop with $kk=0 if neded and uses $reath
Wend

$reath= "/"&$AN&"-"&$val1

How can i make this line or script read the first time $val1, then the next time to read $val2, next $val3 and so on?

and when reaches the $val x with "not" to end loop? Sometimes there wil be more than $val5, so i want to stop on "not" text

Share this post


Link to post
Share on other sites



Hi,

You can use Eval to evaluate a string as a variable..

$val1= "30"
$val2= "70"
$val3= "2"
$val4= "3"
$val5= "not"

For $i = 1 To 5
    If Eval("val" & $i) <> "" Then MsgBox(0,"$val" & $i, "$val" & $i & " = " & Eval("val" & $i))
Next

Share this post


Link to post
Share on other sites

Declare an array with 5 elements and use a For To Next loop.

Share this post


Link to post
Share on other sites

You can use Eval to evaluate a string as a variable...

Bad smashly! Assign/Eval are evil!

Declare an array with 5 elements and use a For To Next loop.

Good three-eyed fishy! Fresh worm for you!

Dim $avArray[5] = ["30" , "70", "2", "3", "not_found"]
$AN = "x" 

For $n = 0 To 4
    $reath = "/" & $AN & "-" & $avArray[$n]
Next

@kimurtus: You'll have to put your other logic back into the loop. I couldn't make any sense of it. Nothing changes the value of $KK or $AN, so the conditions never change, and $ii is never used.

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Bad smashly! Assign/Eval are evil!

Agreed they are evil, but it is an alternative to re - declaring all your already written variables into an array.

Cheers

Share this post


Link to post
Share on other sites

Good three-eyed fishy! Fresh worm for you!

Dim $avArray[5] = ["30" , "70", "2", "3", "not_found"]
$AN = "x" 

For $n = 0 To 4
    $reath = "/" & $AN & "-" & $avArray[$n]
Next
Thanks penguin who loves arrays! <_<

Share this post


Link to post
Share on other sites

Agreed they are evil, but it is an alternative to re - declaring all your already written variables into an array.

Cheers

True enough. But try 'n tell me THAT script doesn't NEED a re-write anyway! :P

Thanks penguin who loves arrays! <_<

You're welcome. Penguins like fish after they've been fattened up a bit, don't 'ya know... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I posted couse i was trying to make this, but it was an idea only, after reading more the help file,

it seems possible now, I started to use autoit a week ago :S, and I never coded before in any other language

#include <Array.au3>

$ip = "10.250.207.80"
$shares= "admin$, my docs, C$, shares, carl(D), disc_f"

$remshare = StringSplit($shares, "," )

;;;;;;;;;;;;;;;;;;;;;;;;temp use
_ArrayDisplay($remshare, "Class List of Active Window")
msgbox (0,"",$remshare)
msgbox (0,"",$remshare[1])
msgbox (0,"",$remshare[2])
msgbox (0,"",$remshare[3])
msgbox (0,"",$remshare[4])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

while 1
 $K=1   
if $K=1 then
    ;;;;;;;;;;;;;help here;;;;;;;;;;;;;;;;;;;
    if $remshare[1] = "" or "$" then  
    Else
    ;;;;;;;;;;;;;and here;;;;;;;;;;;;;;;;;;;
    $remotePath= "//"&$ip&"/"&$remshare&"/"
        if FileExists ($remotePath&"updates") Then
            call ("copy_file")
            $K=0
        Else
        EndIf
    EndIf
Else
EndIf

if $K=0 then
ExitLoop
else
EndIf

WEnd

script looks for the " updates " folder and then copy 2 files into it

updates can be in any shared folder, there are up to 4 machines with wich i whant to use it

how to make $remshare[1] go to [2] [3] [4] in every loop and exit loop if [5] o [6] or more [10] does not exist

also how to ignore shares with $ like admin$ and C$ skip them in the loop proces

srry my bad english

and thx for the help

Share this post


Link to post
Share on other sites

Maybe...

*** not tested

#include <Array.au3>

$ip = "10.250.207.80" 
$remshare = StringSplit("admin$,my docs,C$,shares,carl(D),disc_f", ",")

#cs
    _ArrayDisplay($remshare, "Class List of Active Window")
    MsgBox(0, "", $remshare)
    MsgBox(0, "", $remshare[1])
    MsgBox(0, "", $remshare[2])
    MsgBox(0, "", $remshare[3])
    MsgBox(0, "", $remshare[4])
#ce

For $x = 1 To $remshare[0]

    If $remshare[$x] = "" Or $remshare[$x] = "$"  Then
        ; nada or do something else
    Else
        $remotePath = "//" & $ip & "/" & $remshare[$x] & "/" 
        If FileExists($remotePath & "updates") Then copy_file ()
    EndIf
    
Next

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You could do this if there is no "other" use for the If/Endif

<> means "different than"

For $x = 1 To $remshare[0]

    If $remshare[$x] <> "" And $remshare[$x] <> ""  Then
        $remotePath = "//" & $ip & "/" & $remshare[$x] & "/" 
        If FileExists($remotePath & "updates") Then copy_file ()
    EndIf
    
NextoÝ÷ Ø    趫jk¡§!jëh×6For $x = 1 To $remshare[0]

    If $remshare[$x] = "" Or $remshare[$x] = "$"  Then ContinueLoop
    $remotePath = "//" & $ip & "/" & $remshare[$x] & "/" 
    If FileExists($remotePath & "updates") Then copy_file ()
    
Next

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

thanks alot! Valuater

i got it working now this is the correct one that works, it ignores StringInStr($remshare[$x], "$") <_<

For $x = 1 To $remshare[0]
        If Not $remshare[$x] = '' And Not StringInStr($remshare[$x], "$") Then
            MsgBox(0, "", $remshare[$x])
            $remotePath = "//" & $ip & "/" & $remshare[$x] & "/"
            If FileExists($remotePath & "updates") Then copy_file ()
            MsgBox(0, "", "updates")
        EndIf
Next

i had luck with ifnot ^^

tnx ppl

Edited by kimurtus

Share this post


Link to post
Share on other sites

I posted couse i was trying to make this, but it was an idea only, after reading more the help file,

it seems possible now, I started to use autoit a week ago :S, and I never coded before in any other language

script looks for the " updates " folder and then copy 2 files into it

updates can be in any shared folder, there are up to 4 machines with wich i whant to use it

how to make $remshare[1] go to [2] [3] [4] in every loop and exit loop if [5] o [6] or more [10] does not exist

also how to ignore shares with $ like admin$ and C$ skip them in the loop proces

srry my bad english

and thx for the help

This should help. It creates an array of server IPs to check, and the $remshare array you already had of share names.

The script loops through each server IP, and for each one loops through the list of shares.

For each IP/share it tests for the "$", and then for the existence of the "updates" folder.

All it does it show status on the console for now. You'll have to put the copy back in there after you study how the looping through the arrays works, and the "If" structure.

One lesson you need first off is that "Else" doesn't have to be used at all if you don't need it. In addition, "EndIf" doesn't have to be used if your conditional function after the "Then" is only one line and can be put on the same line with "If".

Read the help file on If/Then/Else/ElseIf/EndIf, and For/Next. Work through the examples given in the help file. If you get lost create a short script that reproduces the part you have trouble with and post it. You'll get plenty of help.

#include <Array.au3>

$shares = "admin$, my docs, C$, shares, carl(D), disc_f" 
$remshare = StringSplit($shares, ",")
_ArrayDisplay($remshare, "Debug:  $remshare")

$ip = "10.250.207.80,10.250.207.91,10.250.207.102,10.250.207.113" 
$avIP = StringSplit($ip, ",")
_ArrayDisplay($avIP, "Debug:  $avIP")

For $i = 1 To $avIP[0]
    ConsoleWrite("Debug:  Working with $avIP[" & $i & "] = " & $avIP[$i] & @LF)
    
    For $n = 1 To $remshare[0]
        ConsoleWrite("Debug:  Working with $remshare[" & $n & "] = " & $remshare[$n] & @LF)
        
        ; Ignore shares with '$' in the name
        If StringInStr($remshare[$n], "$") Then ContinueLoop
        
        $remotePath = "\\" & $avIP[$i] & "\" & $remshare[$n] & "\" 
        ConsoleWrite("Debug:  Working with $remotePath = " & $remotePath & @LF)
        
        If FileExists($remotePath & "updates") Then 
            ConsoleWrite("Debug:  Share exists at: " & $remotePath & "updates" & @LF)
        Else
            ConsoleWrite("Debug:  Share does not exists at: " & $remotePath & "updates" & @LF)
        EndIf
    Next
Next

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

thanx PsaltyDS

ConsoleWrite("Debug: <<--- thnx for the idea too, I didnt know of it <_<

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