Hey Bill Wilk....

1. Senior Member
Join Date
Dec 1969
Posts
2,049

## Hey Bill Wilk....

Here is a sub I found.<BR><BR>It copies it memory though.<BR>Do you know how to read from the memory or change it to write the file?<BR><BR><BR>Sub USAsciiToBase64(bIN() As Byte, b64() As Byte)<BR><BR> Dim sBinary As Byte<BR> Const TriPadding As Byte = 61 &#039; =<BR> Const Base64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"<BR> Static Base64(0 To 63) As Byte, Initialized As Boolean<BR> Dim TriBuf(0 To 3) As Byte, b As Byte, TriBits&<BR> Dim Trips&, Xtras&, bInLen&, bInPtr&, b64Ptr&<BR><BR> If Not Initialized Then<BR> Initialized = True<BR> For b = 0 To 25<BR> Base64(b) = b + 65<BR> Base64(b + 26) = b + 97<BR> Next<BR> For b = 52 To 61<BR> Base64(b) = b - 4<BR> Next<BR> Base64(62) = 43<BR> Base64(63) = 47<BR> End If<BR> bInLen = UBound(bIN) - LBound(bIN) + 1<BR> Trips = bInLen 3<BR> Xtras = bInLen Mod 3<BR> ReDim b64(0 To IIf(Xtras, Trips + 1, Trips) * 4 + 1) &#039;+1 for vbCrLf<BR> <BR> For bInPtr = 0 To Trips * 3 - 1 Step 3<BR> TriBuf(2) = bIN(bInPtr)<BR> TriBuf(1) = bIN(bInPtr + 1)<BR> TriBuf(0) = bIN(bInPtr + 2)<BR> CopyMemory TriBits, TriBuf(0), 3<BR> b64(b64Ptr) = Base64(TriBits &H40000)<BR> b64(b64Ptr + 1) = Base64((TriBits &H1000&) And &H3F&)<BR> b64(b64Ptr + 2) = Base64((TriBits &H40&) And &H3F&)<BR> b64(b64Ptr + 3) = Base64(TriBits And &H3F&)<BR> b64Ptr = b64Ptr + 4<BR> Next<BR> <BR> If Xtras &#062; 0 Then<BR> TriBuf(0) = 0 &#039;TriPadding<BR> TriBuf(2) = bIN(bInPtr)<BR> If Xtras &#062; 1 Then<BR> TriBuf(1) = bIN(bInPtr + 1)<BR> Else<BR> TriBuf(1) = 0 &#039;TriPadding<BR> End If<BR> <BR> CopyMemory TriBits, TriBuf(0), 3<BR> b64(b64Ptr) = Base64(TriBits &H40000)<BR> b64(b64Ptr + 1) = Base64((TriBits &H1000&) And &H3F&)<BR> b64(b64Ptr + 2) = IIf(Xtras = 1, TriPadding, Base64((TriBits &H40&) And &H3F&))<BR> b64(b64Ptr + 3) = TriPadding &#039;IIf(Xtras &#062; 1, TriPadding, Base64(TriBits And &H3F&))<BR> b64Ptr = b64Ptr + 4<BR> End If<BR> b64(b64Ptr) = 13 &#039;vbCr<BR> b64(b64Ptr + 1) = 10 &#039;vbLf<BR><BR>End Sub<BR><BR><BR>Just curious.<BR>jc

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## That's backwards...

It goes ASCII to Base64. You need the opposite direction.<BR><BR>No, I have no idea how to do that in VBScript code, in any case, becuz there is no such thing as<BR> bIN() As Byte, b64() As Byte<BR>in VBScript. Those are both byte arrays.<BR><BR>By the by...you&#039;ll note that my assumption about how to code the conversion was very very close to right.<BR><BR>Gotta go for the night.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•