CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2006
    Posts
    20

    Question Component for compare codes

    I am developing an appilication in which I need to compare two pieces of VB code. Is there any component which I can embed in my application? Or any help for coding such an tool?

    Best Regards
    Surya

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Component for compare codes

    Hi,

    How do you want to compare the code? Do you want a have a visual display of the differences? Perhaps you can use tools like WinDiff or KDiff which are readily available. I don't know if they can be embedded in your application. Even if they could I don't actually see any good reason for doing that. Don't re-invent the wheel...

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Component for compare codes

    Quote Originally Posted by nelo View Post
    ...I don't actually see any good reason for doing that. Don't re-invent the wheel...
    Maybe a school project ? reason enough?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Component for compare codes

    Quote Originally Posted by snayyagari View Post
    I am developing an appilication in which I need to compare two pieces of VB code. Is there any component which I can embed in my application? Or any help for coding such an tool?

    Best Regards
    Surya
    Use Visual Source Safe to compare the code.

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Component for compare codes

    Quote Originally Posted by Shuja Ali View Post
    Use Visual Source Safe to compare the code.
    Hmm.. Shuja, I think he is talking about that he needs to compare that VB code in his program. and not for his program. So whhat he needs is to parse the VB code and compae it maybe in two rtb TextBoxes one left and one right and highlighting different code in a color like the program WinMerge does.
    I dont know why he needs that, but that wasn't the question the question was how to do it.
    I think this will need a lot of parsing the files line by line. Its really just as reinventing somethin´g which is already done by existing programs.
    Will be a lot of work in my opinion. As a first idea I would suggest to download a free version of WinMerge and looking how this was achieved there.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  6. #6
    Join Date
    Feb 2006
    Posts
    20

    Re: Component for compare codes

    Thanks for you replies. But I require it for my project. I am developing this tool specifically for our product. The product is called Process Expert. There are different blocks in which industrial process values are stored which in turn stores in mdb. A set of blocks is called a worksheet. In some blocks VB code is written to stablize the industrial process. I need to compare two different worksheets. I am able compare all the values, but I need to compare the VB code. If any body can help how to go about it, it will be helpful for me.

    Regards
    Surya

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Component for compare codes

    The amount of code you will need to do this will differ on the fact how precise you need to compare the code and which effort is done to nullyfy changes for example done by simple adding a new empty line ((vbCrLf) and such elements who doesn't really change the code but change the format. You cannot simple compare line by line. What if someone has added comments in between. So then your code seems to be totally another one. Or what happens if someone uses the tools and cuts out a method to place it on another place in the same worksheet. Or much bader if he changes a method from a private one to a global used in a .bas modul

    You are the only who knows what could be the problems of the code in suspection so you are the only who can design a 'fundamental way' what could be done and how. Dont think this is a small issue, it isn't especially because VB is such a sort of sloppy code in my eyes, things can be done very different but still are the same. BTW is this VB or VBA becuase what you mentioned seems me to be VBA. There once was a very simple example about a code parser in the book 'MS Visual C# 2005 stepby step' it shows the usage of interfaces to analyse codepart tokens but it uses the original C# code and does nothing then only to show how you may have different classes of Tokens all read in by having this token classes all using the same interface.
    Maybe a small hint for beginning
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  8. #8
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Component for compare codes

    Quote Originally Posted by Shuja Ali View Post
    Ahh, I see. I thought we were looking for some kind of comparison tool here. My bad.

    The simplest solution that comes to my mind is to use StrComp() function. This function will tell you if you two strings are same or different. Something like this
    Code:
        Dim text1 As String, text2 As String
        text1 = "This is first string"
        text2 = "this is first string"
        If StrComp(text1, text2, vbTextCompare) = 0 Then
            MsgBox "both are same"
        Else
            MsgBox "they are different"
        End If
    You can do this with a larger block of strings too.
    Hey Shuja ! we are in the C# forum so I think his code should be C# only what should be compared is VB or IMHO VBA as he wrotes from code inside an application.

    As I told already the needed comparecode may differ from how this code is arranged but may need codeparsing and cleaning out empty lines if they are in one of the sheets but not in that one that should be compared with it. Maybe, I dont know his needs its also enough to have two RTB boxes on the screen which shows both documents and he compares it manually.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  9. #9
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Component for compare codes

    Quote Originally Posted by snayyagari View Post
    Thanks for you replies. But I require it for my project. I am developing this tool specifically for our product. The product is called Process Expert. There are different blocks in which industrial process values are stored which in turn stores in mdb. A set of blocks is called a worksheet. In some blocks VB code is written to stablize the industrial process. I need to compare two different worksheets. I am able compare all the values, but I need to compare the VB code. If any body can help how to go about it, it will be helpful for me.

    Regards
    Surya
    Thanks for providing more details. JohhnyPoet and Shuja Ali's contributions are valuable. However having looked at your requirements I still think that you will be reinventing the wheel. It is certainly possible to do what you want. But is not better to redistribute a third party comparison tool with your application? Think about: it has already been developed and it has already been tested. All you have to do is ship it out. If it comes at a cost it can be recovered from the cost of a product. From within your application you should be able to launch the third party comparison tool with the data to compare. I'm not sure what kind of budget/timescales are involved in your project. I've seen a few projects go over budget and late because the people involved where unwilling to go for the most pragmatic option. It would be nice and elegant to have the comparison fully embedded in your application. I'm not sure it is the most cost effective or pragmatic approach. If you can't find a third party tool then off course you can justify the effort of developing it yourself.

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Component for compare codes

    Duh. I don't believe this. I have removed the post. This might be helpful
    http://support.microsoft.com/kb/320348

  11. #11
    Join Date
    Feb 2006
    Posts
    20

    Re: Component for compare codes

    Thanks to nelo, Jonnypeot and shuja ali for your valuable inputs. The code I am comparing is VBA. As nelo suggested I would try my tecnical manager for purchasing a third party tool. If not I need to do it myself. But anyway once again thanks to all.

    Regards
    Surya

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

Featured