LCRamos
|
GOIANIA GO - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 17/04/2011 19:13 hs
Pessoal tenho esta função, e checa direitinho as inscrições dos estados, mas tem uma que dá inválida, alguém sabe onde está o erro?
Public Function checainsCRICAO(pUF As String, pINSCR As String) As Boolean Dim sTRBASE As String Dim sTRBASE2 As String Dim sTRORIGEM As String Dim sTRDIGITO As String Dim sTRDIGITO1 As String Dim sTRDIGITO2 As String Dim iNTPOS As Long Dim iNTVALOR As Long Dim iNTSOMA As Long Dim iNTRESTO As Long Dim iNTNUMERO As Long Dim iNTPESO As Long Dim iNTDIG As Long sTRBASE = "" sTRBASE2 = "" sTRORIGEM = "" checainsCRICAO = False If Trim(pINSCR) = "ISENTO" Then checainsCRICAO = True Exit Function End If For iNTPOS = 1 To Len(Trim(pINSCR)) sTRDIGITO = Mid$(pINSCR, iNTPOS, 1) Select Case sTRDIGITO Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "P" sTRORIGEM = sTRORIGEM & Mid$(pINSCR, iNTPOS, 1) End Select Next Select Case pUF Case "TO" ' Tocantins If Len(sTRORIGEM) = 9 Then sTRBASE2 = Left(sTRORIGEM, 8) sTRDIGITO = Right$(sTRORIGEM, 1) iNTSOMA = 0 For iNTPOS = 1 To 8 iNTVALOR = Val(Mid$(sTRBASE2, iNTPOS, 1)) iNTVALOR = iNTVALOR * (10 - iNTPOS) iNTSOMA = iNTSOMA + iNTVALOR Next iNTRESTO = iNTSOMA Mod 11 sTRDIGITO1 = Right(IIf(iNTRESTO < 2, "0", Str(11 - iNTRESTO)), 1) If sTRDIGITO1 = sTRDIGITO Then checainsCRICAO = True End If End If End Select Exit Function End Function
Somente no estado do Tocantins, não checa.
vlu//
|
|
|
|
|
Postada em 18/04/2011 14:29 hs
|
|
|
|
Postada em 18/04/2011 14:33 hs
achei esse link na net: http://social.msdn.microsoft.com/Forums/pt-BR/aspnetpt/thread/d878abe3-f5c4-435d-b2a6-768aa0f2e6bd
Inscrição Estadual:
Code Snippet
Public Function retorno(ByVal pUF As String, ByVal pInscr As String) As Boolean
Dim retorno As Boolean = False Dim strBase As String Dim strBase2 As String Dim strOrigem As String Dim strDigito1 As String Dim strDigito2 As String Dim intPos As Integer Dim intValor As Integer Dim intSoma As Integer = 0 Dim intResto As Integer Dim intNumero As Integer Dim intPeso As Integer Dim intDig As Integer strBase = "" strBase2 = "" strOrigem = "" If (pInscr.Trim().ToUpper() = "ISENTO") Then Return True End If For intPos = 1 To pInscr.Trim().Length If (("0123456789P".IndexOf(pInscr.Substring((intPos - 1), 1), 0, System.StringComparison.OrdinalIgnoreCase) + 1) > 0) Then strOrigem = (strOrigem + pInscr.Substring((intPos - 1), 1)) End If Next Select Case pUF.ToUpper() Case "AC" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If ((strBase.Substring(0, 2) = "01") AndAlso (strBase.Substring(2, 2) <> "00")) Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "AL" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "24") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intSoma = (intSoma * 10) intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto = 10),"0",Convert.ToString(intResto))).Substring(((IIf((intResto = 10),"0",Convert.ToString(intResto))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "AM" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While If (intSoma < 11) Then strDigito1 = Convert.ToString((11 - intSoma)).Substring((Convert.ToString((11 - intSoma)).Length - 1)) Else intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) End If strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "AP" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intPeso = 0 intDig = 0 If (strBase.Substring(0, 2) = "03") Then intNumero = Integer.Parse(strBase.Substring(0, 8)) If ((intNumero >= 3000001) AndAlso (intNumero <= 3017000)) Then intPeso = 5 intDig = 0 ElseIf ((intNumero >= 3017001) AndAlso (intNumero <= 3019022)) Then intPeso = 9 intDig = 1 ElseIf (intNumero >= 3019023) Then intPeso = 0 intDig = 0 End If intSoma = intPeso intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor = 10) Then intValor = 0 ElseIf (intValor = 11) Then intValor = intDig End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "BA" strBase = (strOrigem.Trim() + "00000000").Substring(0, 8) If (("0123458".IndexOf(strBase.Substring(0, 1), 0, System.StringComparison.OrdinalIgnoreCase) + 1) > 0) Then intSoma = 0 intPos = 1 While (intPos <= 6) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (8 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 10) strDigito2 = (IIf((intResto = 0),"0",Convert.ToString((10 - intResto)))).Substring(((IIf((intResto = 0),"0",Convert.ToString((10 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 6) + strDigito2) intSoma = 0 intPos = 1 While (intPos <= 7) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * (9 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 10) strDigito1 = (IIf((intResto = 0),"0",Convert.ToString((10 - intResto)))).Substring(((IIf((intResto = 0),"0",Convert.ToString((10 - intResto)))).Length - 1)) Else intSoma = 0 intPos = 1 While (intPos <= 6) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (8 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito2 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 6) + strDigito2) intSoma = 0 intPos = 1 While (intPos <= 7) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * (9 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) End If strBase2 = (strBase.Substring(0, 6) + (strDigito1 + strDigito2)) If (strBase2 = strOrigem) Then retorno = True End If Exit Select
Segue abaixo
ResponderResponder CitaçãoCitação
terça-feira, 26 de agosto de 2008 16:56Eduardo Costa Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário Entrar para Votar 0 Entrar para Votar
Code Snippet
Case "CE" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = 0 End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "DF" strBase = (strOrigem.Trim() + "0000000000000").Substring(0, 13) If (strBase.Substring(0, 3) = "073") Then intSoma = 0 intPeso = 2 intPos = 11 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 9) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 11) + strDigito1) intSoma = 0 intPeso = 2 intPos = 12 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 9) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito2 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 12) + strDigito2) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "ES" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "GO" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (("10,11,15".IndexOf(strBase.Substring(0, 2), 0, System.StringComparison.OrdinalIgnoreCase) + 1) > 0) Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) If (intResto = 0) Then strDigito1 = "0" ElseIf (intResto = 1) Then intNumero = Integer.Parse(strBase.Substring(0, 8)) strDigito1 = (IIf(((intNumero >= 10103105) AndAlso (intNumero <= 10119997)),"1","0")).Substring(((IIf(((intNumero >= 10103105) AndAlso (intNumero <= 10119997)),"1","0")).Length - 1)) Else strDigito1 = Convert.ToString((11 - intResto)).Substring((Convert.ToString((11 - intResto)).Length - 1)) End If strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "MA" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "12") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "MT" strBase = (strOrigem.Trim() + "0000000000").Substring(0, 10) intSoma = 0 intPeso = 2 intPos = 10 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 9) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 10) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "MS" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "28") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select
Segue abaixo
ResponderResponder CitaçãoCitação
terça-feira, 26 de agosto de 2008 16:57Eduardo Costa Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário Entrar para Votar 0 Entrar para Votar
Code Snippet
Case "MG" strBase = (strOrigem.Trim() + "0000000000000").Substring(0, 13) strBase2 = (strBase.Substring(0, 3) + ("0" + strBase.Substring(3, 8))) intNumero = 2 intPos = 1 While (intPos <= 12) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intNumero = (IIf((intNumero = 2),1,2)) intValor = (intValor * intNumero) If (intValor > 9) Then strDigito1 = String.Format("00", intValor) intValor = (Integer.Parse(strDigito1.Substring(0, 1)) + Integer.Parse(strDigito1.Substring((strDigito1.Length - 1)))) End If intSoma = (intSoma + intValor) intPos += 1 End While intValor = intSoma While (String.Format("000", intValor).Substring((String.Format("000", intValor).Length - 1)) <> "0") intValor = (intValor + 1) strDigito1 = String.Format("00", (intValor - intSoma)).Substring((String.Format("00", (intValor - intSoma)).Length - 1)) strBase2 = (strBase.Substring(0, 11) + strDigito1) intSoma = 0 intPeso = 2 intPos = 12 While (intPos <= 1) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 11) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito2 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase2 + strDigito2) If (strBase2 = strOrigem) Then retorno = True End If End While Exit Select Case "PA" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "15") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "PB" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = 0 End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select
Case "PE" strBase = (strOrigem.Trim() + "00000000000000").Substring(0, 14) intSoma = 0 intPeso = 2 intPos = 13 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 9) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = (intValor - 10) End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 13) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "PI" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "PR" strBase = (strOrigem.Trim() + "0000000000").Substring(0, 10) intSoma = 0 intPeso = 2 intPos = 8 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 7) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) intSoma = 0 intPeso = 2 intPos = 9 While (intPos <= 1) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 7) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito2 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase2 + strDigito2) If (strBase2 = strOrigem) Then retorno = True End If Exit Select
Segue abaixo
ResponderResponder CitaçãoCitação
terça-feira, 26 de agosto de 2008 16:59Eduardo Costa Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário Entrar para Votar 0 Entrar para Votar
Code Snippet
Case "RJ" strBase = (strOrigem.Trim() + "00000000").Substring(0, 8) intSoma = 0 intPeso = 2 intPos = 7 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 7) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 7) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "RN" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "20") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intSoma = (intSoma * 10) intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto > 9),"0",Convert.ToString(intResto))).Substring(((IIf((intResto > 9),"0",Convert.ToString(intResto))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "RO" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) strBase2 = strBase.Substring(3, 5) intSoma = 0 intPos = 1 While (intPos <= 5) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * (7 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = (intValor - 10) End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "RR" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) If (strBase.Substring(0, 2) = "24") Then intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 9) strDigito1 = Convert.ToString(intResto).Substring((Convert.ToString(intResto).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "RS" strBase = (strOrigem.Trim() + "0000000000").Substring(0, 10) intNumero = Integer.Parse(strBase.Substring(0, 3)) If ((intNumero > 0) AndAlso (intNumero < 468)) Then intSoma = 0 intPeso = 2 intPos = 9 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 9) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = 0 End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 9) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select Case "SC" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "SE" strBase = (strOrigem.Trim() + "000000000").Substring(0, 9) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) intValor = (11 - intResto) If (intValor > 9) Then intValor = 0 End If strDigito1 = Convert.ToString(intValor).Substring((Convert.ToString(intValor).Length - 1)) strBase2 = (strBase.Substring(0, 8) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If Exit Select
Segue abaixo
ResponderResponder CitaçãoCitação
terça-feira, 26 de agosto de 2008 16:59Eduardo Costa Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário Entrar para Votar 0 Entrar para Votar
Code Snippet
Case "SP" If (strOrigem.Substring(0, 1) = "P") Then strBase = (strOrigem.Trim() + "0000000000000").Substring(0, 13) strBase2 = strBase.Substring(1, 8) intSoma = 0 intPeso = 1 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso = 2) Then intPeso = 3 End If If (intPeso = 9) Then intPeso = 10 End If intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = Convert.ToString(intResto).Substring((Convert.ToString(intResto).Length - 1)) strBase2 = (strBase.Substring(0, 8) + (strDigito1 + strBase.Substring(10, 3))) Else strBase = (strOrigem.Trim() + "000000000000").Substring(0, 12) intSoma = 0 intPeso = 1 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso = 2) Then intPeso = 3 End If If (intPeso = 9) Then intPeso = 10 End If intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = Convert.ToString(intResto).Substring((Convert.ToString(intResto).Length - 1)) strBase2 = (strBase.Substring(0, 8) + (strDigito1 + strBase.Substring(9, 2))) intSoma = 0 intPeso = 2 intPos = 11 While (intPos <= 1) intValor = Integer.Parse(strBase.Substring((intPos - 1), 1)) intValor = (intValor * intPeso) intSoma = (intSoma + intValor) intPeso = (intPeso + 1) If (intPeso > 10) Then intPeso = 2 End If intPos = (intPos + -1) End While intResto = (intSoma Mod 11) strDigito2 = Convert.ToString(intResto).Substring((Convert.ToString(intResto).Length - 1)) strBase2 = (strBase2 + strDigito2) End If If (strBase2 = strOrigem) Then retorno = True End If Exit Select Case "TO" strBase = (strOrigem.Trim() + "00000000000").Substring(0, 11) If (("01,02,03,99".IndexOf(strBase.Substring(2, 2), 0, System.StringComparison.OrdinalIgnoreCase) + 1) > 0) Then strBase2 = (strBase.Substring(0, 2) + strBase.Substring(4, 6)) intSoma = 0 intPos = 1 While (intPos <= 8) intValor = Integer.Parse(strBase2.Substring((intPos - 1), 1)) intValor = (intValor * (10 - intPos)) intSoma = (intSoma + intValor) intPos += 1 End While intResto = (intSoma Mod 11) strDigito1 = (IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Substring(((IIf((intResto < 2),"0",Convert.ToString((11 - intResto)))).Length - 1)) strBase2 = (strBase.Substring(0, 10) + strDigito1) If (strBase2 = strOrigem) Then retorno = True End If End If Exit Select End Select Return retorno End Function
|
|
|
|
Postada em 18/04/2011 14:36 hs
|
|
|
Roßerto
|
SAO PAULO SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 19/04/2011 17:26 hs
|
|
|
LCRamos
|
GOIANIA GO - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 29/04/2011 20:48 hs
Obrigado amigos, a todos vocês, Juan sua dica valeu.
vlu//
|
|
|
|