ciao, ho scritto un banalissimo codice per calcolare il cognome per fare il codice fiscale...
ma il problema è che ogni volta che vado a calcolarlo mi dice index out of range (= indice oltre i limiti) e mi sottolinea la seguente riga (che metto in grassetto)
qualcuno mi può illuminare?codice:Public Class FormCodiceFiscale Private Consonanti() As String = {"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z"} Private Vocali() As String = {"A", "E", "I", "O", "U"} Private Function RestituisciCognome(ByVal Cognome As String) As String() Dim i As Integer Dim k As Integer Dim CostantiCognome As Integer = 0 Dim Risultato() As String Dim VocaliCognome As Integer = 0 For i = LBound(Consonanti) To UBound(Consonanti) For k = 0 To Cognome.Length If Cognome(k).ToString = Consonanti(i).ToString Then CostantiCognome += 1 Risultato(CostantiCognome) = Cognome(k).ToString If CostantiCognome = 3 Then Return Risultato End If End If Next Next i = 0 k = 0 For i = LBound(Vocali) To UBound(Vocali) For k = 0 To Cognome If Cognome(k).ToString = Vocali(i).ToString Then VocaliCognome += 1 Risultato(CostantiCognome + VocaliCognome) = Cognome(k).ToString If CostantiCognome + VocaliCognome = 3 Then Return Risultato End If End If Next Next If Risultato.Length < 2 Then For i = LBound(Risultato) To UBound(Risultato) If Risultato(i).ToString = "" Then Risultato(i) = "X" If Risultato.Length = 2 Then Return Risultato End If End If Next End If Return Risultato End Function End Class

Rispondi quotando
