LSet is a rather quirky statement in VB6: see description in the manual.
- When used on strings, it left-aligns the string in the original string and replaces any leftover characters with spaces.
- When used on user-defined types, it just copies the memory from one user-defined type over the other, even if they had different definitions. This is not recommended.
It's being used in a particularly quirky way in the code you have.
LSet instOfMyTypeBuffer.Buffer = ...
This is redundant both in the VB6 and the migrated Vb.Net. When you assign a new value to a fixed-length string, it always pads out with spaces anyway!
So just change to this (in either VB6 or VB.Net)
instOfMyTypeBuffer.Buffer = ...
LSet instOfMyType = instOfMyTypeBuffer
More interesting. This copies the memory from an instance of one type into an instance of another type, with no checks. Gulp!
Looking at the definitions of the types, I think this simply puts the first 15 characters from instOfMyBuffer
into instOfMyType.PROP1
and the remaining 25 characters into instOfMyType.PROP2
.
I have occasionally seen this used as an ugly way of processing fixed-length string records read from a file. For example the first fifteen characters might be a person's first name, and the next 25 the last name.
You could just replace with this code (in either VB6 or VB.Net).
instOfMyType.PROP1 = Left(instOfMyBuffer.Buffer, 15)
instOfMyType.PROP2 = Mid(instOfMyBuffer.Buffer, 16)
Hans suggested ditching the fixed-length strings. If that's easy - and it depends on the rest of your code base, it might be easy, or it might be hard - it's good advice.