-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathANSICoder.bas
159 lines (118 loc) · 4.25 KB
/
ANSICoder.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Attribute VB_Name = "ANSICoder"
Option Explicit
' This method converts the hexadecimal number to decimal equivalent.
Public Function HEXToDEC(ByVal s As String) As String
Dim i As Integer
Dim sArray() As String
Dim output As String
' Cut a text and save them in an array
sArray = Split(s, " ")
' Loop through the each items
For i = LBound(sArray) To UBound(sArray)
' Convert the item to decimal
output = output + Str(Dec(UCase(sArray(i)))) + " "
Next i
' Return the new string
HEXToDEC = Trim(output)
End Function
' This method converts the hexadecimal number to decimal equivalent.
Public Function DECToHEX(ByVal s As String) As String
Dim i As Integer
Dim sArray() As String
Dim output As String
' Cut a text and save them in an array.
sArray = Split(s, " ")
' Loop through the each items.
For i = LBound(sArray) To UBound(sArray)
' Convert the item to hexadecimal.
output = output + Hex(sArray(i)) + " "
Next i
' Return the new string.
DECToHEX = Trim(output)
End Function
' This method transforms a character set to hexadecimal equivalent.
Public Function HEXEncode(ByVal s As String) As String
Dim i As Integer
Dim output As String
' Loop through the each character.
For i = 1 To Len(s)
' Transform the character to hexadecimal.
output = output + Hex(Asc(Mid(s, i, 1))) + " "
Next i
' Return the new string.
HEXEncode = Trim(output)
End Function
' This method transforms a hexadecimal set to character set equivalent.
Public Function HEXDecode(ByVal s As String) As String
Dim i As Integer
Dim sArray() As String
Dim output As String
' Cut a text and save them in an array.
sArray = Split(s, " ")
' Loop through the each item.
For i = LBound(sArray) To UBound(sArray)
' Transform the hexadecimal to character.
output = output + Chr(Dec(UCase(sArray(i))))
Next i
' Return the new string.
HEXDecode = output
End Function
' This method transforms a character set to decimal set equivalent.
Public Function DECEncode(ByVal s As String) As String
Dim i As Integer
Dim output As String
' Loop through the each item.
For i = 1 To Len(s)
' Transform the character to decimal.
output = output + Str(Asc(Mid(s, i, 1))) + " "
Next i
' Return the new string.
DECEncode = Trim(output)
End Function
' This method transforms a decimal set to character set equivalent.
Public Function DECDecode(ByVal s As String) As String
Dim i As Integer
Dim sArray() As String
Dim output As String
' Loop through the each item.
sArray = Split(s, " ")
For i = LBound(sArray) To UBound(sArray)
' Transform the decimal to character.
output = output + Chr(UCase(sArray(i)))
Next i
' Return the new string.
DECDecode = output
End Function
' This method converts hexadecimal to decimal.
Private Function Dec(ByVal Hexa As String) As Variant
' Return the conversion.
Dec = CDec("&H" & Hexa)
End Function
' This method transforms a character set to Visual Basic notation equivalent.
Public Function VBEncode(ByVal s As String) As String
Dim i As Integer
Dim output As String
' Loop through the each item.
For i = 1 To Len(s) - 1
' Transform the character to hexadecimal and add format.
output = output + "Chr(&H" + Hex(Asc(Mid(s, i, 1))) + ") + "
Next i
' Transform the last character to hexadecimal and add format.
output = output + "Chr(&H" + Hex(Asc(Mid(s, i, 1))) + ")"
' Return the new string.
VBEncode = output
End Function
' This method transforms a character set to Java notation equivalent.
Public Function JAVAEncode(ByVal s As String) As String
Dim i As Integer
Dim output As String
' Loop through the each item.
For i = 1 To Len(s) - 1
' Transform the character to hexadecimal and add format.
output = output + "\u00" + Hex(Asc(Mid(s, i, 1))) + " + "
Next i
' Transform the last character to hexadecimal and add format.
output = output + "\u00" + Hex(Asc(Mid(s, i, 1)))
' Return the new string.
JAVAEncode = output
End Function