Click to See Complete Forum and Search --> : Component for compare codes
snayyagari
April 13th, 2009, 01:22 AM
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
nelo
April 13th, 2009, 06:33 AM
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...:)
JonnyPoet
April 13th, 2009, 11:12 AM
...I don't actually see any good reason for doing that. Don't re-invent the wheel...:)Maybe a school project ? reason enough? :D
Shuja Ali
April 13th, 2009, 03:29 PM
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. :)
JonnyPoet
April 13th, 2009, 04:49 PM
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.
snayyagari
April 13th, 2009, 10:32 PM
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
JonnyPoet
April 14th, 2009, 02:25 AM
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
JonnyPoet
April 14th, 2009, 06:10 AM
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 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 :D ! 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.
nelo
April 14th, 2009, 06:45 AM
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.
Shuja Ali
April 14th, 2009, 07:56 AM
Duh. I don't believe this. I have removed the post. This might be helpful
http://support.microsoft.com/kb/320348
snayyagari
April 14th, 2009, 11:29 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.