Sign in to follow this  
Followers 0
Complhex

Nested Next Inside If

5 posts in this topic

#1 ·  Posted (edited)

Hello all,

I have a For Statement that is reading lines from a file. I have been trying to figure out how to continue to the next line within the file (when a condition is met...or lack thereof), otherwise do other things and then go to the next line. Essentially I'm creating a timeout for a window wait and if the window never shows, I want to continue to the next document in the file. Is it possible to nest a Next inside an If statement or is there some other trick?

I currently get the whole ""Next" statement with no matching "For" statement." error...but there is a For statement...it just doesn't seem to be able to see it from within the If.

If you are wondering what I'm trying to do, it's strip passwords from office files (where the password is known). :thumbsup:

;Read XREF to an Array
Dim $AttLoc
If Not _FileReadToArray($XREF,$AttLoc) Then
MsgBox(4096,"Error", " Error reading XREF to an Array ErrorID: " & @error)
Return
EndIf

;Create Progress Bar For Report Creation
ProgressOn("Working...", "Saving Documents Without Passwords", "Currently Processing item 1 of " & $AttLoc[0],5,5,17)

;Start Of Loop
For $x = 1 to $AttLoc[0]
$File = ""
$line = ""
$inLine = ""
$inPath = ""
$inPass = ""
$inSplit = ""

If $AttLoc[$x] <> "" Then
$inLine = StringSplit($AttLoc[$x],' ')
$inPath = $inLine[1]
$inPass = $inLine[2]
$inSplit = _PathSplit($inPath, $szDrive, $szDir, $szFName, $szExt)
$inSplit = $inSplit[3]&$inSplit[4]
EndIf

ProgressSet(100 * $x / $AttLoc[0], "Currently Processing item " & $x & " of " & $AttLoc[0]&@LF&@LF&$inSplit)

;Write To Report
If FileExists($inPath) =0 Then
If $inPath = "" Then
;Do Nothing
Else
FileWrite($LOG, "File Does Not Exist - "&$inPath&@CRLF)
EndIf
ElseIf FileExists($inPath) Then
FileWrite($LOG,"File Processed: "&$inPath&@CRLF)
EndIf

If FileExists($inPath) Then

;Check Selection Type
If $xlsSet = $GUI_CHECKED Then
ShellExecute($inPath)
While WinExists("Microsoft Excel","") = 0
Wend
If WinWait("Password","",15) =0 Then
MsgBox(16,"Timeout","15 seconds passed without window detection",3)
FileWrite($LOG, "Timeout - "&$inPath&@CRLF)
Next
Else
WinActivate("Password","")
ControlClick("Password","",20)
AutoItSetOption("SendKeyDelay",200)
Sleep(200)
Send($inPass&"{ENTER}")
;Ect...Ect...
EndIf
;More Code...More Code...
EndIf
Next
Edited by Complhex

Share this post


Link to post
Share on other sites



Check this

;Read XREF to an Array
Dim $AttLoc
If Not _FileReadToArray($XREF, $AttLoc) Then
MsgBox(4096, "Error", " Error reading XREF to an Array ErrorID: " & @error)
Return
EndIf

;Create Progress Bar For Report Creation
ProgressOn("Working...", "Saving Documents Without Passwords", "Currently Processing item 1 of " & $AttLoc[0], 5, 5, 17)

;Start Of Loop
For $x = 1 To $AttLoc[0]
$File = ""
$line = ""
$inLine = ""
$inPath = ""
$inPass = ""
$inSplit = ""

If $AttLoc[$x] <> "" Then
$inLine = StringSplit($AttLoc[$x], ' ')
$inPath = $inLine[1]
$inPass = $inLine[2]
$inSplit = _PathSplit($inPath, $szDrive, $szDir, $szFName, $szExt)
$inSplit = $inSplit[3] & $inSplit[4]
EndIf

ProgressSet(100 * $x / $AttLoc[0], "Currently Processing item " & $x & " of " & $AttLoc[0] & @LF & @LF & $inSplit)

;Write To Report
If FileExists($inPath) = 0 Then
If $inPath = "" Then
;Do Nothing
Else
FileWrite($LOG, "File Does Not Exist - " & $inPath & @CRLF)
EndIf
ElseIf FileExists($inPath) Then
FileWrite($LOG, "File Processed: " & $inPath & @CRLF)
EndIf

