VBA意外达到字符串大小限制 [英] VBA unexpected reach of string size limit

查看:162
本文介绍了VBA意外达到字符串大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim MyData As String 
MyData =空格$(321262258)

字符数明显低于2 ^ 31预期限制。可能是这样的错误的原因?



感谢您的帮助!

解决方案

这似乎是一个有点不透明的错误 - 不透明的,它需要详细了解VBA解释器的内部结构来回答。 MSDN说出这个错误:


Visual Basic允许你使用非常大的字符串。但是,其他程序的要求和操作字符串的方式可能会导致此错误。


https://msdn.microsoft.com/en-us/library/aa264524(v = vs60).aspx



我在文档中找不到任何对于许多内置函数(如Space()或String())以及连接操作符(如+或& ,但这些限制似乎存在。在内存中的字符串的最大可能大小(从文本文件中读取)与可由内置VBA函数和运算符构建的字符串的最大可能大小之间似乎存在差异。奇。如果有人知道一个可以在纯VBA中构建空格$(321262258)甚至空格(2 ^ 31 -1)正在构造的字符串的kludge,我会感兴趣。


I am facing an "out of string space" error while trying to assign large strings in vba:

Dim MyData As String
MyData = Space$(321262258)

The number of characters is clearly under 2^31 expected limit. What could be the reason of such an error ?

Thanks for your help !

解决方案

This seems to be a somewhat opaque error -- opaque in the sense that it would require detailed understanding of the internals of the VBA interpreter to answer. MSDN says about this error:

Visual Basic permits you to use very large strings. However, the requirements of other programs and the way you manipulate your strings may cause this error.

https://msdn.microsoft.com/en-us/library/aa264524(v=vs.60).aspx

I can't find anything in the documentation which suggests a limit of around 2^27 for many built-in functions such as Space() or String(), as well as concatenation operators like + or &, but these limits seem to exist. There seems to be a poorly documented discrepancy between the maximum possible size of a string in memory (say read in from a text file) and the maximum possible size of string which can be built up from built-in VBA functions and operators. Odd. I would be interested if anyone knows of a kludge which can in pure VBA construct the string which Space$(321262258) or even Space(2^31 -1 ) is trying to construct.

这篇关于VBA意外达到字符串大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