Trouble defining a bytearray!!

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

    Trouble defining a bytearray!!

    Hello,
    I am having trouble defining a byte array in .Net


    When i go this route it doesnt like the [] definition
    Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48", "0x9d",
    "0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
    "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}



    When I go this route

    Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17", "0x22",
    " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96", "0x65", "0xc2",
    "0x2d", "0x0c", "0x67", " 0xc7"}

    It gives me a run-time error Input string was not in a correct format.



    Running out of ideas..dont see any other definitons anywhere.



    TIA,

    HS






  • Armin Zingler

    #2
    Re: Trouble defining a bytearray!!

    "Harold S" <hsoans@grange. com> schrieb[color=blue]
    > Hello,
    > I am having trouble defining a byte array in .Net
    >
    >
    > When i go this route it doesnt like the [] definition
    > Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48",
    > "0x9d", "0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f",
    > "0x5c", " 0x96", "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}
    >
    >
    >
    > When I go this route
    >
    > Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17",
    > "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
    > "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}
    >
    > It gives me a run-time error Input string was not in a correct
    > format.[/color]

    Run-time error? I can not even compile the code. Forgot to enable Option
    Strict? Why assign strings to the array? Use numeric values:

    Dim xxx() As Byte = {&H45, &h70,&H22, &H48}


    --
    Armin

    Comment

    • Harold Soans

      #3
      Re: Trouble defining a bytearray!!



      Thanks Armin...I will give that a try!!
      On an added note is there a site where i can find numeric equivalents
      eg: for 0x300

      Thanks a lot again!
      Harry!

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Armin Zingler

        #4
        Re: Trouble defining a bytearray!!

        "Harold Soans" <hsoans@yahoo.c om> schrieb[color=blue]
        >
        >
        > Thanks Armin...I will give that a try!!
        > On an added note is there a site where i can find numeric
        > equivalents eg: for 0x300[/color]

        site? 3 * 256 = 768
        You can use calc.exe.
        or: msgbox(val("&H3 00"))
        or: msgbox(convert. toint32("300",1 6))


        --
        Armin

        How to quote and why:



        Comment

        • Sven Groot

          #5
          Re: Trouble defining a bytearray!!

          Harold S wrote:[color=blue]
          > Hello,
          > I am having trouble defining a byte array in .Net
          >
          >
          > When i go this route it doesnt like the [] definition
          > Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48", "0x9d",
          > "0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", "
          > 0x96", "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}[/color]

          [] is for C, C++, C#, and certain languages whose name starts with J.
          [color=blue]
          > When I go this route
          >
          > Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17",
          > "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
          > "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}[/color]

          That's the correct way of doing it, only you are assigning Strings to a Byte
          array. Naturally, it can't cast a String to a Byte. Assign it numbers
          instead.
          0x is the prefix for hex in C etc., in Visual Basic it's &H.
          So your code would become:

          Dim xxx() As Byte = {&H45, &H70, &H22, &H48, &H9D, &H17, _
          &H22, &H11, &H7F, &H96, &H5F, &H8F, &H5C, &H96, _
          &H65, &HC2, &H2D, &HC, &H67, &HC7}

          --
          Sven Groot


          Comment

          Working...