VBA: What is causing this string argument passed to ParamArray to get changed to a number (that looks suspiciously like a pointer)?

拟墨画扇 提交于 2019-11-30 05:19:29

Now this is awesome.

Reproduced on office 2003.
Looks like a compiler bug.

The problem is in this line:

Call c.strange("", v(LBound(v)))

Here the compiler creates a Variant that holds a 1D array of Variant's, the only element of which is a pointer instead of the value. This pointer then goes to the strange function which actually is not strange, it only prints the Variant\Long value passed to it.

This trick brings the compiler sanity back:

Call c.strange("", (v(LBound(v))))

EDIT

Yes, this magic number is a pointer to the VARIANT structure which is supposed to be passed to the strange method. The first field of which is 8, which is vbString, and the data field contains a pointer to the actual string "a".

Therefore, it is definitely a compiler bug... Yet another VB compiler bug in regard of arrays ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!