Array question

jimmay
01-06-2008, 01:23 AM
Been a while since i did vb6 stuff

with a string array, is it possible to show the whole array at once?
ie:

Dim j(2) as string

j(0) = "h"
j(1) = "e"
j(3) = "y"

msgbox j

Yields an error, but i would like it to show "hey" - also, this is an inefficient way, as i assume each element of the array might be occupying the amount of memory a string does. any such way to do a character? Maybe byte?

jimmay
01-06-2008, 01:30 AM
Dim arra(2) As Byte

arra(0) = 97
arra(1) = 98
arra(2) = 99

Dim i As String

Dim k As Integer


For k = 0 To UBound(arra)
i = i & Chr(arra(k))
Next k

MsgBox i


Thats the best way i can think of it. any suggestions?

Rockoon
01-06-2008, 02:16 AM
See the join() function.

the master
01-06-2008, 05:14 AM
You can also put data into the array a little easier too.


arra(0) = asc("a")
arra(1) = asc("b")
arra(2) = asc("c")


Or event better

dim temp as string
Dim arra() As Byte
temp="this is your text"
arra()=strconv(temp,vbfromunicode)


I actually get an error when using the join() function to put it all back together though. The following code joins it together with no errors.

msgbox strconv(arra(),vbunicode)

Rockoon
01-06-2008, 06:29 AM
..because you are using bytes, not strings.

the master
01-06-2008, 06:34 AM
Ahh yes. He changed to bytes in his second post. Join will work perfect on the origional post

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum