You are on page 1of 3

LA SCACCHIERA DI POLIBIO

Private Sub Comando2_Click()


Dim lettera As String
Dim par , parola As String
Dim r, c, i, cod, n, codice As Integer
Dim mat(1 To 5, 1 To 5) As String
'CREAZIONE MATRICE
mat(1, 1) = "A"
mat(1, 2) = "B"
mat(1, 3) = "C"
mat(1, 4) = "D"
mat(1, 5) = "E"
mat(2, 1) = "F"
mat(2, 2) = "G"
mat(2, 3) = "H"
mat(2, 4) = "I"
mat(2, 5) = "K"
mat(3, 1) = "L"
mat(3, 2) = "M"
mat(3, 3) = "N"
mat(3, 4) = "O"
mat(3, 5) = "P"
mat(4, 1) = "Q"
mat(4, 2) = "R"
mat(4, 3) = "S"
mat(4, 4) = "T"

mat(4, 5) = "U"
mat(5, 1) = "V"
mat(5, 2) = "W"
mat(5, 3) = "X"
mat(5, 4) = "Y"
mat(5, 5) = "Z"
'DA PAROLA A CODICE
Textbox1.text = PAROLA
n = Len(PAROLA)
For i = 1 To n
lettera = Mid(PAROLA, i, 1)
For r = 1 To 5
For c = 1 To 5
If mat(r, c) = lettera Then
cod = cod & r & c
End If
Next c
Next r
Next i
MsgBox ("il codice : " & cod)
'DA CODICE A PAROLA
Textbox2.text = CODICE
n = Len(CODICE)
For i = 1 To n Step 2
r = Mid(CODICE, i, 1)
c = Mid(CODICE, i + 1, 1)

par = par & mat(r, c)


Next i
MsgBox ("la parola : " & par)
End Sub