Help with C# to VB.Net ... Please

R

Rob

I am trying to convert the following C# routine (below) to Vb.Net. I
am having troubles with the following line of code

{ result.Append(chars[b % (chars.Length - 1)]); }

My C# to Vb.Net routine converted the line above to be:

result.Append(chars(b % (chars.Length - 1)))

But I am getting error "Character is not Valid" on the "%".

Any help would be appreciated.

Cheers,
Rob Panosh
Advanced Software Designs


private string GetUniqueKey()
{
int maxSize = 8 ;
int minSize = 5 ;
char[] chars = new char[62];
string a;
a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
chars = a.ToCharArray();
int size = maxSize ;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data) ;
size = maxSize ;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size) ;
foreach(byte b in data )
{ result.Append(chars[b % (chars.Length - 1)]); }
return result.ToString();
}
 
L

Larry Lard

Rob said:
I am trying to convert the following C# routine (below) to Vb.Net. I
am having troubles with the following line of code

{ result.Append(chars[b % (chars.Length - 1)]); }

My C# to Vb.Net routine converted the line above to be:

result.Append(chars(b % (chars.Length - 1)))

But I am getting error "Character is not Valid" on the "%".

Any help would be appreciated.

% is the modulus operator in C#, as google easily shows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top