troubleshooting Question

String to Bynary (Fast Conversion)

Avatar of lson_98
lson_98Flag for Italy asked on
Microsoft AccessASP
1 Comment1 Solution308 ViewsLast Modified:
Is there anyone that knows a fast String to Binary conversion with VBA?
Here an example of slow conversion and a fast conversion o Binary to String
Function String_To_Binary(S As String) As Variant
'It takes Long time to Converts the string into a Bynary array() if the string is long...
'Standard conversion...
Dim I As Long, V As Variant
ReDim V(0 To Len(S) - 1) As Byte
For I = 1 To Len(S)
    V(I - 1) = AscB(Mid(S, I, 1))
Next I
String_To_Binary = V
End Function
Function BinaryToString(ByteArray As Variant) As String
'--- Fast Converts the binary content to text
Dim X As New ADODB.Recordset, L As Long
BinaryToString = ""
If IsNull(ByteArray) Then Exit Function
L = LenB(ByteArray)
If L > 0 Then
    X.Fields.Append "mBinary", adLongVarChar, L
    'Use the AppendChunk method to append a Byte Array as a string!
    X("mBinary").AppendChunk ByteArray
    BinaryToString = X("mBinary")
End If
End Function

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros