tags:

views:

116

answers:

3
+1  A: 

10240 bytes* or characters*?

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

(* = VB6 strings are unicode, so each character in a string takes 2 bytes)

KristoferA - Huagati.com
This gives me a compiler error, what am I missing?
Binary Worrier
A star. Dim strFoo As String*5120
MarkJ
Heh, MarkJ is right, my memory failed me... Corrected.
KristoferA - Huagati.com
+2  A: 

Try

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

This will ensure the string is ALWAYS 5120 characters, if there are less in there, it will be padded with spaces. e.g.

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

gives

[Hello     ]
Binary Worrier
A: 

This is the syntax for a fixed-length string of 5120 characters, which is 10240 bytes. The value will always have 5120 characters - trailing spaces will be added, or excess characters truncated. VB6 strings are Unicode (UTF-16) and therefore each character has 2 bytes.

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

It's not clear whether you are dealing with binary data rather than text. The Byte data type is better for binary data.

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