Jump to content
Sign in to follow this  

Using expressions in a For loop definition

Recommended Posts

Hello all,

I'm trying to write an error-handling function that will write to a log file all of the steps that were not completed due to something going wrong. The function accepts a string called $step and a variable called $compFlag that holds the number of steps that have already been completed. I then want to use a For loop to log the uncompleted steps. This is the first time I've used a For loop with AutoIT, and also the first time I've used an array, so I'm not quite sure where I'm going wrong here. The syntax error label shows up right between the For i = $compFlag line and the $step line. Can someone please point me to the fail point?

Func ErrChk($step, $compFlag)

Dim $theSteps[7]

$theSteps[0] = "Enable hidden admin account and set password"
$theSteps[1] = "Disable Windows update service"
$theSteps[2] = "Enable Remote Registry service"
$theSteps[3] = "Enable Remote Desktop connections"
$theSteps[4] = "Configure power settings"
$theSteps[5] = "Check Device Manager for problems"
$theSteps[6] = "Display IP address"

 _FileWriteLog($thelog, "Failed to " & $step & " Script will terminate.")
 _FileWriteLog($thelog, "Steps not completed:" & @CRLF & _
     For i = $compFlag to 6 Step +1
      If i < 6 then
       $theSteps[i] & @CRLF &
       $theSteps[i] & @CRLF



Updated code to include the right variable names, sorry!

Edited by OneJeremias

Share this post

Link to post
Share on other sites

Nevermind, I cut the code all the way down to the For loop by itself, and discovered I had missed the "$" in front of the "i".  Wow. Nothing like wasting my own darn time.

As an FYI, I am aware of a few other problems with the above code, working them out now, and may post later.

Share this post

Link to post
Share on other sites

For one, you cannot have a For loop as a parameter in the _FileWriteLog command. You have to do your For first, and then write the result.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...