tvanstiphout
Active member
- Local time
- Today, 10:55
- Joined
- Jan 22, 2016
- Messages
- 539
(cross-posted in Access MVP email list)
Environment: A365-32.
Some variables have a VarType of vbString (8) and I can pass them to a function that takes a Byte array as argument, and some have the same VarType value and trying to pass those gets a compile error: Type mismatch: array or user-defined type expected.
What explains this difference? Apparently VarType does not confer enough information about the finer points of the String variable, e.g. whether it is convertible to a Byte array or not.
In the attached example I have a table with an AutoNumber that is a Replication ID. We know this is a 16-byte number typically written as a GUID for human consumption.
We’re trying to dump the bytes of such value to the Immediate window.
See procedure testReplicationId.
Dumping the Ascii characters (more accurately, the Unicode characters) can be shown to dump the correct 2-byte values. E.g. the first value is -622 Decimal which is equal to FD92 Hex (the first 2 bytes from DumpBytes) minus 2^16. So far so good.
As you can see from the commented-out line:
'DumpBytes s
I cannot pass that string to the ByRef b() As Byte argument of DumpBytes. A compile error would occur.
Now run testReplicationId, and observer that when I print the VarType of string s, or the DLookup result, or the StringFromGUID result, each reports vbString.
However, only the DLookup and the StringFromGUID result can be passed to DumpBytes.
My questions are:
-Tom.
Environment: A365-32.
Some variables have a VarType of vbString (8) and I can pass them to a function that takes a Byte array as argument, and some have the same VarType value and trying to pass those gets a compile error: Type mismatch: array or user-defined type expected.
What explains this difference? Apparently VarType does not confer enough information about the finer points of the String variable, e.g. whether it is convertible to a Byte array or not.
In the attached example I have a table with an AutoNumber that is a Replication ID. We know this is a 16-byte number typically written as a GUID for human consumption.
We’re trying to dump the bytes of such value to the Immediate window.
See procedure testReplicationId.
Dumping the Ascii characters (more accurately, the Unicode characters) can be shown to dump the correct 2-byte values. E.g. the first value is -622 Decimal which is equal to FD92 Hex (the first 2 bytes from DumpBytes) minus 2^16. So far so good.
As you can see from the commented-out line:
'DumpBytes s
I cannot pass that string to the ByRef b() As Byte argument of DumpBytes. A compile error would occur.
Now run testReplicationId, and observer that when I print the VarType of string s, or the DLookup result, or the StringFromGUID result, each reports vbString.
However, only the DLookup and the StringFromGUID result can be passed to DumpBytes.
My questions are:
- Why is that?
- Is there some way to distinguish between these strings?
-Tom.