Bytes conversion to string

Using an API Function and being returned array containing bytes

Example:

Expression      Value
szsize(0)        126
szsize(1)        88
szsize(2)        68
szsize(3)        65
szsize(4)        86
szsize(5)        48
szsize(6)        48
szsize(7)        50
szsize(8)        0

need to convert this into a string is there a function or if not an easy way to do this.
calisAsked:
Who is Participating?
 
deightonConnect With a Mentor Commented:

sString = ""
for c = 0 to 8

 sString = sString & chr(szsize(0))

next
0
 
deightonCommented:
the 0 represents end of c type string, so maybe you coulds use

sString=""
i = 0
while szsize(i) <> 0
 sString = sString & chr(szsize(0))
 i = i + 1
wend
0
 
deightonCommented:
oops!!

sString=""
                      i = 0
                      while szsize(i) <> 0
                       sString = sString & chr(szsize(i))
                       i = i + 1
                      wend


                       
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
caraf_gCommented:
Quicker....

Dim arrDbl() As byte

ReDim arrDbl(2*LBound(szsize) to 2*UBound(szsize))

Dim lngCounter as long

for lngCounter = lbound(szsize) to ubound(szsize)
    arrDbl(2*lngcounter) = szsize(lngcounter)
next

Dim strResult as string
strResult = arrDbl
0
 
caraf_gCommented:
(just checking)
Option Explicit

Private Sub Command1_Click()

Dim arr1() As Byte

ReDim arr1(0 To 5)
arr1(0) = Asc("H")
arr1(1) = Asc("e")
arr1(2) = Asc("l")
arr1(3) = Asc("l")
arr1(4) = Asc("o")
arr1(5) = 0

Dim arr2() As Byte
ReDim arr2(2 * LBound(arr1) To 2 * UBound(arr1))

Dim lngCounter As Long

For lngCounter = LBound(arr1) To UBound(arr1)
    arr2(2 * lngCounter) = arr1(lngCounter)
Next

Dim strResult As String

strResult = arr2

MsgBox strResult
MsgBox Len(strResult)

End Sub



Yep, it works..
0
 
Erick37Commented:
Dim cArray(260) As Byte
Dim sString As String
Dim lVal As Long
lVal = SendMessage(Me.hwnd, WM_GETTEXT, 255&, cArray(0))

sString = StrConv(cArray, vbUnicode)
sString = Left(sString, lVal)
Debug.Print sString
0
 
Erick37Commented:
Or:

sString = StrConv(cArray, vbUnicode)
sString = Left(sString, InStr(1, sString, vbNullChar) - 1)
0
 
mcriderCommented:
calis,

Go with Erick37's implementation of StrConv... Much quicker!

Cheers!
0
 
caraf_gCommented:
Never even thought of that one <doh>
0
 
mcriderCommented:
caraf_g, alot of people forget about the string conversion and subclassing routines...


Cheers!
0
All Courses

From novice to tech pro — start learning today.