|
|
|
|
|
Dicas
|
|
Visual Basic (Miscelâneas)
|
|
|
Título da Dica: Gerador de CPF
|
|
|
|
Postada em 27/3/2007 por Edimo Aguiar
tej346@gmail.com
Private Sub Command1_Click() Dim pcpf As String Dim co As Integer Dim t As Boolean Do For co = 1 To 11 pcpf = pcpf + Trim(Str(Int(Rnd * 11) + 1)) Next co t = isCPF(pcpf) If t Then: Exit Do pcpf = "" Loop txt.Text = pcpf End Sub Function isCPF(ByVal pcpf As String) As Boolean Dim Conta As Integer, Soma As Integer, Resto As Integer, Passo As Integer isCPF = False: pcpf = Trim(pcpf) If Len(pcpf) <> 11 Then Exit Function End If For Passo = 11 To 12 Soma = 0 For Conta = 1 To Passo - 2 Soma = Soma + Val(Mid(pcpf, Conta, 1)) * (Passo - Conta) Next Resto = 11 - (Soma - (Int(Soma / 11) * 11)) If Resto = 10 Or Resto = 11 Then Resto = 0 If Resto <> Val(Mid(pcpf, Passo - 1, 1)) Then Exit Function End If Next isCPF = True
End Function
|
|
|
|
|