09-04-2003, 06:19 PM
Im trying to 'translate' some delphi code i have into vb, its pretty easy because its mostly just calling API. But in some of the calls, they use the SizeOf() function, and that stopped me from getting it all. As far as i know, there is no vb equilivant to it, so i was hoping someone could explain it to me so i can create my own code or give me some code :)
I think there is a SizeOf() in C++ also...
09-04-2003, 06:31 PM
It depends on what you want the size of? The LenB() function gives
pretty accurate sizes for most datatypes.
09-04-2003, 07:17 PM
yah, i wanted the size of the data type. Ill give that LenB a try!
I've always used Len(). LenB() and Len() differ mostly between strings. Strings in VB are unicode based and are stored as 2 bytes per character. If you are expecting the length of the string to be per character, use Len(). Otherwise, LenB() should work fine.
09-04-2003, 09:11 PM
Actually LenB() will show the true number of bytes being used in a UDT
that isn't packed on 4 byte boundries too. The real question is, if trying
to pass one of these types to some API function that needs to know
exactly how long it is, which should we use? The one that shows how
many bytes it would take if the data was just stuck in a file, or the one
that shows how many bytes VB has allocated to hold it.
On that note, if you use strings in api calls, you need to use Len() most of the time, depending on the calling convention. VB will convert the internal BSTR to a char* depending on whether you pass ByRef or ByVal. It tends to get tricky sometimes, especially with RTLMoveMemory() calls. Sometimes you have to use ByRef and sometimes you have to use ByVal. Be careful which you use there. I've had a hard time in the past deciphering what I need for what situation.