'T9 Simulator by Piero Tofy 2006 - http://www.pierotofy.it
'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Option Explicit
Private Sub cmdBrowse_Click()
On Error GoTo errhandler
comdlg.Filter = "Text files|*.txt|All files|*.*|"
comdlg.ShowOpen
If comdlg.FileName <> vbNullString Then txtdictionary.Text = comdlg.FileName
errhandler:
' Non ha selezionato...
End Sub
Private Sub searchFor(numbers As String, dictionaryfile As String)
On Error GoTo errhandler
'Clear the textarea
txtwords.Text = ""
'Set the numbers' length
Dim numLength As Integer
numLength = Len(numbers)
'Open the file
Dim strBuff As String
Open dictionaryfile For Input As #1
'Read all lines from file
Do Until EOF(1)
Line Input #1, strBuff
'if it's longer than the numbers, skip
If Not (Len(strBuff) > numLength) Then
If wordIsValid(strBuff, numbers) Then txtwords.Text = txtwords.Text + " - " + strBuff + vbCrLf
End If
Loop
Close #1
Exit Sub
errhandler:
MsgBox "The application will terminate now!", vbCritical, "Critical error"
End
End Sub
Public Function wordIsValid(word As String, numbers As String) As Boolean
Dim c, d, e As Byte
Dim ch As String, compareCh As String, possibleChars As String
Dim foundChar As Boolean
'Compare each number with the word
For c = 1 To Len(numbers)
foundChar = False
ch = Mid$(numbers, c, 1)
Select Case ch
Case "1"
possibleChars = "pqrs"
Case "2"
possibleChars = "tuv"
Case "3"
possibleChars = "wxyz"
Case "4"
possibleChars = "ghi"
Case "5"
possibleChars = "jkl"
Case "6"
possibleChars = "mno"
Case "8"
possibleChars = "abc"
Case "9"
possibleChars = "def"
End Select
'Search for the right chars in the word
compareCh = Mid$(word, c, 1)
For e = 1 To Len(possibleChars)
If compareCh = Mid$(possibleChars, e, 1) Then foundChar = True
Next e
If Not foundChar Then
wordIsValid = False
Exit Function
End If
Next c
wordIsValid = True
End Function
Private Sub Form_Load()
txtdictionary.Text = App.Path + "\Italiano.txt"
End Sub
Private Sub txtnumbers_Change()
searchFor txtnumbers.Text, txtdictionary.Text
End Sub
Private Sub txtnumbers_KeyPress(KeyAscii As Integer)
'Delete all codes that aren't numbers (except backspace, keycode 8)
If KeyAscii <> 8 Then
If KeyAscii > 57 Or KeyAscii < 48 Then
KeyAscii = 0
End If
If KeyAscii = 55 Then KeyAscii = 0
End If
End Sub