Results 1 to 7 of 7

Thread: Counting loops and Ifs in a piece of code (Resolved)

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    5

    Talking Counting loops and Ifs in a piece of code (Resolved)

    hi everyone

    Im quite new to vb so please bear with me.
    What I would like to do is write a piece of vb code
    which will read in another piece of vb code line by line.
    But it needs to be able to count how many occurances
    of a loop and IF statements which appear in that code.
    This must however ignore any IFs or similar words that
    may appear in any comments or within a string.

    Hope that makes sense.

    So far ive managed to write a very simple piece of code
    which counts the number of FORs, IFs, and WHILEs.

    VB Code:
    1. Dim strText As String
    2. Dim intCounter1 As Integer
    3. Dim intCounter2 As Integer
    4. Dim intCounter3 As Integer
    5.  
    6. Open "C:\blah\blah\something.txt" For Input As #1
    7.  
    8. While Not EOF(1)
    9.  
    10.   Line Input #1, strText
    11.  
    12.     If InStr(strText, "End If") <> 0 Then
    13.       intCounter1 = intCounter1 + 1
    14.     End If
    15.    
    16.     If InStr(strText, "Loop") <> 0 Then
    17.       intCounter2 = intCounter2 + 1
    18.     End If
    19.    
    20.     If InStr(strText, "Wend") <> 0 Then
    21.       intCounter3 = intCounter3 + 1
    22.     End If
    23.    
    24. Wend
    25.  
    26. txtIf.Text = intCounter1
    27. txtFor.Text = intCounter2
    28. txtWhile.Text = intCounter3
    29. txtTotal.Text = intCounter1 + intCounter2 + intCounter3
    30.  
    31. Close #1
    32.  
    33. End Sub

    Thanks in advance for any advice or tips.
    Last edited by abe; Oct 13th, 2003 at 06:15 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width