everymn
Wed Feb 28 02:03:03 CST 2007
Richard,
Interesting idea. I'm a bit confused by this though. Why is it
called hex conversion? It's taking plain text as input right?
adoStream.Type = 2 is adTypeText. Is text stored as a hex array?
Although the stream converson is a handy idea, I'm not sure how I'd go
about getting it into fld.Value? I took a leap and tried a direct
assignment which went nowhere.
Also out of curiousity what am I ending up with when I do this in
VBscript?
Dim strBin, b, arrBin(7)
strBin = "bintest"
For b = 0 To 6
arrBin(b) = Asc(Mid(strBin, b+1, 1))
Next
Have I not created an array of bytes? I can read them in, I can read
them out. I just can't seem to assign it to fld.Value, when that
property happens to be a byte array. I gather an array of bytes is
fundamentally different from a byte array.
Just thinking out loud but is there a way I can compile something in
VB6 that I could call from VBscript to help me with this bit? These
binary fields are part of a much larger record so I'd need some way to
pass the record into VB and then get it back into script.
Thanks
Eric
>One technique suggested by Paul Randall works in some cases. He writes a hex
>value to an ADO stream, then reads it back as a byte array. This may help
>you:
>===============
>Function HexStrToOctet(strInput)
> ' Function to convert hex string to an OctetString (byte array).
> ' Based on a program by Paul Randall, October, 2002.
>
> Dim orginalLocale, adoStream
>
> ' Retain original locale setting.
> originalLocale = SetLocale(1033)
>
> Set adoStream = CreateObject("ADODB.Stream")
>
> ' Write hex string to stream.
> adoStream.Type = 2
> adoStream.Charset = "x-ansi"
> adoStream.Open
> adoStream.WriteText strInput, 0
>
> ' Read stream as byte array.
> adoStream.Position = 0
> adoStream.Type = 1
> HexStrToOctet = adoStream.Read
>
> ' Restore original locale setting.
> SetLocale(originalLocale)
>End Function
>
>--
>Richard Mueller
>Microsoft MVP Scripting and ADSI
>Hilltop Lab -
http://www.rlmueller.net