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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    #1

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

    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(c hars[b % (chars.Length - 1)]); }

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

    result.Append(c hars(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 = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ1234567 890";
    chars = a.ToCharArray() ;
    int size = maxSize ;
    byte[] data = new byte[1];
    RNGCryptoServic eProvider crypto = new RNGCryptoServic eProvider();
    crypto.GetNonZe roBytes(data) ;
    size = maxSize ;
    data = new byte[size];
    crypto.GetNonZe roBytes(data);
    StringBuilder result = new StringBuilder(s ize) ;
    foreach(byte b in data )
    { result.Append(c hars[b % (chars.Length - 1)]); }
    return result.ToString ();
    }

  • Larry Lard

    #2
    Re: Help with C# to VB.Net ... Please


    Rob wrote:[color=blue]
    > 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(c hars[b % (chars.Length - 1)]); }
    >
    > My C# to Vb.Net routine converted the line above to be:
    >
    > result.Append(c hars(b % (chars.Length - 1)))
    >
    > But I am getting error "Character is not Valid" on the "%".
    >
    > Any help would be appreciated.[/color]

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

    --
    Larry Lard
    Replies to group please

    Comment

    • IdleBrain

      #3
      Re: Help with C# to VB.Net ... Please

      Try result.Append(c hars(b Mod (chars.Length - 1)))

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Help with C# to VB.Net ... Please

        "Rob" <rob_panosh@asd software.com> schrieb:[color=blue]
        >I am trying to convert the following C# routine (below) to Vb.Net.[/color]

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

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • David Anton

          #5
          RE: Help with C# to VB.Net ... Please

          result.Append(c hars(b Mod (chars.Length - 1)))
          --
          David Anton
          Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

          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:
          [color=blue]
          > 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(c hars[b % (chars.Length - 1)]); }
          >
          > My C# to Vb.Net routine converted the line above to be:
          >
          > result.Append(c hars(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 = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ1234567 890";
          > chars = a.ToCharArray() ;
          > int size = maxSize ;
          > byte[] data = new byte[1];
          > RNGCryptoServic eProvider crypto = new RNGCryptoServic eProvider();
          > crypto.GetNonZe roBytes(data) ;
          > size = maxSize ;
          > data = new byte[size];
          > crypto.GetNonZe roBytes(data);
          > StringBuilder result = new StringBuilder(s ize) ;
          > foreach(byte b in data )
          > { result.Append(c hars[b % (chars.Length - 1)]); }
          > return result.ToString ();
          > }
          >
          >[/color]

          Comment

          • Rob

            #6
            Re: Help with C# to VB.Net ... Please

            Everybody,

            Thanks for your help.

            Cheers,
            Rob

            Rob wrote:[color=blue]
            > 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(c hars[b % (chars.Length - 1)]); }
            >
            > My C# to Vb.Net routine converted the line above to be:
            >
            > result.Append(c hars(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 = "abcdefghijklmn opqrstuvwxyzABC DEFGHIJKLMNOPQR STUVWXYZ1234567 890";
            > chars = a.ToCharArray() ;
            > int size = maxSize ;
            > byte[] data = new byte[1];
            > RNGCryptoServic eProvider crypto = new RNGCryptoServic eProvider();
            > crypto.GetNonZe roBytes(data) ;
            > size = maxSize ;
            > data = new byte[size];
            > crypto.GetNonZe roBytes(data);
            > StringBuilder result = new StringBuilder(s ize) ;
            > foreach(byte b in data )
            > { result.Append(c hars[b % (chars.Length - 1)]); }
            > return result.ToString ();
            > }[/color]

            Comment

            Working...