Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
T9 Simulator - FrmMain.frm

FrmMain.frm

Caricato da: Piero Tofy
Scarica il programma completo

  1. 'T9 Simulator by Piero Tofy 2006 - http://www.pierotofy.it
  2.  
  3. 'This program is free software; you can redistribute it and/or
  4. 'modify it under the terms of the GNU General Public License
  5. 'as published by the Free Software Foundation; either version 2
  6. 'of the License, or (at your option) any later version.
  7.  
  8. 'This program is distributed in the hope that it will be useful,
  9. 'but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. 'GNU General Public License for more details.
  12.  
  13. 'You should have received a copy of the GNU General Public License
  14. 'along with this program; if not, write to the Free Software
  15. 'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  16.  
  17. Option Explicit
  18.  
  19. Private Sub cmdBrowse_Click()
  20. On Error GoTo errhandler
  21.     comdlg.Filter = "Text files|*.txt|All files|*.*|"
  22.     comdlg.ShowOpen
  23.     If comdlg.FileName <> vbNullString Then txtdictionary.Text = comdlg.FileName
  24. errhandler:
  25. ' Non ha selezionato...
  26. End Sub
  27.  
  28. Private Sub searchFor(numbers As String, dictionaryfile As String)
  29. On Error GoTo errhandler
  30.     'Clear the textarea
  31.     txtwords.Text = ""
  32.    
  33.     'Set the numbers' length
  34.     Dim numLength As Integer
  35.     numLength = Len(numbers)
  36.    
  37.     'Open the file
  38.     Dim strBuff As String
  39.     Open dictionaryfile For Input As #1
  40.        
  41.     'Read all lines from file
  42.     Do Until EOF(1)
  43.         Line Input #1, strBuff
  44.        
  45.         'if it's longer than the numbers, skip
  46.         If Not (Len(strBuff) > numLength) Then
  47.             If wordIsValid(strBuff, numbers) Then txtwords.Text = txtwords.Text + " - " + strBuff + vbCrLf
  48.         End If
  49.     Loop
  50.     Close #1
  51. Exit Sub
  52.  
  53. errhandler:
  54. MsgBox "The application will terminate now!", vbCritical, "Critical error"
  55. End
  56. End Sub
  57.  
  58. Public Function wordIsValid(word As String, numbers As String) As Boolean
  59. Dim c, d, e As Byte
  60. Dim ch As String, compareCh As String, possibleChars As String
  61. Dim foundChar As Boolean
  62.  
  63.  
  64. 'Compare each number with the word
  65. For c = 1 To Len(numbers)
  66.     foundChar = False
  67.    
  68.     ch = Mid$(numbers, c, 1)
  69.     Select Case ch
  70.         Case "1"
  71.             possibleChars = "pqrs"
  72.         Case "2"
  73.             possibleChars = "tuv"
  74.         Case "3"
  75.             possibleChars = "wxyz"
  76.         Case "4"
  77.             possibleChars = "ghi"
  78.         Case "5"
  79.             possibleChars = "jkl"
  80.         Case "6"
  81.             possibleChars = "mno"
  82.         Case "8"
  83.             possibleChars = "abc"
  84.         Case "9"
  85.             possibleChars = "def"
  86.     End Select
  87.    
  88.     'Search for the right chars in the word
  89.     compareCh = Mid$(word, c, 1)
  90.     For e = 1 To Len(possibleChars)
  91.         If compareCh = Mid$(possibleChars, e, 1) Then foundChar = True
  92.     Next e
  93.     If Not foundChar Then
  94.         wordIsValid = False
  95.         Exit Function
  96.     End If
  97. Next c
  98. wordIsValid = True
  99. End Function
  100.  
  101. Private Sub Form_Load()
  102.     txtdictionary.Text = App.Path + "\Italiano.txt"
  103. End Sub
  104.  
  105.  
  106. Private Sub txtnumbers_Change()
  107. searchFor txtnumbers.Text, txtdictionary.Text
  108. End Sub
  109.  
  110. Private Sub txtnumbers_KeyPress(KeyAscii As Integer)
  111. 'Delete all codes that aren't numbers (except backspace, keycode 8)
  112.  
  113. If KeyAscii <> 8 Then
  114.     If KeyAscii > 57 Or KeyAscii < 48 Then
  115.         KeyAscii = 0
  116.     End If
  117.     If KeyAscii = 55 Then KeyAscii = 0
  118. End If
  119. End Sub