2009-08-17 26 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