/
to-morse.bas
119 lines (113 loc) · 3.88 KB
/
to-morse.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
REM to-morse.bas is a LibreOffice macro that translates text in a spreadsheet
REM cell to its representation in Morse Code.
REM https://github.com/erictheise/to-morse is its home.
REM Copyright (C) 2021 Eric Theise <erictheise@gmail.com>
REM This program is free software: you can redistribute it and/or modify
REM it under the terms of the GNU Affero General Public License as published
REM by the Free Software Foundation, either version 3 of the License, or
REM (at your option) any later version.
REM This program is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
REM GNU Affero General Public License for more details.
REM You should have received a copy of the GNU Affero General Public License
REM along with this program. If not, see <https://www.gnu.org/licenses/>.
Function ToMorse(Optional x) As Variant
Dim s$
Dim i As Integer
For i = 1 to Len(x)
char = Mid(x, i, 1)
Select Case LCase(char)
Case "a"
s = s & "▄ ▄▄▄"
Case "b"
s = s & "▄▄▄ ▄ ▄ ▄"
Case "c"
s = s & "▄▄▄ ▄ ▄▄▄ ▄"
Case "d"
s = s & "▄▄▄ ▄ ▄"
Case "e"
s = s & "▄"
Case "f"
s = s & "▄ ▄ ▄▄▄ ▄"
Case "g"
s = s & "▄▄▄ ▄▄▄ ▄"
Case "h"
s = s & "▄ ▄ ▄ ▄"
Case "i"
s = s & "▄ ▄"
Case "j"
s = s & "▄ ▄▄▄ ▄▄▄ ▄▄▄"
Case "k"
s = s & "▄▄▄ ▄ ▄▄▄"
Case "l"
s = s & "▄ ▄▄▄ ▄ ▄"
Case "m"
s = s & "▄▄▄ ▄▄▄"
Case "n"
s = s & "▄▄▄ ▄"
Case "o"
s = s & "▄▄▄ ▄▄▄ ▄▄▄"
Case "p"
s = s & "▄ ▄▄▄ ▄▄▄ ▄"
Case "q"
s = s & "▄▄▄ ▄▄▄ ▄ ▄▄▄"
Case "r"
s = s & "▄ ▄▄▄ ▄"
Case "s"
s = s & "▄ ▄ ▄"
Case "t"
s = s & "▄▄▄"
Case "u"
s = s & "▄ ▄ ▄▄▄"
Case "v"
s = s & "▄ ▄ ▄ ▄▄▄"
Case "w"
s = s & "▄ ▄▄▄ ▄▄▄"
Case "x"
s = s & "▄▄▄ ▄ ▄ ▄▄▄"
Case "y"
s = s & "▄▄▄ ▄ ▄▄▄ ▄▄▄"
Case "z"
s = s & "▄▄▄ ▄▄▄ ▄ ▄"
Case "1"
s = s & "▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄"
Case "2"
s = s & "▄ ▄ ▄▄▄ ▄▄▄ ▄▄▄"
Case "3"
s = s & "▄ ▄ ▄ ▄▄▄ ▄▄▄"
Case "4"
s = s & "▄ ▄ ▄ ▄ ▄▄▄"
Case "5"
s = s & "▄ ▄ ▄ ▄ ▄"
Case "6"
s = s & "▄▄▄ ▄ ▄ ▄ ▄"
Case "7"
s = s & "▄▄▄ ▄▄▄ ▄ ▄ ▄"
Case "8"
s = s & "▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄"
Case "9"
s = s & "▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄"
Case "0"
s = s & "▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄"
Case "."
s = s & "▄ ▄▄▄ ▄ ▄▄▄ ▄ ▄▄▄"
Case ","
s = s & "▄▄▄ ▄▄▄ ▄ ▄ ▄▄▄ ▄▄▄"
REM Here we need to test for straight and "smart"
REM opening & closing double quotation marks.
Case """", "“", "”"
s = s & "▄ ▄▄▄ ▄ ▄ ▄▄▄ ▄"
Case "?"
s = s & "▄ ▄ ▄▄▄ ▄▄▄ ▄ ▄"
Case "'"
s = s & "▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄"
Case "!"
s = s & "▄▄▄ ▄ ▄▄▄ ▄ ▄▄▄ ▄▄▄"
Case " "
s = s & " "
End Select
s = s & " "
Next
ToMorse = s
End Function