443,694 Members | 1,845 Online Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

# Need Help Converting VB6 to VB.NET

 P: n/a Hello All, I have tried multiple online tools to convert an VB6 (bas) file to VB.NET file and no luck. I was hoping that someone could help me covert this. I am new to the .NET world and still learning all help would be greatly apperciated. Attribute VB_Name = "Module1" Option Explicit Dim pass\$ Dim Strg\$ Function decrypt(ByVal H\$) As String Dim i As Integer, J\$ pass\$ = "THEFELDGROUP" 'H\$ = the buffered encrypted data H\$ = Mid\$(H\$, 3, Val(Left\$(H\$, 2))) ' debuffer it Strg\$ = "" For i = 1 To Len(H\$) Step 2 J\$ = Mid\$(H\$, i, 2) Strg\$ = Strg\$ + Chr\$(Val("&H" + J\$)) Next 'Strg\$ now contains the encrypted string, which you can now 'decrypt. Call Crypt(pass\$, Strg\$) 'strg\$ now is decrypted decrypt = Strg\$ End Function Function Crypt(pass\$, Strg\$) Dim a, b Dim i As Integer a = 1 For i = 1 To Len(Strg\$) b = Asc(Mid\$(pass\$, a, 1)): a = a + 1: If a Len(pass\$) Then a = 1 Mid\$(Strg\$, i, 1) = Chr\$(Asc(Mid\$(Strg\$, i, 1)) Xor b) Next End Function Oct 9 '06 #1
