2009-08-17 27 views
0

可能重复:
How to declare variable containing character limiting to 1000 bytes in vb6
“Object variable or With block variable not set” runtime error in VB6限制vbstring的10240个字节的大小在VB6

确切的重复提问者的自己的问题How to declare variable containing character limiting to 1000 bytes in vb6

如何declarare大小字符串变量为10240在VB6中的butes?

+0

这不是你刚才问的那个问题吗? http://stackoverflow.com/questions/1286476/how-to-declare-variable-containing-character-limiting-to-1000-bytes-in-vb6 – 2009-08-17 08:29:16

回答

1

10240字节*或字符*?

Dim strFoo As String * 5120 // 10240 bytes 
Dim strFoo As String * 10240 // 10240 characters 

(* = VB6字符串是unicode的,所以在一个串中的每个字符占用2个字节)

+0

这给了我一个编译器错误,我错过了什么? – 2009-08-17 08:26:44

+0

明星。 Dim strFoo As String * 5120 – MarkJ 2009-08-17 08:38:28

+0

呃,MarkJ是对的,我的记忆失败了......纠正了。 – KristoferA 2009-08-17 09:40:38

2

尝试

Dim s As String * 5120 
' Gives 10240 bytes, as pointed out by KristoferA 

这将确保的字符串是ALWAYS 5120个字符,如果存在在那里少一些,它将被填充空格。例如

Dim s As String * 10 
s = "Hello" 
Debug.Print "[" & s & "]" 

给出

[Hello  ] 
0

这是5120个字符的固定长度字符串,这是10240个字节的语法。该值将始终有5120个字符 - 将添加尾随空格或截断多余字符。 VB6 stringsUnicode(UTF-16),因此每个字符都有2个字节。

Dim s As String * 5120 ' 5120 characters, 10240 bytes 

目前还不清楚您是处理二进制数据而不是文本。数据类型对于二进制数据更好。

Dim byt(10240) as Byte ' an array of 10240 bytes