Option Explicit
Private Sub Command1_Click()
Call TestEncodeDecode
End Sub
Private Sub TestEncodeDecode()
'Populate byte array to UI-defined size
Dim lArraySize As Long
lArraySize = CLng(Val(txtArraySize.Text))
ReDim a_bytData(0 To lArraySize) As Byte
Dim lLooper As Long
For lLooper = 0 To lArraySize
a_bytData(lLooper) = lLooper Mod 255
Next
Dim a_bytDataOut() As Byte
Dim sDataOut As String
Dim objBase64Encoder As Base64Encoder
Set objBase64Encoder = New Base64Encoder
'Either
Call objBase64Encoder.Base64EncoderString(a_bytData, sDataOut)
'Or
Call objBase64Encoder.Base64Encoder(a_bytData, a_bytDataOut)
sDataOut = StrConv(a_bytDataOut, vbUnicode)
txtBase64Encoded = sDataOut
Dim a_bytDataBackIn() As Byte
'a_bytDataBackIn = a_byteRef
a_bytDataBackIn = a_bytDataOut
Dim a_bytDataBackOutAgain() As Byte
'Either
Call objBase64Encoder.Base64Decoder(a_bytDataBackIn, a_bytDataBackOutAgain)
'Or
Call objBase64Encoder.Base64DecoderString(sDataOut, a_bytDataBackOutAgain)
#If iCompareMSXML = -1 Then
'If we compile this block in, we need to reference MSXML's Type Library
Dim objXMLDoc As DOMDocument
Set objXMLDoc = New DOMDocument
Dim objXMLNode As IXMLDOMNode
Set objXMLNode = objXMLDoc.createElement("Test")
objXMLNode.dataType = "bin.base64"
objXMLNode.nodeTypedValue = a_bytData
Dim sRef As String
sRef = objXMLNode.Text
Dim a_byteRef() As Byte
a_byteRef = StrConv(sRef, vbFromUnicode)
Dim booSameBytes As Boolean
booSameBytes = True
Dim lLooperBytes As Long
Dim booLBoundSame As Boolean
Dim booUBoundSame As Boolean
booLBoundSame = (LBound(a_bytData) = LBound(a_bytDataBackOutAgain))
booUBoundSame = (UBound(a_bytData) = UBound(a_bytDataBackOutAgain))
If booLBoundSame And booUBoundSame Then
For lLooperBytes = LBound(a_bytData) To UBound(a_bytData)
If (a_bytData(lLooperBytes) <> a_bytDataBackOutAgain(lLooperBytes)) Then
booSameBytes = False
Exit For
End If
Next
Else
booSameBytes = False
End If
Call SetCompareLabel("Byte Arrays Match = " & booSameBytes)
#End If 'iCompareMSXML = -1
End Sub
Private Sub Form_Load()
Call SetCompareLabel(vbNullString)
End Sub
Private Sub Form_Resize()
On Error Resume Next
With txtBase64Encoded
Call .Move(0, .Top, Me.ScaleWidth, Me.ScaleHeight - .Top)
End With
End Sub
Private Sub SetCompareLabel(sMsg As String)
#If iCompareMSXML = -1 Then
lblCompare = sMsg
#Else
lblCompare = "To compare results, add a reference to the MSXML Type Library, then set the conditional compilation constant 'iCompareMSXML = -1'"
#End If 'iCompareMSXML = -1
End Sub