1

I'm trying to understand the official Microsoft VBA documentation for the LSet statement, specifically this warning in the example section:

Due to the varying implementations of data structures among platforms, such a use of LSet can't be guaranteed to be portable.

Source: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/lset-statement

Question: What specifically does "platforms" refer to in this context? My assumption is that "platforms" refers to either:

  • Different operating system versions (Windows 7, Windows 10, Windows 11, etc.)
  • Different CPU architectures (x86, x64, ARM, etc.)
  • Or possibly both

What I've tried:

However, I cannot find any official Microsoft documentation that explicitly defines what "platforms" means in this VBA context.

  • Searched through Microsoft's VBA documentation
  • Asked AI assistants, but received unclear answers
  • Looked for clarification in related MSDN articles

The context suggests it's related to data structure implementation differences that could affect the portability of using LSet to copy between different user-defined types, but I need confirmation of what specific platform differences are being referenced. Can anyone point me to official documentation or provide authoritative clarification on what "platforms" means in this VBA warning?

9
  • 3
    “Platforms” refers to the different operating systems or environments where VBA might be executed... such as Windows or macOS. Commented Aug 23 at 6:16
  • 1
    When Microsoft says “platforms” in the LSet docs, they are really talking about the different environments where VBA can run. That covers things like the operating system (Windows or Mac), the specific Office host (Excel, Word, Access), and the version or bitness of VBA itself (32-bit, 64-bit, VBA 6, VBA 7). Each of these factors can influence how user-defined types (UDTs) are stored in memory, how fields are aligned, and whether padding is inserted. CONTD... Commented Aug 23 at 6:33
  • 1
    Because of these variations, LSet is not a safe way to copy one UDT into another if you want the code to work everywhere. LSet just moves raw bytes around, ignoring type safety. If the memory layout differs between platforms, you can end up with corrupted values or misinterpreted data. For example, differences in pointer size, alignment rules, or string storage (Unicode vs ANSI) can cause code that runs fine on one system to break on another. That is why the warning exists. Commented Aug 23 at 6:33
  • 1
    I would like to check difference of environments in several computers. So, I need some script to check it. If you type this in ChatGpt or CoPilot, it can spit out an entire set of script for you. I just tried it and it worked. I would recommend giving it a try and then if you do not understand anything in that script then, post the script here with your understanding and we can help you figure it out... Commented Aug 23 at 6:42
  • 1
    @OEOptionExplicit The answer is not binary i.e. safe or unsafe. As was mentioned in the previous comments, there can be padding and alignment issues. But those can be "fixed" by having manual padding that you add yourself to the UDTs so that they are aligned regardless of "platform". For example if you have an Integer followed by a Double you might get an 8-byte alignment on x64 i.e. 6-byte padding but that might look different on x32 e.g. 4-byte alignment (2-byte padding) - but you can just insert 3 dummy Integers in between the two. In short, it depends on the use case. Commented Sep 12 at 15:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.