Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2006, 11:16 AM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default vb.net Vs C#

I have converted following C# script to vb.net(http://www.codeproject.com/useritems/UniqueKeys.asp). Can anyone let me know vb.net script is same as c#? Why am asking is am not getting fixed length Unique ID.

C#:
private string GetUniqueKey()
  {
  int maxSize = 8 ;
  char[] chars = new char[62];
  string a;
  a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890";
  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();
  }


VB.NET

    Function GetUniqueKey()
        Dim MaxSize As Integer = 8
        Dim chars(62) As Char
        Dim a As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890"
        chars = a.ToCharArray()
        Dim size As Integer = MaxSize
        Dim data(size) As Byte
        Dim crypt As New RNGCryptoServiceProvider
        crypt.GetNonZeroBytes(data)
        Dim result As New StringBuilder(MaxSize)
        Dim b As Byte
        For Each b In data
            result.Append(chars(b Mod (chars.Length - 1)))
        Next
        Console.WriteLine(result.ToString)
        Return result.ToString()
    End Function


__________________
Rams





Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net 2008 re: VB.NET databases book bigbearjeff VB.NET 0 June 2nd, 2008 01:22 PM
convert dsr file from vb to vb.net Shashi001 VB Components 1 September 22nd, 2006 12:24 PM
VB.Net question on Windows VB.Net datagrids dmsousa VS.NET 2002/2003 1 January 19th, 2005 02:45 PM
vb.net 2002 OR vb.net 2003 metalaaron VB.NET 2002/2003 Basics 0 August 5th, 2003 10:00 AM
vb.net 2002 - vb.net 2003 book metalaaron Wrox Book Feedback 0 August 2nd, 2003 10:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.