Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di hkproj
    Registrato dal
    Jul 2006
    Messaggi
    250

    Calcolo del codice fiscale

    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)
    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
    qualcuno mi può illuminare?
    --------------------HkProj------------------

  2. #2
    Non so cosa potrebbe essere, ma metti così,forse funziona:

    If Cognome(k).ToString() = Consonanti(i).ToString() Then


  3. #3
    E un'altra cosa, potrebbe essere quello che appare nel Visual Studio Express!
    Più di qui non so come aiutarti!
    Immagini allegate Immagini allegate

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.