Character array in Visual Basic 6.0

vb6

Consider:

char [] chararray = txt1.Text;

How we do the same in Visual Basic 6.0?

Best Answer

That depends on what you eventually want to do.

You can, for example, do this in VB6:

Dim b() As Byte
b = Text1.Text

That way the b array will be resized to hold the Unicode data from "string" -- but then each character will be split across two bytes which is probably not what you want. This trick only works with Byte.


You also can do that:

Dim b() As Byte
b = StrConv(Text1.Text, vbFromUnicode)

Each letter will now occupy one byte, but the extended characters will be gone. Only do this if the current system code page contains the required characters.


You can copy the characters manually to an array:

Dim s() As String, i As Long
ReDim s(1 To Len(Text1.Text))

For i = 1 To UBound(s)
  s(i) = Mid$(Text1.Text, i, 1)
Next

Or you can even avoid creating an array at all, becase Mid also serves as an indexer operator that changes a character in place, without copying or allocating anything:

Dim s As String
s = Text1.Text

Mid$(s, 3, 1) = "!"
Related Topic