Hi All,

I am trying to store the message id/correlation id from a MSMQ message
into a database table but am having trouble doing so as the data type
of the message id is of type Variant (array of bytes).

In VBScript how can I convert this data type in order to store as a
varchar in
a SQL Server 2000 db table?

When I run the code (from Michael Harris),where sMsgId is the array of
bytes for an MSMQ message Id, I get
=F2c=B3=8B=AEvG=80O^=F0"=F40=FF back as my character string:

ChrString =3D ""
NumValues =3D ""
HexValues =3D ""
comma =3D ""
for n =3D 0 to ubound(sMsgId)


ChrString =3D ChrString _
& midb(sMsgId,n+1,1) & chrb(0)


NumValues =3D NumValues & comma _
& asc(midb(sMsgId,n+1,1) & chrb(0))
HexValues =3D HexValues & comma _
& "0x" & hex(asc(midb(sMsgId,n+1,1) & chrb(0)))
comma =3D ","
next
msgbox "Typename: " & typename(sMsgId) & vbcrlf _
& "Vartype: " & vartype(sMsgId) & vbcrlf _
& "ChrString: " & ChrString & vbcrlf _
& "NumValues: " & NumValues & vbcrlf _
& "HexValues: " & HexValues & vbcrlf


-------------------------------------------


I also tried and get the same result:


For j =3D 1 To Lenb(sMsgId)
sMessageId =3D sMessageId & Chr(AscB(MidB(sMsgId, j)))
Next=20


Thanks for any help
Patrick

Re: Converting an array of bytes to a string (VBScript) by Richard

Richard
Mon Mar 13 15:13:06 CST 2006

Hi,

I use this function:

Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.

Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function

If the value is one byte array, TypeName returns Byte(). If the value is an
array, even an array of byte arrays, TypeName returns Variant(). I hope this
helps.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<patrickwmurray@gmail.com> wrote in message
news:1142269499.271040.115640@u72g2000cwu.googlegroups.com...

Hi All,

I am trying to store the message id/correlation id from a MSMQ message
into a database table but am having trouble doing so as the data type
of the message id is of type Variant (array of bytes).

In VBScript how can I convert this data type in order to store as a
varchar in
a SQL Server 2000 db table?

When I run the code (from Michael Harris),where sMsgId is the array of
bytes for an MSMQ message Id, I get
òc³<®vG?O^ð"ô0ÿ back as my character string:

ChrString = ""
NumValues = ""
HexValues = ""
comma = ""
for n = 0 to ubound(sMsgId)


ChrString = ChrString _
& midb(sMsgId,n+1,1) & chrb(0)


NumValues = NumValues & comma _
& asc(midb(sMsgId,n+1,1) & chrb(0))
HexValues = HexValues & comma _
& "0x" & hex(asc(midb(sMsgId,n+1,1) & chrb(0)))
comma = ","
next
msgbox "Typename: " & typename(sMsgId) & vbcrlf _
& "Vartype: " & vartype(sMsgId) & vbcrlf _
& "ChrString: " & ChrString & vbcrlf _
& "NumValues: " & NumValues & vbcrlf _
& "HexValues: " & HexValues & vbcrlf


-------------------------------------------


I also tried and get the same result:


For j = 1 To Lenb(sMsgId)
sMessageId = sMessageId & Chr(AscB(MidB(sMsgId, j)))
Next


Thanks for any help
Patrick



Re: Converting an array of bytes to a string (VBScript) by patrickwmurray

patrickwmurray
Tue Mar 14 17:45:40 CST 2006

Thanks this worked