By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
16 Replies


P: n/a
Noticed the name of this NG? Please post to the
microsoft.public.dotnet.languages.vb NG.
Willy.
<ma**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| 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 #2

P: n/a
<ma**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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 to the world of newsgroups too, by the looks of it...

Is there any particular reason that you posted a question regarding
converting VB6 to VB.NET to a C# newsgroup...?
Oct 9 '06 #3

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:
<ma**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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 to the world of newsgroups too, by the looks of it...

Is there any particular reason that you posted a question regarding
converting VB6 to VB.NET to a C# newsgroup...?
Oct 9 '06 #4

P: n/a
<ma**********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Yes,
Actually I will be converting this to C#.
Ah... what you need to do is to enable telepathy mode when posting on
newsgroups - if you're using Outlook or Outlook Express, it's under Tools,
Options...

That way, everybody will just instinctively understand what you really
mean...
Oct 9 '06 #5

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
<ma**********@gmail.comwrote:
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
Well, the converted code is pretty horrible - I've tidied it up a bit
and I think this is *nearly* what you want. However, it only decrypts
to Xperience1 when you get rid of the 20 from the front of the test
data. Are you sure your original data is correct?

Note that your "encryption" is very weak, and that it also doesn't
support Unicode properly.

using System;

class Test
{
static void Main()
{
Console.WriteLine (Decrypt("THEFELDGROUP",
"0C3820342C292A24377E"));

}

static byte[] ParseHex(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, 2), 16);
}
return ret;
}

static string Decrypt (string password,
string encrypted)
{
byte[] binary = ParseHex(encrypted);
char[] chars = new char[binary.Length];
for (int i=0; i < chars.Length; i++)
{
chars[i] = (char)(binary[i] ^ password[i%password.Length]);
}
return new string(chars);
}
}

--
Jon Skeet - <sk***@pobox.com>
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
<ma**********@gmail.comwrote:
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.
Actually, it'll do quite a bit more than that, by the looks of it. Far
simpler is:

temp = temp.Substring(2);

Ah yes - I hadn't seen this line:
H$ = Mid$(H$, 3, Val(Left$(H$, 2)))

I don't see what the point of that bit is, to be honest - it just gives
the length of the rest of the string. If you really need it, use:

temp = temp.Substring (2, int.Parse(temp.Substring(0, 2));

There's no need for all these calls to the Visual Basic dll.
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?
Well, I didn't do a line by line conversion. I thought about what the
VB6 code is doing in chunks, and converted the chunks. There are two
basic operations here:

1) Parse the hex values, essentially as bytes (but then treat them as
characters, which will give a different result in .NET than in VB6, but
never mind). In the C# version this is performed by the ParseHex method
which returns an array of bytes. We parse each pair of characters using
Convert.ToByte, specifying 16 as the base (for hex).

2) Take each value (byte in the C# code, character in the original VB6
code) and XOR it with the value of the corresponding character in the
password. The VB6 version kept an extra counter to wrap round if it
reaches the end of the password, but in the C# version I just use the
remainder operator (%) to do that without having a separate counter.

If any of it stumps you, I can go through individual bits in more
detail.

--
Jon Skeet - <sk***@pobox.com>
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
<ma**********@gmail.comwrote:
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 don't know enough about VB to say for sure, but I suspect it was
changing the string "in-place" with this:

Mid$(Strg$, i, 1) = Chr$(Asc(Mid$(Strg$, i, 1)) Xor b)

You *could* do that with a StringBuilder, and change the data in place,
but it's neater just to return a new string.
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.
Your "deParseHex" is incorrect. It should be taking a byte array and
returning a string - effectively producing a hex representation of what
you give it.

You then need to change your Encrypt method to do the "encryption"
(within a byte array, hoping that Unicode isn't going to be a problem
for you) and call deParseHex (or "ConvertToHex" as I'd call it) *after*
that.

Basically, to work out the encryption process you need to reverse the
order and action of the decryption process. So as the decryption
process is:

o Start with string
o Convert string into bytes by treating each pair of characters as the
hex representation of a byte
o XOR each byte with the value of the corresponding password character
o Convert bytes into a string

then the encryption process is:

o Convert string into bytes
o XOR each byte with the value of the corresponding password character
o Convert bytes into string by converting each byte into its hex
representation
o End with string

--
Jon Skeet - <sk***@pobox.com>
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.