-
Notifications
You must be signed in to change notification settings - Fork 4
/
stringToBinary.bas
40 lines (30 loc) · 1.21 KB
/
stringToBinary.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'''''''''''''''''''''''''''''''''''''''''''''''
' Convert String To Binary '
'''''''''''''''''''''''''''''''''''''''''''''''
' *** Note: 2003 Antonin Foller, http://www.motobit.com ***
'recieves text (ex. "Hello World") as string
'outputs binary data
Function stringToBinary(Text As String)
'dimension constants
Const adTypeText = 2
Const adTypeBinary = 1
'create stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'specify stream type - we want to save text/string data
BinaryStream.Type = adTypeText
'specify charset for the source text (unicode) data
BinaryStream.Charset = "us-ascii"
'open the stream and write text/string data to the object
BinaryStream.Open
BinaryStream.WriteText Text
'change stream type to binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
'ignore first two bytes - sign of
BinaryStream.Position = 0
'return - open the stream and get binary data from the object
stringToBinary = BinaryStream.Read
'garbage collection
Set BinaryStream = Nothing
End Function