Forum Discussion

anju355's avatar
anju355
New Contributor
4 years ago
Solved

Need to check in a file if dim is displaying in the routine or not

Hi All,    I need help in writing a code for below scenario: I have a txt file where there is around 2000+ line of code and I need to check multiple routines that if the DIM is displaying under ...
  • tphillips's avatar
    4 years ago

    Hi. Not 100% sure what you're trying to achieve here. Are you trying to parse Visual Basic code to determine if there are variables defined outside functions defined in the code?

     

    Parsing code is quite an advanced task, especially if you have to factor in all the edge cases. At a basic level you need to read in the code using one of these approaches (probably easiest to read the file line-by-line into an array), find all your "Dim" statements and check that they occur inside a "Sub...End Sub" block (by reading backwards and forwards).

     

    This is where it gets a little tricky. When you find a "Dim" statement, you need to go backwards to find a "Sub" statement without encountering any "End Sub" statements. Likewise, you will need to read forwards to find an "End Sub" statement without encountering any "Sub" statements.