|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help with C# to VB.Net ... Pleaseam 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(); } Rob wrote:
> I am trying to convert the following C# routine (below) to Vb.Net. I % is the modulus operator in C#, as google easily shows.> 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. -- Larry Lard Replies to group please "Rob" <rob_pan***@asdsoftware.com> schrieb: Converting code between .NET programming languages>I am trying to convert the following C# routine (below) to Vb.Net. <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/> result.Append(chars(b Mod (chars.Length - 1)))
-- Show quoteHide quoteDavid 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 "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(); > } > > 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(); > }
RANT: option strict etc
Handling DBNull from databases Final Post of the day c# to vb.net getting screen coordinates for positioning a floating control next to a tableLayOutPanel embeded con Tokenizing Emulating keyboard strokes in vb.net Refer to sheet2 - even when named To catch when a process is terminated cast from string to button |
|||||||||||||||||||||||