ChrB Question

Hello… I have been using ChrB alot for converting integers into a binary strings (one byte at a time) and have a question. ChrB only converts one byte at a time ( ChrB(255) = 0xFF). I am looking for a cheat on bigger bytes. Say 0x11FF (two bytes instead of one). I couldn’t find a method to do this and I have no problem using ChrB, but I figured I’d check before writing more code. :slight_smile:

Thanks in advance!

If there isn’t I have used a computed property to basically “add” 1 byte at a time and (Get) return the total byte string of 2 Bytes (or more).

Why not use a MemoryBlock and do it in shot with StringValue?

If you post your current code, we can see how to rewrite it around a MemoryBlock, if we can.

Thanks Kem. I haven’t used memory blocks yet and wondered when I would get into that :slight_smile:

This is my computed property:

Preamble is a string computed property Dim Calulate_2Bytes as String = ChrB(17) + ChrB(255) return Calulate_2Bytes

Here is part of my method that uses the computed properties:

Dim NewFrame as String = Preamble + SOF + ProtocolVer + ChrB(ICP_ID)

Ah well if its a computed property like this that NEVER changes why not

static Calculate2Bytes as String
if Calculate2Bytes = "" then
   Calculate2Bytes = ChrB(17) + ChrB(255)
end if
return Calculate2Bytes

at least then you only do this once

Oh. In this case, I would just declare Calulate_2Bytes as static to make a pseudo-constant.

Did you mean “Calculate_2Bytes”, btw?

static Calulate_2Bytes as string = ChrB( 17 ) + ChrB( 255 )
return Calulate_2Bytes

The next question is, are each parts of your frame a fixed size? If so, a Structure might help you here.

Yes all my headers have a fixed size byte count.

Then why not set up a Structure that you can reuse?

Kem I was setting up a structure which is how I ran into the original question about converting more than one byte at a time. My code above was test code since I just designed the rfc like protocol specs. Thanks again for your help guys!! The validation helps tremendously!