shragi
asked on
regex to check nested loop
i am looking for a simple solution which checks whether there are any nested loops...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
For Each p In Pages
p.IE_COLOR_DETECT.InputIma ge = p.Scan.OutputImage
For Each R In Range
R.Foil_Number_From_Scan =R.Tree.KeyEntry_0
Next R
Next p
End Sub
the above has nested For loop ...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
Else If
'If color_content value is not equal to 0 sends to COLOR_CLEANUP
Else
p.IE_COLOR_CLEANUP.InputIm age = p.IE_COLOR_DETECT.OutputIm age
End If
End Sub
the above has nested If loop ...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
For Each R In Range
R.Foil_Number_From_Scan =R.Tree.KeyEntry_0
Next R
End If
End Sub
The above has nested loop but for inside if
so, I want a code to check whether there is any nested loop... if so what is the loop name..
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
For Each p In Pages
p.IE_COLOR_DETECT.InputIma
For Each R In Range
R.Foil_Number_From_Scan =R.Tree.KeyEntry_0
Next R
Next p
End Sub
the above has nested For loop ...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
Else If
'If color_content value is not equal to 0 sends to COLOR_CLEANUP
Else
p.IE_COLOR_CLEANUP.InputIm
End If
End Sub
the above has nested If loop ...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
For Each R In Range
R.Foil_Number_From_Scan =R.Tree.KeyEntry_0
Next R
End If
End Sub
The above has nested loop but for inside if
so, I want a code to check whether there is any nested loop... if so what is the loop name..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@iHadi...
that Regex worked..but can we extend it to while and do while..
1) while
while()
wend
Wend
nested while loop
2) do
do
while
while
nested do while loop
3) while
do
while
wend
dowhile inside while
4) do
while()
wend
while
while inside dowhile
the statment
return m.Groups["type"].Value;
returns End If or for....
there is a problem with that...return...
but there will be no clarity with that...
if the return value is "end if" does it mean if inside for or if inside if
so can we return the two values may be "End if" and "for" if there is for loop inside if
that Regex worked..but can we extend it to while and do while..
1) while
while()
wend
Wend
nested while loop
2) do
do
while
while
nested do while loop
3) while
do
while
wend
dowhile inside while
4) do
while()
wend
while
while inside dowhile
the statment
return m.Groups["type"].Value;
returns End If or for....
there is a problem with that...return...
but there will be no clarity with that...
if the return value is "end if" does it mean if inside for or if inside if
so can we return the two values may be "End if" and "for" if there is for loop inside if
Replace the previous regex with the following:
(?:For Each|If|While|Do).+?(?:(?< type>For Each).+?Next\w*|(?<type>El se If)|(?<type>While).+?Wend| (?<type>Do ).+?While) .+?(?:Next \w*|End If|While|Wend)
And the previous and current code returns Else If and not End If
(?:For Each|If|While|Do).+?(?:(?<
And the previous and current code returns Else If and not End If
ASKER
hmm ..awesome.....
final one...
i would like to check....one more condition...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
Else If
'If color_content value is not equal to 0 sends to COLOR_CLEANUP
Else
p.IE_COLOR_CLEANUP.InputIm age = p.IE_COLOR_DETECT.OutputIm age
End Sub
the above code missing "end if"
so how do you write regular expression for checking "end if" and "Wend"
final one...
i would like to check....one more condition...
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
If p.ColorContent0 = 0 Then
p.InputImage = p.OutputImage
Else If
'If color_content value is not equal to 0 sends to COLOR_CLEANUP
Else
p.IE_COLOR_CLEANUP.InputIm
End Sub
the above code missing "end if"
so how do you write regular expression for checking "end if" and "Wend"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Scan_Finish(ByVal pRoot As IASLib.IAS_RECORD_7)
For Each p In Pages
p.IE_COLOR_DETECT.InputIma
Next p
End Sub
However, if you're happy with a mostly accurate result it should be possible with regular expressions like this one:
http://www.myregextester.com/?r=66cdd2b4
In the linked example, I'm only looking at a for loop nested in a for loop. If's aren't loops by the way.
Is it only for's and if's that you're interested in?