If FileExists($inPath) Then

;Check Selection Type
If $xlsSet = $GUI_CHECKED Then
ShellExecute($inPath)
While WinExists("Microsoft Excel", "") = 0
WEnd
If WinWait("Password", "", 15) = 0 Then
MsgBox(16, "Timeout", "15 seconds passed without window detection", 3)
FileWrite($LOG, "Timeout - " & $inPath & @CRLF)
EndIf
Else
WinActivate("Password", "")
ControlClick("Password", "", 20)
AutoItSetOption("SendKeyDelay", 200)
Sleep(200)
Send($inPass & "{ENTER}")
;Ect...Ect...
EndIf
;More Code...More Code...
EndIf
Next
You forgot EndIf in Line 51


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't think it's a forgotten EndIf because the code works fine if I don't call next within the If. Let me try giving more of the code for this one portion:

;Read XREF to an Array
Dim $AttLoc
If Not _FileReadToArray($XREF,$AttLoc) Then
MsgBox(4096,"Error", " Error reading XREF to an Array ErrorID: " & @error)
Return
EndIf

;Create Progress Bar For Report Creation
ProgressOn("Working...", "Saving Documents Without Passwords", "Currently Processing item 1 of " & $AttLoc[0],5,5,17)

;Start Of Loop
For $x = 1 to $AttLoc[0]
$File = ""
$line = ""
$inLine = ""
$inPath = ""
$inPass = ""
$inSplit = ""

If $AttLoc[$x] <> "" Then
$inLine = StringSplit($AttLoc[$x],' ')
$inPath = $inLine[1]
$inPass = $inLine[2]
$inSplit = _PathSplit($inPath, $szDrive, $szDir, $szFName, $szExt)
$inSplit = $inSplit[3]&$inSplit[4]
EndIf

ProgressSet(100 * $x / $AttLoc[0], "Currently Processing item " & $x & " of " & $AttLoc[0]&@LF&@LF&$inSplit)

;Write To Report
If FileExists($inPath) =0 Then
If $inPath = "" Then
;Do Nothing
Else
FileWrite($LOG, "File Does Not Exist - "&$inPath&@CRLF)
EndIf
ElseIf FileExists($inPath) Then
FileWrite($LOG,"File Processed: "&$inPath&@CRLF)
EndIf

If FileExists($inPath) Then

;Check Selection Type
If $xlsSet = $GUI_CHECKED Then
ShellExecute($inPath)

While WinExists("Microsoft Excel","") = 0
Wend

If WinWait("Password","",15) =0 Then
;Write Log
Next
Else
WinActivate("Password","")
ControlClick("Password","",20)
AutoItSetOption("SendKeyDelay",200)
Sleep(200)
Send($inPass&"{ENTER}")
AutoItSetOption("SendKeyDelay",500)
EndIf

If WinWait("Microsoft Excel","",15) =0 Then
;Write Log
Next
Else
WinActivate("Microsoft Excel","")
Sleep(1000)
Send("{ALT}+{F}{I}{P}{E}")
AutoItSetOption("SendKeyDelay",100)
Send("{END}{LSHIFT}+{HOME}{DEL}{ENTER}")
AutoItSetOption("SendKeyDelay",500)
WinClose("Microsoft Excel","")
EndIf

AutoItSetOption("WinTitleMatchMode",1)

If WinWait("Microsoft Excel","",15) =0 Then
;Write Log
Next
Else
WinActivate("Microsoft Excel","")
Sleep(500)
Send("{S}")
EndIf

AutoItSetOption("WinTitleMatchMode",2)

If WinWait("Save As","",4) =0 Then
;Do Nothing
Else
WinActivate("Save As","")
Send("{ENTER}")
Sleep(500)
Send("{Y}")
EndIf

While WinExists("Microsoft Excel","")
WEnd

EndIf

Next
Edited by Complhex

Share this post


Link to post
Share on other sites

Replace the "Next" with "ContinueLoop"

There can only be one for...next pair.

Share this post


Link to post
Share on other sites

Replace the "Next" with "ContinueLoop"

There can only be one for...next pair.

That was it! Thanks for this. Helped me finish the project I was working on. B)

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