字符比较QWERTY键接近错误(访问VBA等效)

时间:2013-08-19 15:53:01

标签: multidimensional-array access-vba vb6 string-comparison user-defined-types

这需要一个解决方案&从VB6迁移到Access的代码如下。 我有一个功能来比较来自VB6的字符,我是VB6的新手用户,主要是在VBA平台上工作。我需要在MS Access中设置一个类或更好的方法,在不使用UDT的情况下逐个字符地检查错字错误。

作为数组的Mytypolist引用以下数据集: QWA WESAQ ERDSW RTFDE TYGFR YUHGT UIJHY IOKJU OPLKI PLO AQWSZ SEDXZA DRFCXSE FTGVCDR GYHBVFT HUJNBGY JIKMNHU KOLMJI LPKO ZASX XZSDC CXDFV VCFGB BVGHN NBHJM MNJK

以上数据用于比较某个字符输入错误的单词.ex。如果我使用A在Auebec而不是我的意思是键入魁北克,我感兴趣的群集是QWA; WESAQ; AQWSZ;或基于接近度的标准英语Qwerty键盘上的任何其他Q排列。这不仅适用于Q,而且适用于整套字母表,无论情况如何,因此c都有自己的错字匹配集群等。

在UDT的VB6设置中(用户定义的类型): '为拼写错误声明UDT类型

Public Type Mytypos
    Rightrkey As String * 1
    PossibleKey As String * 8
End Type
'declare arrays and variable for master list and typos
Public Masterlist() As String
Public Mytypolist(26) As Mytypos
Public Matchkey As Mytypos

以下函数比较两个单词;并通过计算currentpct得分来指定相似度:

Public Function CompareCharacters(ByRef MasterWord As String, _
ByRef Checkword As String, ByRef CurrentPCT As Double, _
ByRef WordVal As Long) As Double

'define function variables
Dim ChrCount As Long
Dim ChrValue As Long
Dim loop1 As Long
Dim loop2 As Long

'define the letter values
If Len(MasterWord) > Len(Checkword) Then
    ChrCount = Len(MasterWord) * 2
Else
    ChrCount = Len(Checkword) * 2
End If

ChrValue = 1 / ChrCount

'say CURRENT PCT has a value of 10%

'check each letter for a match in current word position
For loop1 = 1 To Len(Checkword)

            'check for typo errors (key proximity)
            For loop2 = 0 To UBound(Mytypolist)
                Matchkey = Mytypolist(loop2)
                'if indexkey = letter in masterword
                If Matchkey.Rightrkey = Mid(MasterWord, loop1, 1) Then
                    'does the letter in the checkword exist in the proximity keylist
                    If InStr(1, Matchkey.PossibleKey, Mid(Checkword, loop1, 1), vbTextCompare) > 0 Then
                        'value for letter found in proximity keylist
                        CurrentPCT = CurrentPCT + ChrValue
                    End If
                    Exit For
                End If
            Next loop2

Next loop1
CompareCharacters = CurrentPCT

End Function

如果您可以发布一个可能不会产生编译器问题的数组/类解决方案(VBA中的字符串UDT是个问题)。请立即查看!

1 个答案:

答案 0 :(得分:0)

最好,因为你有一个1个字符到8个字符的东西,只有一个完整的映射。要取代它的东西:

Public Type Mytypos
    Rightrkey As String * 1
    PossibleKey As String * 8
End Type

要:

PossibleKeys(255) As String * 8

这样,每个字符(从0到255)将具有8个字符映射。不需要UDT!