VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A spell-checking code completely written in VB6! You need to create a .txt file that will act as di

by H W Samuel (4 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 18th October 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

A spell-checking code completely written in VB6! You need to create a .txt file that will act as dictionary.Code alerts of misspelt words!

API Declarations



'Programmed by H W Samuel
'[email protected]

'This code was developed based on a VB spell-checing code by
'William Quincy
'[email protected]

'Program Algorithm (real-time processing)
'1.Break sentence into separate words
'2.Compare words in sentence with words in dictionary
'3.Words not matched are assumed to be mis-spelt

'You can freely use this source code in your own applications by just
'mentioning my details as shown above

'This spelling-checking code uses an over-simplistic text file/ dictionary
'that anyone with NotePad can create. Ot won't work without you
'creating and calling one. Each word comes on a separate line in a text
'file. The code will then identify/alert mis-spelt words based on your text file

'To create a sample dictionary, just type some words (each on a
'separate line) in NotePad or any word processor and save as .txt file

'Sample dictionary entries
'ace
'ada
'after
'again
'ajar

'Call the Scan_Words procedure from an activation point
'e.g. Form_Load, CommandButton1_Click, and specify the path of the
'text file as argument along with the name of a valid text box
'At run time, experiment with some words to see whether words not in
'your dictionary are picked out

'Sample calling routine
'Scan_Words Text1, "C:\MyDict.txt"


Rate A spell-checking code completely written in VB6! You need to create a .txt file that will act as di



(txtCTRL As Control, _
ByVal custDICT As String)

'Set your custom dictionary's path and the control that contains the text
'being scanned. This could be a grid or textbox

'These strings will be skipped as they occur in sentences
Const Separators As String = _
" 1234567890-=`~!@#$%^&*()_+{}[]|\:;'<,>.?/" _
& vbCrLf & vbCr & vbLf & vbTab

Dim lSelLen As Long 'Returns position of occurance of any match
Dim lSelBegin As Long 'Sets starting point for checking

Dim lTmpLen As Long 'Similar to above variables, only these are used on
Dim lTmpBegin As Long 'the string of separators

Dim stWordBits As String 'Stores parsed single characters of word
Dim txtLen As Integer 'Sets whole length of string being checed
Dim lLastTxt As Long 'Used to check for separators occuring in sequence

Dim DictNowWord As String 'Used to set the current dictionary word
Dim ScannedWord As String 'Used to store current parsed word
Dim FileSystem, DictFile 'File constants
    
'All pointers are initialized
lSelBegin = 1
lSelLen = 0
lTmpBegin = 1
lTmpLen = 0
lLastTxt = 0

'Initialize dictionary file
Set FileSystem = CreateObject("Scripting.FileSystemObject")

With txtCTRL
txtLen = Len(.Text) + 1
Do Until lSelLen = txtLen
Re_Do:
    'This line sets the start pointer for selecting the current word to look-up
    'It is based on the length of the last word, if any, that was scanned
    lSelBegin = lSelLen + 1

    'This loop tries to detect invalid strings that cannot form sentences
    'It is necessary to scan and find separators as they occur in the main
    'string because there may be more than one type.e.g. spaces, numbers
    Do Until lTmpBegin = txtLen
        'This line breaks a sentence word into separate letters so that we
        'can find any invalid characters
        stWordBits = UCase(Mid(.Text, lTmpBegin, 1))
        
        'This line will return a value greater than 0 if the curent parsed
        'letter is found in the separator string
        lTmpLen = InStr(1, Separators, stWordBits)
        
        lTmpBegin = lTmpBegin + 1
        
        If lTmpLen > 0 Then Exit Do
    Loop
    
    'Now that we have gotten the first occuring separator we can find its
    'occurance in the main text string
    lSelLen = InStr(lSelBegin, .Text, stWordBits)
    
    'This line handles a possible error of lSelLen being reset to 0 (this
    'usually happens after the end of the main string has been reached
    If lSelLen = 0 Then lSelLen = txtLen
        
    'Another error handler
    If lSelLen < lSelBegin Then Exit Do
    
    'Now we set the beginning position and the ending position pointers
    'These pointers will be used to select the text we require
    .SelStart = lSelBegin - 1
    .SelLength = lSelLen - lSelBegin
    
    lLastTxt = InStr(1, Separators, .SelText)
    
    'Another error handler for error occuring when a separator is made the
    'current word. The separator is then rechecked and skipped
    If lLastTxt > 0 Then GoTo Re_Do
    
    ScannedWord = .SelText 'Store current sentence word
    Set DictFile = FileSystem.OpenTextFile(custDICT, 1) 'Open dictionary
    With DictFile
    Do Until .AtEndOfStream = True 'Keep matching each dictionary word
        DictNowWord = .ReadLine 'Read word from dictionary
        If Trim(UCase(DictNowWord)) = _
        Trim(UCase(ScannedWord)) Then GoTo Word_Found 'If match found
    Loop
    .Close 'Close dictionary
    End With
    
    'Alert of misspelt word
    MsgBox Chr(34) & ScannedWord & Chr(34) & _
    " was not found in the custom dictionary", _
    vbExclamation, "Look-up Results"
Word_Found:
Loop
End With
End Sub

Download this snippet    Add to My Saved Code

A spell-checking code completely written in VB6! You need to create a .txt file that will act as di Comments

No comments have been posted about A spell-checking code completely written in VB6! You need to create a .txt file that will act as di. Why not be the first to post a comment about A spell-checking code completely written in VB6! You need to create a .txt file that will act as di.

Post your comment

Subject:
Message:
0/1000 characters