Structure member offset

Is there a way to access the offset of a structure member programmatically?

curious why you need that as there may be a different way to achieve what it is you’re trying to do

Probably not worth it to explain. Just simplifies some things if I change my structure layout in the future.

I probably should be using a Class anyway.

If you’re not interfacing via a Declare, you probably should be using a class. Unless you’re writing a bytecode interpreter like I was / am in which case you might want to pass things around on the stack rather than the heap.

Ok, still curious, just for the sake of learning.

Sometimes I’ll have part of a structure that’s filled with bytes.
I’d like to read back that section sometimes as bytes, sometimes as characters.

Structure MyStruct ' No idea how to define in code, I just use the Structure editor
b(4) as byte
w(4) as UInt16
End Structure

Of course, I can just use MyStruct.StringValue(0, MyStruct.b.Size) function, but it needs to know where to start. It’s 0 in this case, but if I add another field ahead of “b”, then it’s wrong.

FYI, you can only create a Structure with the structure editor.

What is your use case here? A class really would give you more flexibility…

Yeah, you’re right. A class would be a better way to go, but I’d like to see what structures have to offer too. So many of the devices I interface with use structure-based packets.

You need to read this one then
define two dfferent structs and use them like overlays

1 Like

Great stuff. Been away from pointers for so long (VB.NET discourages their direct use), but I need to get back to them. They are hella useful.