How to parse VBA code and generate XML file from it [Using C#]?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prashantdixit
    New Member
    • Jun 2010
    • 36

    How to parse VBA code and generate XML file from it [Using C#]?

    Hi all,

    i have got a VBA code (a Subroutine in a module). Now what i want to do is that parse each line of this Subroutine (VBA code) and generate XML file from it using C#.

    for example:

    Option Compare Database
    Dim RecordNumber As Integer
    Dim TableName As String
    Dim FLD As Field
    Dim Db As Database, rs As Recordset
    Dim TimeStart As Single, TimeEnd As Single, TimeElapsed As Single
    Option Explicit

    Sub ChangeAreaTD()
    Set rs = Db.OpenRecordse t(TableName, dbOpenTable)
    Set FLD = rs![Field1]
    TimeStart = Timer
    .....

    Sub End



    This is my Subroutine code in a vba file

    Now i'll be reading line by line from this file and parse the word and generate XML file from it.

    Like
    Code:
     String filename = "C:/.vba";
                    using (StreamReader streader = new StreamReader(filename))
                    {
                        String line;
                        while ((line = streader.ReadLine()) != null)
                        {
                            Processline(line);
                            //Console.WriteLine(line);                    
                        }
                        streader.Close();
                        Console.ReadLine();
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }         
            }
    
            private static void Processline(string line)
            {            
                if(line.StartsWith("Sub"))
                {
    //Lines of Code>
    }
    if(line.Contains("="))
                {
    //Lines of Code
    }
    }
    I am doing like this. What should be there in Processline Method above. My question is how can i do this using C#?

    Is there any other way to accomplish this, then please suggest.

    How can i read lines from this Sub and Processeach line to generate an equivalent XML file of this VBA code using C#?

    Any help would be highly appreciated.


    Thanks

    Mintoo
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Originally posted by prashantdixit
    Hi all,

    i have got a VBA code (a Subroutine in a module). Now what i want to do is that parse each line of this Subroutine (VBA code) and generate XML file from it using C#.

    for example:

    Option Compare Database
    Dim RecordNumber As Integer
    Dim TableName As String
    Dim FLD As Field
    Dim Db As Database, rs As Recordset
    Dim TimeStart As Single, TimeEnd As Single, TimeElapsed As Single
    Option Explicit

    Sub ChangeAreaTD()
    Set rs = Db.OpenRecordse t(TableName, dbOpenTable)
    Set FLD = rs![Field1]
    TimeStart = Timer
    .....

    Sub End



    This is my Subroutine code in a vba file

    Now i'll be reading line by line from this file and parse the word and generate XML file from it.

    Like
    Code:
     String filename = "C:/.vba";
                    using (StreamReader streader = new StreamReader(filename))
                    {
                        String line;
                        while ((line = streader.ReadLine()) != null)
                        {
                            Processline(line);
                            //Console.WriteLine(line);                    
                        }
                        streader.Close();
                        Console.ReadLine();
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }         
            }
    
            private static void Processline(string line)
            {            
                if(line.StartsWith("Sub"))
                {
    //Lines of Code>
    }
    if(line.Contains("="))
                {
    //Lines of Code
    }
    }
    I am doing like this. What should be there in Processline Method above. My question is how can i do this using C#?

    Is there any other way to accomplish this, then please suggest.

    How can i read lines from this Sub and Processeach line to generate an equivalent XML file of this VBA code using C#?

    Any help would be highly appreciated.


    Thanks

    Mintoo
    It would be difficult for you to analyze such code and judge as
    where did the subroutine started ans when did it end..

    Its as tough as building an language interpreter..

    Comment

    Working...