16 Replies

 P: n/a Noticed the name of this NG? Please post to the microsoft.public.dotnet.languages.vb NG. Willy.

 P: n/a

 P: n/a Yes, Actually I will be converting this to C#. Thought converting to VB.NET might be easier. If anyone could help me convert this to C#, even better :). Thanks Mark Rae wrote:

 P: n/a

 P: n/a Use the VB.NET upgrade wizard (with Visual Studio) to convert this. Hopefully, it can handle those nasty ancient VB1 type specifiers... -- David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter Instant Python: VB to Python converter "ma**********@gmail.com" wrote: Hello All, I have tried multiple online tools to convert an VB6 (bas) file to VB.NET file and no luck. I was hoping that someone could help me covert this. I am new to the .NET world and still learning all help would be greatly apperciated. Attribute VB_Name = "Module1" Option Explicit Dim pass\$ Dim Strg\$ Function decrypt(ByVal H\$) As String Dim i As Integer, J\$ pass\$ = "THEFELDGROUP" 'H\$ = the buffered encrypted data H\$ = Mid\$(H\$, 3, Val(Left\$(H\$, 2))) ' debuffer it Strg\$ = "" For i = 1 To Len(H\$) Step 2 J\$ = Mid\$(H\$, i, 2) Strg\$ = Strg\$ + Chr\$(Val("&H" + J\$)) Next 'Strg\$ now contains the encrypted string, which you can now 'decrypt. Call Crypt(pass\$, Strg\$) 'strg\$ now is decrypted decrypt = Strg\$ End Function Function Crypt(pass\$, Strg\$) Dim a, b Dim i As Integer a = 1 For i = 1 To Len(Strg\$) b = Asc(Mid\$(pass\$, a, 1)): a = a + 1: If a Len(pass\$) Then a = 1 Mid\$(Strg\$, i, 1) = Chr\$(Asc(Mid\$(Strg\$, i, 1)) Xor b) Next End Function Oct 9 '06 #6

 P: n/a Thanks for the info David but I have already tried that and it made it look even worse. Any Help? David Anton wrote: Use the VB.NET upgrade wizard (with Visual Studio) to convert this. Hopefully, it can handle those nasty ancient VB1 type specifiers... -- David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter Instant Python: VB to Python converter "ma**********@gmail.com" wrote: Hello All, I have tried multiple online tools to convert an VB6 (bas) file to VB.NET file and no luck. I was hoping that someone could help me covert this. I am new to the .NET world and still learning all help would be greatly apperciated. Attribute VB_Name = "Module1" Option Explicit Dim pass\$ Dim Strg\$ Function decrypt(ByVal H\$) As String Dim i As Integer, J\$ pass\$ = "THEFELDGROUP" 'H\$ = the buffered encrypted data H\$ = Mid\$(H\$, 3, Val(Left\$(H\$, 2))) ' debuffer it Strg\$ = "" For i = 1 To Len(H\$) Step 2 J\$ = Mid\$(H\$, i, 2) Strg\$ = Strg\$ + Chr\$(Val("&H" + J\$)) Next 'Strg\$ now contains the encrypted string, which you can now 'decrypt. Call Crypt(pass\$, Strg\$) 'strg\$ now is decrypted decrypt = Strg\$ End Function Function Crypt(pass\$, Strg\$) Dim a, b Dim i As Integer a = 1 For i = 1 To Len(Strg\$) b = Asc(Mid\$(pass\$, a, 1)): a = a + 1: If a Len(pass\$) Then a = 1 Mid\$(Strg\$, i, 1) = Chr\$(Asc(Mid\$(Strg\$, i, 1)) Xor b) Next End Function Oct 10 '06 #7

 P: n/a Mannit, I assume that this is a troll message to let people say that C# is better. In my idea you don't know much from VB otherwise you would not have included this in your message. 'H\$ = the buffered encrypted data Cor Oct 10 '06 #8

 P: n/a Yeah, I perfer C# over VB.NET anytime. I did not even noticed that I had that in the statement. So, has anyone converted this so far? :( -If I had the ability to cry on this forum, I would make this face cry. Cor Ligthert [MVP] wrote: Mannit, I assume that this is a troll message to let people say that C# is better. In my idea you don't know much from VB otherwise you would not have included this in your message. 'H\$ = the buffered encrypted data Cor Oct 10 '06 #9

 P: n/a On Oct 9, 3:01 pm, manmit.wa...@gmail.com wrote: Attribute VB_Name = "Module1" Option Explicit Dim pass\$ Dim Strg\$ These are just strings, so declare them normally in C#: string pass; string Strg; > Function decrypt(ByVal H\$) As String This is a method that takes a string and returns a string: public string decrypt(string h) Dim i As Integer, J\$ An integer and a string: int i; string J; > pass\$ = "THEFELDGROUP" This is just string assignment. > 'H\$ = the buffered encrypted data Same here H\$ = Mid\$(H\$, 3, Val(Left\$(H\$, 2))) Here, the Mid\$ statement is taking a substring of a string so in .Net it would be the string.Substring method. The Left\$ method would also be replaced by the Substring method. ' debuffer it Strg\$ = "" String assignment again. For i = 1 To Len(H\$) Step 2 For loop: for (int i = 1; i <= H.Length; i += 2) J\$ = Mid\$(H\$, i, 2) Strg\$ = Strg\$ + Chr\$(Val("&H" + J\$)) Next More Substring activity, along with some string concatenation. The remaining method is just more of the same. It should be a fairly straight forward conversion. If you have a specifc problem, you can post those questions for help here. Good Luck. Oct 10 '06 #10

 P: n/a Thanks Chris for the help. I have something that I bieleve might be on the right track. But somehow it is still not working. TEST Data - H = 200C3820342C292A24377E Output decrypted H should = Xperience1 But I am getting the following - â8 4,)*\$7~ public string Mydecrypt(string H) { long i; string J; const string pass = "THEFELDGROUP"; H = H.Substring(2, Convert.ToInt32(Microsoft.VisualBasic.Conversion.V al(H.Substring(0, 2)))); string Strg = ""; int tempFor1 = H.Length; for (i = 1; i <= tempFor1; i += 2) { int t = Convert.ToInt32(i-1); J = H.Substring(t, 2); Strg = Strg + (char)(Microsoft.VisualBasic.Conversion.Val("&H" + J)); } myCrypt(pass, Strg); return Strg; } public object myCrypt(string pass, string Strg) { int a; int b; long i = 0; a = 1; long tempFor1 = Strg.Length; for (i = 1; i <= tempFor1; i++) { b = System.Convert.ToInt32(pass[a - 1]); a = a + 1; if (a pass.Length) { a = 1; } Strg += Strg.Remove(Convert.ToInt32(i - 1), 1).Insert(Convert.ToInt32(i - 1), ((char)(System.Convert.ToInt32(Strg[Convert.ToInt32(i - 1)]) ^ b)).ToString()); } return Strg; } Oct 10 '06 #11

 P: n/a http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Oct 10 '06 #12

 P: n/a Thanks Jon, This helped a lot, to answer your question about the "20" in the front of the data. I basically added the following to my application: temp = temp.Substring(2,Convert.ToInt32(Microsoft.VisualB asic.Conversion.Val(temp.Substring(0,2)))); As you already know, this will trim of the first two characters of the string. Now I usually don't ask people for help but this one was a total brain teaser. If you do not mind, can you please explain to me where each line of your C# fits in with the VB6 code I have posted on top of this post? Thanks again Jon Oct 10 '06 #13

 P: n/a http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Oct 11 '06 #14

 P: n/a Thanks Jon, your explaination makes it a little clearer. I do have a question though, in my original VB6 code, there was a method called Crypt, which took a 'key' and a 'string value'. The thing I don't understand is does this method actually encrypts a string, because I do not see it returning anything. Please tell me if I am wrong or incorrect. I have also took your code and see if I can create an Encryption Method just to test it out as well learn C# even more. Below is what I have so far. static byte[] deParseHex(string text) { byte[] ret = new byte[text.Length * 2]; for (int i = 0; i < ret.Length; i++) { ret[i] = Convert.ToByte(text.Substring(i * 2), 16); } return ret; } static string Encrypt(string password, string decrypted) { byte[] binary = deParseHex(decrypted); char[] chars = new char[binary.Length]; for (int i = 0; i < chars.Length; i++) { chars[i] = (char)(password[i % password.Length] ^ binary[i]); } return new string(chars); } Jon wrote: If any of it stumps you, I can go through individual bits in more detail. Oct 12 '06 #15

 P: n/a Thanks Jon, your explanation makes it a little clearer. I do have a question though, in my original VB6 code, there was a method called Crypt, which took a 'key' and a 'string value'. The thing I don't understand is does this method actually encrypts a string, because I do not see it returning anything. Please tell me if I am wrong or incorrect. I have also taken your code and see if I can create an Encryption Method just to test it out as well learn C# even more. Below is what I have so far. static byte[] deParseHex(string text) { byte[] ret = new byte[text.Length * 2]; for (int i = 0; i < ret.Length; i++) { ret[i] = Convert.ToByte(text.Substring(i * 2), 16); } return ret; } static string Encrypt(string password, string decrypted) { byte[] binary = deParseHex(decrypted); char[] chars = new char[binary.Length]; for (int i = 0; i < chars.Length; i++) { chars[i] = (char)(password[i % password.Length] ^ binary[i]); } return new string(chars); } Oct 12 '06 #16

 P: n/a http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Oct 13 '06 #17

### This discussion thread is closed

Replies have been disabled for this discussion. 