home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD112661132000.psc / frmSpellIt.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-11-02  |  12.3 KB  |  359 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
  4. Begin VB.Form frmSpellIt 
  5.    BorderStyle     =   4  'Fixed ToolWindow
  6.    Caption         =   "Spell Check"
  7.    ClientHeight    =   4020
  8.    ClientLeft      =   45
  9.    ClientTop       =   315
  10.    ClientWidth     =   7020
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4020
  15.    ScaleWidth      =   7020
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin MSComctlLib.ProgressBar prgCount 
  19.       Height          =   255
  20.       Left            =   240
  21.       TabIndex        =   11
  22.       Top             =   3600
  23.       Width           =   6615
  24.       _ExtentX        =   11668
  25.       _ExtentY        =   450
  26.       _Version        =   393216
  27.       Appearance      =   1
  28.    End
  29.    Begin VB.CommandButton cmdStart 
  30.       Caption         =   "Start"
  31.       Height          =   375
  32.       Left            =   3000
  33.       TabIndex        =   10
  34.       Top             =   3000
  35.       Width           =   855
  36.    End
  37.    Begin RichTextLib.RichTextBox rtfSpell 
  38.       Height          =   2535
  39.       Left            =   120
  40.       TabIndex        =   9
  41.       Top             =   240
  42.       Width           =   3735
  43.       _ExtentX        =   6588
  44.       _ExtentY        =   4471
  45.       _Version        =   393217
  46.       Enabled         =   -1  'True
  47.       TextRTF         =   $"frmSpellIt.frx":0000
  48.    End
  49.    Begin VB.CommandButton cmdChange 
  50.       Caption         =   "Change"
  51.       Enabled         =   0   'False
  52.       Height          =   375
  53.       Left            =   4080
  54.       TabIndex        =   3
  55.       Top             =   3000
  56.       Width           =   855
  57.    End
  58.    Begin VB.CommandButton cmdIgnore 
  59.       Caption         =   "Ignore"
  60.       Default         =   -1  'True
  61.       Enabled         =   0   'False
  62.       Height          =   375
  63.       Left            =   5040
  64.       TabIndex        =   4
  65.       Top             =   3000
  66.       Width           =   855
  67.    End
  68.    Begin VB.CommandButton cmdCancel 
  69.       Caption         =   "&Cancel"
  70.       Height          =   375
  71.       Left            =   6000
  72.       TabIndex        =   5
  73.       Top             =   3000
  74.       Width           =   855
  75.    End
  76.    Begin VB.TextBox txtSpell 
  77.       Height          =   285
  78.       Left            =   4080
  79.       TabIndex        =   1
  80.       Top             =   960
  81.       Width           =   2775
  82.    End
  83.    Begin VB.ListBox lstCorrect 
  84.       Height          =   1155
  85.       IntegralHeight  =   0   'False
  86.       Left            =   4080
  87.       TabIndex        =   2
  88.       Top             =   1560
  89.       Width           =   2775
  90.    End
  91.    Begin VB.Label lblInfo 
  92.       Height          =   255
  93.       Index           =   2
  94.       Left            =   240
  95.       TabIndex        =   14
  96.       Top             =   3360
  97.       Width           =   2535
  98.    End
  99.    Begin VB.Label lblInfo 
  100.       Height          =   255
  101.       Index           =   1
  102.       Left            =   240
  103.       TabIndex        =   13
  104.       Top             =   3120
  105.       Width           =   2535
  106.    End
  107.    Begin VB.Label lblInfo 
  108.       Height          =   255
  109.       Index           =   0
  110.       Left            =   240
  111.       TabIndex        =   12
  112.       Top             =   2880
  113.       Width           =   2535
  114.    End
  115.    Begin VB.Label Label 
  116.       Caption         =   "Suggestions"
  117.       Height          =   255
  118.       Index           =   2
  119.       Left            =   4080
  120.       TabIndex        =   8
  121.       Top             =   1320
  122.       Width           =   2295
  123.    End
  124.    Begin VB.Label Label 
  125.       Caption         =   "Change To"
  126.       Height          =   255
  127.       Index           =   1
  128.       Left            =   4080
  129.       TabIndex        =   7
  130.       Top             =   720
  131.       Width           =   2295
  132.    End
  133.    Begin VB.Label Label 
  134.       Caption         =   "Not In Dictionary"
  135.       Height          =   255
  136.       Index           =   0
  137.       Left            =   4080
  138.       TabIndex        =   6
  139.       Top             =   90
  140.       Width           =   2295
  141.    End
  142.    Begin VB.Label lblFind 
  143.       BorderStyle     =   1  'Fixed Single
  144.       Height          =   255
  145.       Left            =   4080
  146.       TabIndex        =   0
  147.       Top             =   360
  148.       Width           =   2775
  149.    End
  150. Attribute VB_Name = "frmSpellIt"
  151. Attribute VB_GlobalNameSpace = False
  152. Attribute VB_Creatable = False
  153. Attribute VB_PredeclaredId = True
  154. Attribute VB_Exposed = False
  155.     Option Explicit
  156.     Private SpellIt As Word.Application
  157.     Private SpDoc As Document
  158.     Private SpErrors As SpellingSuggestions
  159.     Private SplError As SpellingSuggestion
  160.     Private bDontCheck As Boolean
  161.     Private lStart As Long
  162.     Dim sAlready() As String
  163.     Dim iLineCt As Integer
  164.     Dim sHotKey As String
  165. Private Function AddHotKey(ByVal sCaption As String)
  166.     Dim k As Integer
  167.     If (Len(sHotKey) = 0) Or (InStr(sCaption, sHotKey) = 0) Then
  168.         AddHotKey = sCaption
  169.         Exit Function
  170.     End If
  171.     'If the original word had a hot key then we want to ad the ampersand into
  172.     'the suggested words with the same hot key char.
  173.     AddHotKey = Left$(sCaption, InStr(sCaption, sHotKey) - 1) & "&" & Right$(sCaption, Len(sCaption) - InStr(sCaption, sHotKey) + 1)
  174. End Function
  175. Private Function RemoveHotKey(ByVal sCaption As String)
  176.     Dim k As Integer
  177.     'Strip the ampersand and return the word
  178.     If Len(sHotKey) = 0 Then
  179.         RemoveHotKey = sCaption
  180.         Exit Function
  181.     End If
  182.     RemoveHotKey = Left$(sCaption, InStr(sCaption, "&") - 1) & Right$(sCaption, Len(sCaption) - InStr(sCaption, "&"))
  183. End Function
  184. Private Sub CheckWords()
  185.     Dim sCheckWord As String
  186.     Dim lSpot As Long
  187.     Dim lTempSpot As Long
  188.     Dim lSpcSpot As Long
  189.     Dim bLastWord As Boolean
  190.     Dim lRetWords As Long
  191.     If bDontCheck Then Exit Sub
  192.     If Len(rtfSpell.Text) = 0 Then Exit Sub
  193.     Screen.MousePointer = 13
  194.     If lStart = 0 Then lStart = 1
  195.     'Loop through the text box and get one word at a time and then spell check it
  196.     If InStr(lStart, rtfSpell.Text, " ") Or (InStr(lStart, rtfSpell.Text, vbCrLf) > 0) Then
  197.         Do Until (InStr(lStart, rtfSpell.Text, " ") = 0) And (InStr(lStart, rtfSpell.Text, vbCrLf) = 0)
  198.             If lStart = 1 Then
  199.                 If Left$(rtfSpell.Text, 1) <> Chr$(32) Then
  200.                     lSpot = 1
  201.                 Else
  202.                     lSpot = InStr(lStart, rtfSpell.Text, " ") + 1
  203.                 End If
  204.             Else
  205.                 lSpot = InStr(lStart, rtfSpell.Text, " ")
  206.             End If
  207.             lSpcSpot = InStr(lSpot + 1, rtfSpell.Text, " ")
  208.             
  209.             If (lSpcSpot = 0) Then
  210.                 lSpcSpot = Len(rtfSpell.Text) + 1
  211.                 bLastWord = True
  212.             End If
  213.             
  214.             'Get the word
  215.             sCheckWord = Mid$(rtfSpell.Text, lSpot, lSpcSpot - lSpot)
  216.             
  217.             'The FixWord function checks the word for a number of things
  218.             lSpot = FixWord(lSpot, sCheckWord)
  219.             
  220.             If Len(Trim$(sCheckWord)) Then
  221.                 'GetSuggestions populates the list box with suggestions for the misspelled word
  222.                 lRetWords = GetSuggestions(sCheckWord)
  223.                 If (lRetWords > 0) Then
  224.                     'If the list count is > 0 then the word was not found in the dictionary
  225.                     If (lstCorrect.ListCount > 0) Then
  226.                         'Show the word
  227.                         lblFind = sCheckWord
  228.                         'select it in the text box containing the var/or caption assignment
  229.                         rtfSpell.SelStart = lSpot - 1
  230.                         rtfSpell.SelLength = Len(sCheckWord) + Len(sHotKey)
  231.                         'Save the end spot of the word in the text box
  232.                         lStart = lSpcSpot - 1
  233.                         Screen.MousePointer = 0
  234.                         Exit Sub
  235.                     End If
  236.                 ElseIf lRetWords < -1 Then
  237.                     Screen.MousePointer = 0
  238.                     Exit Sub
  239.                 End If
  240.             Else
  241.                 lSpcSpot = lSpcSpot + 1
  242.             End If
  243.             lStart = lSpcSpot
  244.             sCheckWord = ""
  245.         Loop
  246.     End If
  247.     If bLastWord Then GoTo FinishJob
  248.     Screen.MousePointer = 0
  249.     'If we got here then all of the words in the text box have been checked.
  250.     'Click cmdStart_Click to select the next item and start the process again.
  251.     cmdStart_Click
  252.     Exit Sub
  253. FinishJob:
  254.     Screen.MousePointer = 0
  255.     cmdStart_Click
  256.     'MsgBox "Spell check is complete.", 64, App.Title
  257. End Sub
  258. Private Function FixWord(lSpot As Long, sWordToFix As String) As Long
  259. '    On Error Resume Next
  260.     Dim lCount As Long
  261.     Dim bFoundOne As Boolean
  262.     Dim k As Long
  263.     If Len(sWordToFix) = 0 Then
  264.         FixWord = lSpot
  265.         Exit Function
  266.     End If
  267.     sHotKey = ""
  268.     'If its a caption with a hot key then get the char
  269.     'just after the ampersand
  270.     If InStr(sWordToFix, "&") > 0 Then
  271.         sHotKey = Mid$(sWordToFix, InStr(sWordToFix, "&") + 1, 1)
  272.     End If
  273.     'Get rid of puncuation, brackets, parenthesis, etc
  274.     Select Case Asc(Right$(sWordToFix, 1))
  275.         Case 33, 44, 46, 58, 59, 63, 125, 41, 93, 13, 10, 61
  276.             sWordToFix = Left$(sWordToFix, Len(sWordToFix) - 1)
  277.             'lSpot = lSpot - 1
  278.     End Select
  279.     If Len(sWordToFix) = 0 Then
  280.         FixWord = lSpot
  281.         Exit Function
  282.     End If
  283.     'Again for the other side
  284.     Select Case Asc(Left$(sWordToFix, 1))
  285.         Case 40, 91, 123, 13, 10
  286.             sWordToFix = Right$(sWordToFix, Len(sWordToFix) - 1)
  287.             'lSpot = lSpot + 1
  288.     End Select
  289.     If Len(sWordToFix) = 0 Then
  290.         FixWord = lSpot
  291.         Exit Function
  292.     End If
  293.     Select Case Asc(Left$(sWordToFix, 1))
  294.         Case 32
  295.             sWordToFix = Right$(sWordToFix, Len(sWordToFix) - 1)
  296.             lSpot = lSpot + 1
  297.     End Select
  298.     'Strip any vbCrLf
  299.     Do Until Left$(sWordToFix, 2) <> vbCrLf
  300.         If Left$(sWordToFix, 2) = vbCrLf Then
  301.             sWordToFix = Right$(sWordToFix, Len(sWordToFix) - 2)
  302.             lSpot = lSpot + 2
  303.         End If
  304.     Loop
  305.     'See if we've already confirmed this word to be spelled correctly
  306.     lCount = UBound(sAlready)
  307.     For k = 0 To lCount - 1
  308.         If sAlready(k) = sWordToFix Then
  309.             sWordToFix = ""
  310.             bFoundOne = True
  311.             Exit For
  312.         End If
  313.     Next
  314.     'If not add it to the list.
  315.     'If the word is incorrect it will be removed.
  316.     If Not bFoundOne Then
  317.         ReDim Preserve sAlready(lCount + 1)
  318.         sAlready(lCount) = sWordToFix
  319.     End If
  320.         
  321.     FixWord = lSpot
  322. End Function
  323. Private Function GetSuggestions(sWord As String) As Long
  324.     lstCorrect.Clear
  325.     txtSpell.Text = ""
  326.     On Error GoTo NoWord2
  327.     'Strip any ampersand from the word
  328.     sWord = RemoveHotKey(sWord)
  329.     'Check the Word 8 dictionary
  330.     Set SpErrors = SpellIt.GetSpellingSuggestions(Word:=sWord)
  331.     If InStr(sWord, "~-") > 0 Then GoTo NoWord2
  332.     GetSuggestions = SpErrors.Count
  333.     'The word was found in the dictionary and there are suggestions
  334.     If SpErrors.Count > 0 Then
  335.         'Loop through the words returned from the dictionary.
  336.         'Add back an ampersand for the hot key if necessary.
  337.         For Each SplError In SpErrors
  338.           lstCorrect.AddItem AddHotKey(SplError.Name)
  339.         Next SplError
  340.         lstCorrect.Enabled = True
  341.     'The word was spelled correctly - do nothing
  342.     ElseIf SpellIt.CheckSpelling(Word:=sWord) Then
  343.         GetSuggestions = -1
  344.     'The word was not found in the dictionary and there was no suggestions
  345.     Else
  346.         GetSuggestions = 1
  347.         lstCorrect.AddItem "(No Suggestion)"
  348.         txtSpell.Text = sWord
  349.         SelectIt txtSpell
  350.         lstCorrect.Enabled = False
  351.     (sWord)
  352. .CheckSpelSpelSpelSpelSpelSpelSpelSpelR the text = 'Check d back an ampersannrdse
  353.   rthe text = 'Check d back an amlxi     End If
  354.         lR
  355.     ElseIf Spell1cmdStactly
  356. l83k an ampers= 'Ct     dictionary.
  357.  Rnpersand for the hot key if ne.
  358.  Rnpersad for the hot
  359.