0
顯然我要走出我的陣列邊界。每次嘗試讀取列時,都會出現「下標超出範圍錯誤」。試圖調試它,並在另一列運行它,它絕對有效,但不是在這個特定的。任何提示?走出循環的界限?
Private Sub Form_Load()
Dim curp, fname, lname1, lname2, gender As String, i, pos As Long, asciinum As String, f As Long, validar As Boolean, fechaNac As Date
With Worksheets("sheet1")
For f = 2 To Cells(.Rows.Count, "L").End(xlUp).Row
curp = Cells(f, "L").Value2
fname = Cells(f, "F").Value2
lname1 = Cells(f, "I").Value2
lname2 = Cells(f, "J").Value
gender = Cells(f, "k").Value2
fechaNac = Cells(f, "P").Value2
' works validar = CheckFirstLetter(lname1, curp, 1, f)
' works validar = CheckFirstVowel(lname1, curp, 2, f)
validar = CheckFirstLetter(lname2, curp, 3, f)
' validar = CheckFirstLetter(fname, curp, 4)
' validar = CheckDate(fechaNac, curp, 5)
' validar = CheckGender(gender, curp, 11)
' validar = CheckConsonant(lname1, curp, 12, 2)
' validar = CheckConsonant(lname2, curp, 13, 2)
' pos = posVowel(fname)
' validar = CheckConsonant(fname, curp, 14, pos)
If (validar = True) Then
Cells(f, "N") = "Valido"
Else: Cells(f, "N") = "No Valido"
End If
Next f
End With
End Sub
Function CheckFirstLetter(mystring, text, indexCurp, index) As Boolean
Dim outStr, asciinum, vocal, vocal2 As String, ary As Variant, i As Long
ary = Split(mystring, " ")
vocal = LCase(ary(LBound(ary))) Breaks in this line
vocal2 = LCase(ary(UBound(ary)))
If (vocal = "de" Or vocal = "del") Then
vocal = vocal2
End If
outStr = LCase(Mid(text, indexCurp, 1))
asciinum = LCase(Mid(vocal, 1, 1))
Cells(index, "M") = vocal
Cells(index, "O") = vocal2
If (asciinum = outStr) Then
CheckFirstLetter = True
Else: CheckFirstLetter = False
End If
End Function
2 lbound和ubound的原因是因爲有時字符串有不同的長度,我只想說出最後一個字。但它打破了這個特定的空間。我猜是因爲我沒有指向正確的細胞?
謝謝!