Home All Groups Group Topic Archive Search About

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

Author
13 Jun 2006 12:35 PM
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();
  }

Author
13 Jun 2006 1:04 PM
Larry Lard
Rob wrote:
> 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.

--
Larry Lard
Replies to group please
Author
13 Jun 2006 1:28 PM
IdleBrain
Try result.Append(chars(b Mod (chars.Length - 1)))
Author
13 Jun 2006 1:45 PM
Herfried K. Wagner [MVP]
"Rob" <rob_pan***@asdsoftware.com> schrieb:
>I am trying to convert the following C# routine (below) to Vb.Net.

Converting code between .NET programming languages
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=languageconverters&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
13 Jun 2006 2:27 PM
David Anton
result.Append(chars(b Mod (chars.Length - 1)))
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter


Show quoteHide quote
"Rob" wrote:

> 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();
>   }
>
>
Author
13 Jun 2006 3:07 PM
Rob
Everybody,

Thanks for your help.

Cheers,
Rob

Rob wrote:
Show quoteHide quote
> 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();
>   }