Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
T9 Simulator v2.1 - FrmMain.frm

FrmMain.frm

Caricato da: Piero Tofy
Scarica il programma completo

  1. 'T9 Simulator v2.1 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. ' User doesn't selected
  26. End Sub
  27.  
  28. Private Sub searchFor(numbers As String, dictionaryfile As String)
  29. On Error GoTo errhandler
  30.     'Set a new array that will contains the inserted items
  31.     Dim addedWords(99) As String
  32.     Dim addedWordsComplete(99) As Boolean
  33.     Dim addedWordsCount As Integer
  34.     addedWordsCount = 0
  35.    
  36.     Dim isComplete As Boolean
  37.     Dim showIncompleteWords As Boolean
  38.     showIncompleteWords = True
  39.    
  40.     'Clear the ListBox area
  41.     ListBox.Clear
  42.        
  43.     'Set the numbers' length
  44.     Dim numLength As Integer
  45.     numLength = Len(numbers)
  46.    
  47.     'Open the file
  48.     Dim strBuff As String
  49.     Open dictionaryfile For Input As #1
  50.        
  51.     'Read all lines from file
  52.     Do Until EOF(1)
  53.         Line Input #1, strBuff
  54.        
  55.         isComplete = True
  56.        
  57.         'Truncate strBuff if its length is major than the numbers' length
  58.         If (Len(strBuff) > numLength) Then
  59.             strBuff = Left$(strBuff, numLength)
  60.             isComplete = False
  61.         End If
  62.        
  63.         If Not alreadyAdded(strBuff, addedWords, addedWordsCount) And wordIsValid(strBuff, numbers) Then
  64.             addedWords(addedWordsCount) = strBuff
  65.             addedWordsComplete(addedWordsCount) = isComplete
  66.             addedWordsCount = addedWordsCount + 1
  67.         End If
  68.     Loop
  69.     Close #1
  70.    
  71.     'If there is a complete word, don't show the incomplete words
  72.     If thereIsACompleteWord(addedWordsComplete, addedWordsCount) Then showIncompleteWords = False
  73.    
  74.     'Fill the listbox
  75.     fillListBox addedWords, addedWordsCount, addedWordsComplete, showIncompleteWords
  76. Exit Sub
  77.  
  78. errhandler:
  79. MsgBox "The application will terminate now!", vbCritical, "Critical error"
  80. End
  81. End Sub
  82.  
  83.  
  84.  
  85. Public Function thereIsACompleteWord(addedWordsComplete() As Boolean, addedWordsCount As Integer) As Boolean
  86. Dim c As Integer
  87. For c = 0 To addedWordsCount
  88.     If addedWordsComplete(c) Then
  89.         thereIsACompleteWord = True
  90.         Exit Function
  91.     End If
  92. Next c
  93. thereIsACompleteWord = False
  94. End Function
  95.  
  96. Public Sub fillListBox(addedWords() As String, addedWordsCount As Integer, addedWordsComplete() As Boolean, showIncompleteWords As Boolean)
  97. Dim c As Integer
  98. For c = 0 To addedWordsCount
  99.     If showIncompleteWords Then
  100.         ListBox.AddItem addedWords(c)
  101.     Else
  102.         If addedWordsComplete(c) Then ListBox.AddItem addedWords(c)
  103.     End If
  104. Next c
  105. End Sub
  106.  
  107. Public Function alreadyAdded(word As String, addedWords() As String, addedWordsCount As Integer) As Boolean
  108. Dim c As Integer
  109. For c = 0 To addedWordsCount
  110.     If word = addedWords(c) Then
  111.         alreadyAdded = True
  112.         Exit Function
  113.     End If
  114. Next c
  115. alreadyAdded = False
  116. End Function
  117.  
  118. Public Function wordIsValid(word As String, numbers As String) As Boolean
  119. Dim c, d, e As Byte
  120. Dim ch As String, compareCh As String, possibleChars As String
  121. Dim foundChar As Boolean
  122.  
  123.  
  124. 'Compare each number with the word
  125. For c = 1 To Len(numbers)
  126.     foundChar = False
  127.    
  128.     ch = Mid$(numbers, c, 1)
  129.     Select Case ch
  130.         Case "1"
  131.             possibleChars = "pqrs"
  132.         Case "2"
  133.             possibleChars = "tuv"
  134.         Case "3"
  135.             possibleChars = "wxyz"
  136.         Case "4"
  137.             possibleChars = "ghi"
  138.         Case "5"
  139.             possibleChars = "jkl"
  140.         Case "6"
  141.             possibleChars = "mno"
  142.         Case "8"
  143.             possibleChars = "abc"
  144.         Case "9"
  145.             possibleChars = "def"
  146.     End Select
  147.    
  148.     'Search for the right chars in the word
  149.     compareCh = Mid$(word, c, 1)
  150.     For e = 1 To Len(possibleChars)
  151.         If compareCh = Mid$(possibleChars, e, 1) Then foundChar = True
  152.     Next e
  153.     If Not foundChar Then
  154.         wordIsValid = False
  155.         Exit Function
  156.     End If
  157. Next c
  158. wordIsValid = True
  159. End Function
  160.  
  161. Private Sub Form_Load()
  162.     txtdictionary.Text = App.Path + "\Italiano.txt"
  163. End Sub
  164.  
  165.  
  166. Private Sub txtnumbers_Change()
  167. searchFor txtnumbers.Text, txtdictionary.Text
  168. End Sub
  169.  
  170. Private Sub txtnumbers_KeyPress(KeyAscii As Integer)
  171. 'Delete all codes that aren't numbers (except backspace, keycode 8)
  172.  
  173. If KeyAscii <> 8 Then
  174.     If KeyAscii > 57 Or KeyAscii < 48 Then
  175.         KeyAscii = 0
  176.     End If
  177.     If KeyAscii = 55 Then KeyAscii = 0
  178. End If
  179. End Sub