|
Postada em 02/02/2007 22:48 hs
Post seu code por favor
|
|
|
|
|
Postada em 06/02/2007 19:35 hs
O código ficou assim: 'verifica CPF If Opt_Tran_Tipo(1).Value = True Then CPF_Antes = Txt_Tran_Codi For intPos = 1 To Len(Trim(Txt_Tran_Codi)) If InStr(1, "0123456789P", Mid$(Txt_Tran_Codi, intPos, 1), vbTextCompare) > 0 Then strOrigem = strOrigem & Mid$(Txt_Tran_Codi, intPos, 1) End If Next CPF = strOrigem lngSoma = 0 intNumero = 0 intMais = 0 strcampo = Left(CPF, 9) 'Inicia cálculos do 1º dígito For I = 2 To 10 strCaracter = Right(strcampo, I - 1) intNumero = Left(strCaracter, 1) intMais = intNumero * I lngSoma = lngSoma + intMais Next I dblDivisao = lngSoma / 11 lngInteiro = Int(dblDivisao) * 11 intResto = lngSoma - lngInteiro If intResto = 0 Or intResto = 1 Then intDig1 = 0 Else intDig1 = 11 - intResto End If strcampo = strcampo & intDig1 'concatena o CPF com o primeiro digito verificador lngSoma = 0 intNumero = 0 intMais = 0 'Inicia cálculos do 2º dígito For I = 2 To 11 strCaracter = Right(strcampo, I - 1) intNumero = Left(strCaracter, 1) intMais = intNumero * I lngSoma = lngSoma + intMais Next I dblDivisao = lngSoma / 11 lngInteiro = Int(dblDivisao) * 11 intResto = lngSoma - lngInteiro If intResto = 0 Or intResto = 1 Then intDig2 = 0 Else intDig2 = 11 - intResto End If strConf = intDig1 & intDig2 'Caso o CPF esteja errado dispara a mensagem If strConf <> Right(CPF, 2) Then Txt_Tran_Codi = CPF_Antes MsgBox "O CPF informado está incorreto !" & Chr(10) & "(" & strConf & ")", vbCritical, "Erro de informação" Txt_Tran_Codi.SetFocus Exit Sub End If End If 'verifica CNPJ If Opt_Tran_Tipo(0).Value = True Then CNPJ_Antes = Txt_Tran_Codi For intPosj = 1 To Len(Trim(Txt_Tran_Codi)) If InStr(1, "0123456789P", Mid$(Txt_Tran_Codi, intPosj, 1), vbTextCompare) > 0 Then strOrigemj = strOrigemj & Mid$(Txt_Tran_Codi, intPosj, 1) End If Next CNPJ = strOrigemj For Passoj = 5 To 6 Somaj = 0 Flag = Passoj For Contaj = 1 To Passoj + 7 X = Val(Mid(CNPJ, Contaj, 1)) * Flag Somaj = Somaj + X Flag = IIf(Flag > 2, Flag - 1, 9) Next Somaj = Somaj Mod 11 If Passoj = 5 Then Digito1 = IIf(Somaj > 1, 11 - Somaj, 0) CNPJ = Left(CNPJ, Contaj - 1) & Digito1 End If If Passoj = 6 Then Digito2 = IIf(Somaj > 1, 11 - Somaj, 0) Next CNPJ = strOrigemj If (Digito1 <> Val(Mid(CNPJ, 13, 1)) Or Digito2 <> Val(Mid(CNPJ, 14, 1))) Or Not IsNumeric(Right(Txt_Tran_Codi, 1)) Then Txt_Tran_Codi = CNPJ_Antes MsgBox "O CNPJ informado está incorreto !" & Chr(10) & "(" & Digito1 & Digito2 & ")", vbCritical, "Erro de informação" Txt_Tran_Codi.SetFocus Exit Sub End If Txt_Tran_Codi = CNPJ_Antes End If
|
|
|
|