1
我正在嘗試爲Microsoft Access創建一個VBA腳本,該名稱從名稱字段中抽取標題(如Mr.,Mrs.,Dr.等),然後返回一個清晰的特定版本的標題。我試圖製作一個多維數組,其中一列中的標題和另一列中的已清理標題,但是當我嘗試編譯腳本時,出現語法錯誤。我知道語法錯誤是由於多維數組,因爲我基於此前的腳本,以前的腳本只是找到舊的標題,它運行良好。 我錯過了什麼導致這是一個語法錯誤?我沒有正確調用多維數組嗎?無可否認,我是VBA腳本的新手,在編程時會生鏽,所以如果我錯過簡單的東西,請原諒我。嘗試在VBA中創建多維數組時出現語法錯誤
Public Function findTitles(inName) As String
' Returns cleaned up titles
Dim strName As String
Dim strTitle As String
Dim Titles As Variant
Titles = Array(Array("Ms", "Ms."), Array("Miss ", "Miss"), Array("Mrs", "Mrs."), Array("Mr", "Mr."), Array("Master", "Master"), Array("Rev", "Rev."), Array("Reverend", "Reverend"), Array("Fr", "Fr."),Array("Father", "Father"), Array("Dr", "Dr."), Array("Doctor", "Doctor"), Array("Atty", "Atty."), Array("Attorney", "Attorney"),Array("Prof", "Prof."), Array("Professor", "Professor"), Array("Hon", "Hon."), Array("Honorable", "Honorable"), Array("Pres", "Pres."), Array("President", "President"), Array("Gov", "Gov."), Array("Governor", "Governor"))
Dim I
I = 0
strTitle = ""
'Compare input to list of Titles
Do
If inName Like Titles(I, 0) & " *" Then
strTitle = Titles(I, 1)
Else
I = I + 1
End If
Loop While (strTitle = "" And I < UBound(Titles))
cleanTitles = strTitle
End Function
謝謝。你是正確的,數組聲明是錯誤的。 – TKESuperDave 2014-10-01 21:07:14