Compile error help byte array

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

    Compile error help byte array

    Hello,
    I have the following code:
    background:
    const int MAX_DATA_BYTES= 250;
    byte[] blkin =new byte[MAX_DATA_BYTES]; /* Receive buffer */

    and I use it in the following:
    memmove(blkout[1], blkout[0], len);

    but i get the following error:
    Cannot apply indexing with [] to an expression of type 'byte'

    What am i doing wrong?
    Thanks
    mike

  • AMP

    #2
    Re: Compile error help byte array

    Actually I changed memmove to ARRAY.COPY. (Sorry, Im porting a c
    program to c#)
    AMP wrote:
    Hello,
    I have the following code:
    background:
    const int MAX_DATA_BYTES= 250;
    byte[] blkin =new byte[MAX_DATA_BYTES]; /* Receive buffer */
    >
    and I use it in the following:
    memmove(blkout[1], blkout[0], len);
    >
    but i get the following error:
    Cannot apply indexing with [] to an expression of type 'byte'
    >
    What am i doing wrong?
    Thanks
    mike

    Comment

    • AMP

      #3
      Re: Compile error help byte array- Modified

      Let me rewrite this:
      Hello,
      I have the following code:
      background:
      const int MAX_DATA_BYTES= 250;
      byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */

      and I use it in the following:
      ARRAY.COPY(blko ut[1], blkout[0], len);

      but i get the following error:
      Cannot apply indexing with [] to an expression of type 'byte'

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Compile error help byte array

        Mike,

        You are showing the declaration for the blkin variable, but your call on
        the indexer is for the blkout variable. I would take a look at that.

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "AMP" <ampeloso@gmail .comwrote in message
        news:1157902567 .207678.114620@ i3g2000cwc.goog legroups.com...
        Hello,
        I have the following code:
        background:
        const int MAX_DATA_BYTES= 250;
        byte[] blkin =new byte[MAX_DATA_BYTES]; /* Receive buffer */
        >
        and I use it in the following:
        memmove(blkout[1], blkout[0], len);
        >
        but i get the following error:
        Cannot apply indexing with [] to an expression of type 'byte'
        >
        What am i doing wrong?
        Thanks
        mike
        >

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Compile error help byte array- Modified

          Take a look at the Buffer.BlockCop y method for this.

          Willy.

          "AMP" <ampeloso@gmail .comwrote in message
          news:1157904894 .095943.83180@p 79g2000cwp.goog legroups.com...
          | Let me rewrite this:
          | Hello,
          | I have the following code:
          | background:
          | const int MAX_DATA_BYTES= 250;
          | byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */
          |
          | and I use it in the following:
          | ARRAY.COPY(blko ut[1], blkout[0], len);
          |
          | but i get the following error:
          | Cannot apply indexing with [] to an expression of type 'byte'
          |


          Comment

          • AMP

            #6
            Re: Compile error help byte array- Modified

            Still not getting anywhere.
            I need some help.Please
            Thanks
            Mike


            Willy Denoyette [MVP] wrote:
            Take a look at the Buffer.BlockCop y method for this.
            >
            Willy.
            >
            "AMP" <ampeloso@gmail .comwrote in message
            news:1157904894 .095943.83180@p 79g2000cwp.goog legroups.com...
            | Let me rewrite this:
            | Hello,
            | I have the following code:
            | background:
            | const int MAX_DATA_BYTES= 250;
            | byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */
            |
            | and I use it in the following:
            | ARRAY.COPY(blko ut[1], blkout[0], len);
            |
            | but i get the following error:
            | Cannot apply indexing with [] to an expression of type 'byte'
            |

            Comment

            • Willy Denoyette [MVP]

              #7
              Re: Compile error help byte array- Modified


              "AMP" <ampeloso@gmail .comwrote in message
              news:1157917907 .969618.171290@ i3g2000cwc.goog legroups.com...
              | Still not getting anywhere.
              | I need some help.Please
              | Thanks
              | Mike
              |

              What problem do you have using BlockCopy? Please post what you have done so
              far.

              Here's a usage sample:
              byte[] arr1 = {1, 2, 3, 4, 5};
              byte[] arr2 = {10, 11, 12, 13, 14, 15};
              // copy 5 bytes from arr1 starting at offset 0 to arr2 starting at offset 1
              Buffer.BlockCop y( arr1, 0, arr2, 1, 5);
              // result: arr2 = 10, 1, 2, 3, 4, 5

              Willy.



              Comment

              • Rudy Velthuis

                #8
                Re: Compile error help byte array- Modified

                At 18:14:54, 10.09.2006, AMP wrote:
                Let me rewrite this:
                Hello,
                I have the following code:
                background:
                const int MAX_DATA_BYTES= 250;
                byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */
                >
                and I use it in the following:
                ARRAY.COPY(blko ut[1], blkout[0], len);
                Array.Copy has a different parameter set. Assuming the original C code
                was:

                memmove(blkout + 1, blkout, len);

                or:

                memmove(&blkout[1], &blkout[0], len);

                then try this:

                Array.Copy(blko ut, 0, blkout, 1, len);

                Where blkout[0] is the source and blkout[1] is the destination.

                --
                Rudy Velthuis http://rvelthuis.de/

                "If you're sick and tired of the politics of cynicism and polls
                and principles, come and join this campaign." -- George W. Bush

                Comment

                • AMP

                  #9
                  Re: Compile error help byte array- Modified

                  Yes the original code was:
                  memmove(&blkout[1], &blkout[0], len);

                  so why doesnt my code work??????????? ?

                  const int MAX_DATA_BYTES= 250;
                  byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
                  Array.Copy(blko ut,1, blkout,0, len);

                  what i'm getting now is:
                  Error 10 Argument '1': cannot convert from 'byte' to
                  'System.Array' M:\Rocket-CSharp\Rocket\R ocket\Form1.cs 466 20 Rocket
                  And
                  Error 11 Argument '3': cannot convert from 'byte' to
                  'System.Array' M:\Rocket-CSharp\Rocket\R ocket\Form1.cs 466 30 Rocket

                  And the next line in the program is:
                  blkout[0]= 0xFF;
                  and i get the error:

                  Error 12 Cannot apply indexing with [] to an expression of type
                  'byte' M:\Rocket-CSharp\Rocket\R ocket\Form1.cs 467 9 Rocket




                  I dont get it.............

                  Thanks Again
                  Mike





                  Rudy Velthuis wrote:
                  At 18:14:54, 10.09.2006, AMP wrote:
                  >
                  Let me rewrite this:
                  Hello,
                  I have the following code:
                  background:
                  const int MAX_DATA_BYTES= 250;
                  byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */

                  and I use it in the following:
                  ARRAY.COPY(blko ut[1], blkout[0], len);
                  >
                  Array.Copy has a different parameter set. Assuming the original C code
                  was:
                  >
                  memmove(blkout + 1, blkout, len);
                  >
                  or:
                  >
                  memmove(&blkout[1], &blkout[0], len);
                  >
                  then try this:
                  >
                  Array.Copy(blko ut, 0, blkout, 1, len);
                  >
                  Where blkout[0] is the source and blkout[1] is the destination.
                  >
                  --
                  Rudy Velthuis http://rvelthuis.de/
                  >
                  "If you're sick and tired of the politics of cynicism and polls
                  and principles, come and join this campaign." -- George W. Bush

                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: Compile error help byte array- Modified

                    AMP <ampeloso@gmail .comwrote:
                    Yes the original code was:
                    memmove(&blkout[1], &blkout[0], len);
                    >
                    so why doesnt my code work??????????? ?
                    >
                    const int MAX_DATA_BYTES= 250;
                    byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
                    Array.Copy(blko ut,1, blkout,0, len);
                    The above code compiles fine. The problem was when you were using

                    blkout[1] or blkout[0], which each evaluate to a byte value, not a byte
                    array.

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                    If replying to the group, please do not mail me too

                    Comment

                    • AMP

                      #11
                      Re: Compile error help byte array- Modified

                      I managed to fix that one,(Many Thanks) but I have one that looks like
                      this:
                      memcpy(&dataOut[4], blkout, len)

                      The "blkout" has no index.
                      Any Suggestions?



                      Jon wrote:
                      AMP <ampeloso@gmail .comwrote:
                      Yes the original code was:
                      memmove(&blkout[1], &blkout[0], len);

                      so why doesnt my code work??????????? ?

                      const int MAX_DATA_BYTES= 250;
                      byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
                      Array.Copy(blko ut,1, blkout,0, len);
                      >
                      The above code compiles fine. The problem was when you were using
                      >
                      blkout[1] or blkout[0], which each evaluate to a byte value, not a byte
                      array.
                      >
                      --
                      Jon Skeet - <skeet@pobox.co m>
                      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                      If replying to the group, please do not mail me too

                      Comment

                      • Jon Skeet [C# MVP]

                        #12
                        Re: Compile error help byte array- Modified

                        AMP wrote:
                        I managed to fix that one,(Many Thanks) but I have one that looks like
                        this:
                        memcpy(&dataOut[4], blkout, len)
                        >
                        The "blkout" has no index.
                        Any Suggestions?
                        That's basically

                        Array.Copy (dataOut, 4, blkout, 0, len);

                        (or possibly the other way round - I can't remember which way round the
                        arguments go in memcpy).

                        Jon

                        Comment

                        • Arne Vajhøj

                          #13
                          Re: Compile error help byte array- Modified

                          Jon Skeet [C# MVP] wrote:
                          AMP wrote:
                          >I managed to fix that one,(Many Thanks) but I have one that looks like
                          >this:
                          >memcpy(&dataOu t[4], blkout, len)
                          >>
                          >The "blkout" has no index.
                          >Any Suggestions?
                          >
                          That's basically
                          >
                          Array.Copy (dataOut, 4, blkout, 0, len);
                          >
                          (or possibly the other way round - I can't remember which way round the
                          arguments go in memcpy).
                          memcpy is <- !

                          Arne

                          Comment

                          Working...