Re: how to update binary field types in ADO



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
.



Relevant Pages

  • Re: how to update binary field types in ADO
    ... One technique suggested by Paul Randall works in some cases. ... ' Function to convert hex string to an OctetString (byte array). ... ' Write hex string to stream. ...
    (microsoft.public.scripting.vbscript)
  • Re: Big endian convention in Ruby
    ... if the array holding this is ... messageHex[0].hex.to_i this will ensure that it is a integer in hex. ... Unpack directly to Integers, as shown above. ... It works perfectly fine with in give the loop 64 times.. ...
    (comp.lang.ruby)
  • Re: byte data manipulation
    ... Read in the input hex file, stripping of the preamble and checksum ... and putting the bytes (2 chars) into array_1. ... explains why you need the array. ...
    (comp.lang.c)
  • Re: Hex to Binary Conversion
    ... I have an array of hex bytes. ... The conversion itself depends on exactly what you mean, as well as in what order the bytes are provided. ... complement of it ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Need Help getting values from bits.
    ... array, and convert it back to a hex value. ... Out of those 32 bits I need to get the hex value of certain ... The header information I am ... I've been able to move the data into a BitArray, but from that point I'm at ...
    (microsoft.public.dotnet.languages.csharp)