VBA 字符串限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10927764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA String Limit
提问by riaandl
I've been working in Visual Basic for Applications (VBA) in Microstation V8i SS2, and I'm getting an Overflow error for my String value.
我一直在 Microstation V8i SS2 中的 Visual Basic for Applications (VBA) 中工作,我的 String 值出现溢出错误。
It seems there is a limit in VBA for String values. The limit seems to be 255 characters. Reading up on it, a lot of sources says it can support up to 2 billion characters. This is not true?
VBA 中似乎对 String 值有限制。限制似乎是 255 个字符。阅读它,很多消息来源说它可以支持多达 20 亿个字符。这不是真的?
What happens is, I'm using ADO to interact with the database, so I'm building my own SQL INSERT statement inside the VBA. The INSERT statement gets long, like 300+ characters, depending on the 'Comments' column that accepts a multi-line text value.
发生的情况是,我使用 ADO 与数据库进行交互,因此我正在 VBA 中构建自己的 SQL INSERT 语句。INSERT 语句变得很长,比如 300+ 个字符,这取决于接受多行文本值的“评论”列。
Anybody have a solution? Should I write my own COM-Addin from a .NET point of view, that gets referenced in the VBA?
有人有解决方案吗?我应该从 .NET 的角度编写自己的 COM-Addin,在 VBA 中引用吗?
回答by Mitch Wheat
VBA strings can be more than 255 chars.
VBA 字符串可以超过 255 个字符。
A possible culprit is how the column is declared in your table.... Is the Comments
column declared as varchar(255)
?
一个可能的罪魁祸首是列是如何在您的表中声明的......Comments
列是否声明为varchar(255)
?
From the help file:
从帮助文件:
A variable-length string can contain up to approximately 2 billion (2^31) characters.
A fixed-length string can contain 1 to approximately 64K (2^16) characters.
可变长度字符串最多可以包含大约 20 亿 (2^31) 个字符。
固定长度的字符串可以包含 1 到大约 64K (2^16) 个字符。
Ref.
参考。