A
Ameen
I am very new to programming and VB.net, and I wrote the code below,
but it seem to go on an infinite loop. Please tell me what I am doing
wrong.
Private Sub search(ByVal indexstart)
Pos1 = LineNoSpace.IndexOf("<!--", indexstart) 'checks for the
begining of the comment
While Pos1 = -1 And Not (line Is Nothing) ' keep checking till
end of file
nextline()
Pos1 = LineNoSpace.IndexOf("<!--", indexstart)
End While
If Pos1 <> -1 Then ' first comment was found, continue
Pos2 = LineNoSpace.IndexOf("#includevirtual", Pos1) 'check
if the starting comment contains #include virtual
While Pos2 = -1 And Not (line Is Nothing) 'if not found in
the same line check the next line till found or end reached
nextline()
Pos2 = LineNoSpace.IndexOf("#includevirtual",
indexstart)
End While
If Pos2 <> -1 Then 'if virtual
include is found, check for the first double quotes
Pos3 = LineNoSpace.IndexOf("""", Pos2) 'in same
line
While Pos3 = -1 And Not (line Is Nothing) 'keep
checking for the first double quotes in next line to end of file
nextline()
Pos3 = LineNoSpace.IndexOf("""", indexstart)
End While
If Pos3 <> -1 Then 'if first double quotes are found
then
Pos4 = LineNoSpace.IndexOf("""", Pos3 + 1) ' check
for second double quotes in the same line
If Pos4 <> -1 Then ' if second double quotes is
found in the same line continue
OriginalLine = Mid(LineNoSpace, Pos3 + 1, Pos4
- Pos3 + 2) & "in line: " & linenumber 'creating a temporary message
before moving to the next line
CheckCommentClose() 'check if there is a
problem with the closing of the comment tag, display problem if there
is
If Pos4 <> 0 Then 'if there was no problem
with the closing comment then
While LineNoSpace.IndexOf("<!--", Pos4) <>
-1 'as long as there is a new comment tag in the same line check for
the virtual include
ListBox1.Items.Add(filename & "
includes: " & Mid(LineNoSpace, Pos3 + 1, Pos4 - Pos3 + 1) & " - in
line: " & linenumber) 'list the current virtual include found
counter = counter + 1 'count of
virtual includes found
search(Pos3) 'start search again from
the position right before the new comment open tag(RECURSION)
End While
ListBox1.Items.Add(filename & " includes: "
& Mid(LineNoSpace, Pos3 + 1, Pos4 - Pos3 + 1) & " - in line: " &
linenumber)
counter = counter + 1 'count of
virtual includes found
nextline()
Else 'else there was a problem with the comment
closing tag in the next line and beyond
ListBox1.Items.Add(filename & " - includes:
" & OriginalLine)
counter = counter + 1
nextline()
End If
Else 'if the second double quotes is not found
in the same line, display error and continue
ListBox1.Items.Add("There is an error in line:
" & linenumber & " - missing double quotes -")
counter = counter + 1 'count of virtual
includes found
nextline()
End If
End If
End If
End If
indexstart = 0
Pos1 = -1
Pos2 = -1
Pos3 = -1
Pos4 = -1
End Sub
but it seem to go on an infinite loop. Please tell me what I am doing
wrong.
Private Sub search(ByVal indexstart)
Pos1 = LineNoSpace.IndexOf("<!--", indexstart) 'checks for the
begining of the comment
While Pos1 = -1 And Not (line Is Nothing) ' keep checking till
end of file
nextline()
Pos1 = LineNoSpace.IndexOf("<!--", indexstart)
End While
If Pos1 <> -1 Then ' first comment was found, continue
Pos2 = LineNoSpace.IndexOf("#includevirtual", Pos1) 'check
if the starting comment contains #include virtual
While Pos2 = -1 And Not (line Is Nothing) 'if not found in
the same line check the next line till found or end reached
nextline()
Pos2 = LineNoSpace.IndexOf("#includevirtual",
indexstart)
End While
If Pos2 <> -1 Then 'if virtual
include is found, check for the first double quotes
Pos3 = LineNoSpace.IndexOf("""", Pos2) 'in same
line
While Pos3 = -1 And Not (line Is Nothing) 'keep
checking for the first double quotes in next line to end of file
nextline()
Pos3 = LineNoSpace.IndexOf("""", indexstart)
End While
If Pos3 <> -1 Then 'if first double quotes are found
then
Pos4 = LineNoSpace.IndexOf("""", Pos3 + 1) ' check
for second double quotes in the same line
If Pos4 <> -1 Then ' if second double quotes is
found in the same line continue
OriginalLine = Mid(LineNoSpace, Pos3 + 1, Pos4
- Pos3 + 2) & "in line: " & linenumber 'creating a temporary message
before moving to the next line
CheckCommentClose() 'check if there is a
problem with the closing of the comment tag, display problem if there
is
If Pos4 <> 0 Then 'if there was no problem
with the closing comment then
While LineNoSpace.IndexOf("<!--", Pos4) <>
-1 'as long as there is a new comment tag in the same line check for
the virtual include
ListBox1.Items.Add(filename & "
includes: " & Mid(LineNoSpace, Pos3 + 1, Pos4 - Pos3 + 1) & " - in
line: " & linenumber) 'list the current virtual include found
counter = counter + 1 'count of
virtual includes found
search(Pos3) 'start search again from
the position right before the new comment open tag(RECURSION)
End While
ListBox1.Items.Add(filename & " includes: "
& Mid(LineNoSpace, Pos3 + 1, Pos4 - Pos3 + 1) & " - in line: " &
linenumber)
counter = counter + 1 'count of
virtual includes found
nextline()
Else 'else there was a problem with the comment
closing tag in the next line and beyond
ListBox1.Items.Add(filename & " - includes:
" & OriginalLine)
counter = counter + 1
nextline()
End If
Else 'if the second double quotes is not found
in the same line, display error and continue
ListBox1.Items.Add("There is an error in line:
" & linenumber & " - missing double quotes -")
counter = counter + 1 'count of virtual
includes found
nextline()
End If
End If
End If
End If
indexstart = 0
Pos1 = -1
Pos2 = -1
Pos3 = -1
Pos4 = -1
End Sub