Validar Inscrição Estadual para qualquer Estado
Com esta função é possível fazer a validação da Inscrição Estadual (IE) para qualquer Estado (UF) da federação.
A Inscrição Estadual é o registro do contribuinte no cadastro do ICMS mantido pela Receita Estadual.
O algorítmo para a validação da IE é um tanto complicado e difícil de ser encontrado já que para cada estado existe uma fórmula.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
<% '------------------------------------------ UF = "ES" inscricao = "080233880" valida = ChecaInscrE(UF,inscricao) response.write(valida) '------------------------------------------ function IIf(condicao,verdadeiro,falso) if(condicao) then IIF = verdadeiro else IIF = falso end if end function Function ChecaInscrE (pUF, pInscr) ChecaInscrE = False Dim strBase Dim strBase2 Dim strOrigem Dim strDigito1 Dim strDigito2 Dim intPos Dim intValor Dim intSoma Dim intResto Dim intNumero Dim intPeso Dim intDig strBase = "" strBase2 = "" strOrigem = "" If Trim(pInscr) = "ISENTO" or Trim(pInscr) = "EX" Then ChecaInscrE = True Exit Function End If For intPos = 1 To Len(Trim(pInscr)) If Instr(1, "0123456789P", Mid(pInscr, intPos, 1), vbTextCompare) > 0 Then strOrigem = strOrigem & Mid(pInscr, intPos, 1) End If Next Select Case pUF Case "AC" 'Acre strBase = Left(Trim(strOrigem) & "000000000", 13) d01 = Cint(mid(strBase,1,1)) d02 = Cint(mid(strBase,2,1)) d03 = Cint(mid(strBase,3,1)) d04 = Cint(mid(strBase,4,1)) d05 = Cint(mid(strBase,5,1)) d06 = Cint(mid(strBase,6,1)) d07 = Cint(mid(strBase,7,1)) d08 = Cint(mid(strBase,8,1)) d09 = Cint(mid(strBase,9,1)) d10 = Cint(mid(strBase,10,1)) d11 = Cint(mid(strBase,11,1)) dv01 = Cint(mid(strBase,12,1)) dv02 = Cint(mid(strBase,13,1)) if d01 <> 0 or d02 <> 1 then ChecaInscrE = false Exit Function end if ds = 4*d01 + 3*d02 + 2*d03 + 9*d04 + 8*d05 + 7*d06 + 6*d07 + 5*d08 + _ 4*d09 + 3*d10 + 2*d11 aux1 = Fix(ds / 11) aux1 = aux1 * 11 aux2 = ds - aux1 ' aux2 é o resto, ou mod digverificador1 = 11 - aux2 if digverificador1 = 10 or digverificador1 = 11 then digverificador1 = 0 'primeiro digito end if ds = 5*d01 + 4*d02 + 3*d03 + 2*d04 + 9*d05 + 8*d06 + 7*d07 + 6*d08 + _ 5*d09 + 4*d10 + 3*d11 + 2*digverificador1 aux1 = Fix(ds / 11) aux1 = aux1 * 11 aux2 = ds - aux1 ' aux2 é o resto, ou mod digverificador2 = 11 - aux2 if digverificador2 = 10 or digverificador2 = 11 then digverificador2 = 0 'primeiro digito end if if digverificador1 = dv01 and digverificador2 = dv02 then ChecaInscrE = true end if Case "AL" ' Alagoas strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "24" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intSoma = intSoma * 10 intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto = 10, "0", Cstr(intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "AM" ' Amazonas strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next If intSoma < 11 Then strDigito1 = Right(Cstr(11 - intSoma), 1) Else intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) End If strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "AP" ' Amapa strBase = Left(Trim(strOrigem) & "000000000", 9) intPeso = 0 intDig = 0 If Left(strBase, 2) = "03" Then intNumero = Fix(Left(strBase, 8)) If intNumero >= 3000001 And intNumero <= 3017000 Then intPeso = 5 intDig = 0 ElseIf intNumero >= 3017001 And intNumero <= 3019022 Then intPeso = 9 intDig = 1 ElseIf intNumero >= 3019023 Then intPeso = 0 intDig = 0 End If intSoma = intPeso For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor = 10 Then intValor = 0 ElseIf intValor = 11 Then intValor = intDig End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "BA" ' Bahia strBase = Left(Trim(strOrigem) & "00000000", 8) If Instr(1, "0123458", Left(strBase, 1), vbTextCompare) > 0 Then intSoma = 0 For intPos = 1 To 6 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (8 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 10 strDigito2 = Right(IIf(intResto = 0, "0", Cstr(10 - intResto)), 1) strBase2 = Left(strBase, 6) & strDigito2 intSoma = 0 For intPos = 1 To 7 intValor = Cint(Mid(strBase2, intPos, 1)) intValor = intValor * (9 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 10 strDigito1 = Right(IIf(intResto = 0, "0", Cstr(10 - intResto)), 1) Else intSoma = 0 For intPos = 1 To 6 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (8 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito2 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 6) & strDigito2 intSoma = 0 For intPos = 1 To 7 intValor = Cint(Mid(strBase2, intPos, 1)) intValor = intValor * (9 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) End If strBase2 = Left(strBase, 6) & strDigito1 & strDigito2 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "CE" ' Ceara strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor > 9 Then intValor = 0 End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "DF" ' Distrito Federal strBase = Left(Trim(strOrigem) & "0000000000000", 13) If Left(strBase, 3) = "073" Then intSoma = 0 intPeso = 2 For intPos = 11 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 9 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 11) & strDigito1 intSoma = 0 intPeso = 2 For intPos = 12 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 9 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito2 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 12) & strDigito2 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "ES" ' Espirito Santo strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "GO" ' Goias strBase = Left(Trim(strOrigem) & "000000000", 9) If Instr(1, "10,11,15", Left(strBase, 2), vbTextCompare) > 0 Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 If intResto = 0 Then strDigito1 = "0" ElseIf intResto = 1 Then intNumero = Cint(Left(strBase, 8)) strDigito1 = Right(IIf(intNumero >= 10103105 And intNumero <= 10119997, "1", "0"), 1) Else strDigito1 = Right(Cstr(11 - intResto), 1) End If strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "MA" ' Maranhão strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "12" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "MT" ' Mato Grosso while len(strOrigem) < 11 strOrigem = "0" & strOrigem wend strBase = Left(Trim(strOrigem) & "000000000", 11) d01 = Cint(mid(strBase,1,1)) d02 = Cint(mid(strBase,2,1)) d03 = Cint(mid(strBase,3,1)) d04 = Cint(mid(strBase,4,1)) d05 = Cint(mid(strBase,5,1)) d06 = Cint(mid(strBase,6,1)) d07 = Cint(mid(strBase,7,1)) d08 = Cint(mid(strBase,8,1)) d09 = Cint(mid(strBase,9,1)) d10 = Cint(mid(strBase,10,1)) dfinal = Cint(mid(strBase,11,1)) ds = 3*d01 + 2*d02 + 9*d03 + 8*d04 + 7*d05 + 6*d06 + 5*d07 + 4*d08 + _ 3*d09 + 2*d10 aux1 = Fix(ds / 11) aux1 = aux1 * 11 aux2 = ds - aux1 if aux2 = 0 or aux2 = 1 then digVerificador = 0 else digVerificador = 11 - aux2 end if if dfinal = digVerificador then ChecaInscrE = true end if Case "MS" ' Mato Grosso do Sul strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "28" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "MG" ' Minas Gerais, aki onde tem FormatNumber ante era format strBase = Left(Trim(strOrigem) & "0000000000000", 13) strBase2 = Left(strBase, 3) & "0" & Mid(strBase, 4, 8) intNumero = 2 For intPos = 1 To 12 intValor = Cint(Mid(strBase2, intPos, 1)) intNumero = IIf(intNumero = 2, 1, 2) intValor = intValor * intNumero If intValor > 9 Then strDigito1 = FormatNumber(intValor, "00") intValor = Cint(Left(strDigito1, 1)) + Cint(Right(strDigito1, 1)) End If intSoma = intSoma + intValor Next intValor = intSoma While Right(FormatNumber(intValor, "000"), 1) <> "0" intValor = intValor + 1 Wend strDigito1 = Right(FormatNumber(intValor - intSoma, "00"), 1) strBase2 = Left(strBase, 11) & strDigito1 intSoma = 0 intPeso = 2 For intPos = 12 To 1 Step -1 intValor = Cint(Mid(strBase2, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 11 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito2 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = strBase2 & strDigito2 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "PA" ' Para strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "15" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "PB" ' Paraiba strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor > 9 Then intValor = 0 End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "PE" ' Pernambuco strBase = Left(Trim(strOrigem) & "00000000000000", 14) intSoma = 0 intPeso = 2 For intPos = 13 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 9 Then intPeso = 1 End If Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor > 9 Then intValor = intValor - 10 End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 13) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "PI" ' Piaui strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "PR" ' Parana strBase = Left(Trim(strOrigem) & "0000000000", 10) intSoma = 0 intPeso = 2 For intPos = 8 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 7 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 intSoma = 0 intPeso = 2 For intPos = 9 To 1 Step -1 intValor = Cint(Mid(strBase2, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 7 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito2 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = strBase2 & strDigito2 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "RJ" ' Rio de Janeiro strBase = Left(Trim(strOrigem) & "00000000", 8) intSoma = 0 intPeso = 2 For intPos = 7 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 7 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 7) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "RN" ' Rio Grande do Norte strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "20" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intSoma = intSoma * 10 intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto > 9, "0", Cstr(intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "RO" ' Rondonia, estado alterado strBase = Left(Trim(strOrigem) & "000000000", 14) d01 = Cint(mid(strBase,1,1)) d02 = Cint(mid(strBase,2,1)) d03 = Cint(mid(strBase,3,1)) d04 = Cint(mid(strBase,4,1)) d05 = Cint(mid(strBase,5,1)) d06 = Cint(mid(strBase,6,1)) d07 = Cint(mid(strBase,7,1)) d08 = Cint(mid(strBase,8,1)) d09 = Cint(mid(strBase,9,1)) d10 = Cint(mid(strBase,10,1)) d11 = Cint(mid(strBase,11,1)) d12 = Cint(mid(strBase,12,1)) d13 = Cint(mid(strBase,13,1)) dfinal = Cint(mid(strBase,14,1)) ds = 6*d01 + 5*d02 + 4*d03 + 3*d04 + 2*d05 + 9*d06 + 8*d07 + 7*d08 + _ 6*d09 + 5*d10 + 4*d11 + 3*d12 + 2*d13 aux1 = Fix(ds / 11) aux1 = aux1 * 11 aux2 = ds - aux1 digVerificador = 11 - aux2 if digVerificador > 9 then resto_do_calculo = digVerificador - 10 else resto_do_calculo = digVerificador end if if dfinal <> resto_do_calculo then ChecaInscrE = false else ChecaInscrE = true end if Case "RR" ' Roraima strBase = Left(Trim(strOrigem) & "000000000", 9) If Left(strBase, 2) = "24" Then intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPos intSoma = intSoma + intValor Next intResto = intSoma Mod 9 strDigito1 = Right(Cstr(intResto), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "RS" ' Rio Grande do Sul strBase = Left(Trim(strOrigem) & "0000000000", 10) intNumero = Cint(Left(strBase, 3)) If intNumero > 0 And intNumero < 468 Then intSoma = 0 intPeso = 2 For intPos = 9 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 9 Then intPeso = 2 End If Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor > 9 Then intValor = 0 End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 9) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If Case "SC" ' Santa Catarina strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "SE" ' Sergipe strBase = Left(Trim(strOrigem) & "000000000", 9) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 intValor = 11 - intResto If intValor > 9 Then intValor = 0 End If strDigito1 = Right(Cstr(intValor), 1) strBase2 = Left(strBase, 8) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If Case "SP" ' São Paulo If Left(strOrigem, 1) = "P" Then strBase = Left(Trim(strOrigem) & "0000000000000", 13) strBase2 = Mid(strBase, 2, 8) intSoma = 0 intPeso = 1 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 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 Next intResto = intSoma Mod 11 strDigito1 = Right(Cstr(intResto), 1) strBase2 = Left(strBase, 8) & strDigito1 & Mid(strBase, 11, 3) Else strBase = Left(Trim(strOrigem) & "000000000000", 12) intSoma = 0 intPeso = 1 For intPos = 1 To 8 intValor = Cint(Mid(strBase, intPos, 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 Next intResto = intSoma Mod 11 strDigito1 = Right(Cstr(intResto), 1) strBase2 = Left(strBase, 8) & strDigito1 & Mid(strBase, 10, 2) intSoma = 0 intPeso = 2 For intPos = 11 To 1 Step -1 intValor = Cint(Mid(strBase, intPos, 1)) intValor = intValor * intPeso intSoma = intSoma + intValor intPeso = intPeso + 1 If intPeso > 10 Then intPeso = 2 End If Next intResto = intSoma Mod 11 strDigito2 = Right(Cstr(intResto), 1) strBase2 = strBase2 & strDigito2 End If If strBase2 = strOrigem Then ChecaInscrE = True End If Case "TO" ' Tocantins strBase = Left(Trim(strOrigem) & "00000000000", 11) If Instr(1, "01,02,03,99", Mid(strBase, 3, 2), vbTextCompare) > 0 Then strBase2 = Left(strBase, 2) & Mid(strBase, 5, 6) intSoma = 0 For intPos = 1 To 8 intValor = Cint(Mid(strBase2, intPos, 1)) intValor = intValor * (10 - intPos) intSoma = intSoma + intValor Next intResto = intSoma Mod 11 strDigito1 = Right(IIf(intResto < 2, "0", Cstr(11 - intResto)), 1) strBase2 = Left(strBase, 10) & strDigito1 If strBase2 = strOrigem Then ChecaInscrE = True End If End If End Select End Function %> |
Carregando...
Você pode se interessar

Artigos
152 visualizações
Artigos
152 visualizações
15 ferramentas de desenvolvimento para melhorar sua produtividade em 2021 sem gastar nada
Carlos L. A. da Silva - 2 de abril de 2021O cenário de desenvolvimento está em constante mudança e muitas vezes uma ferramenta nova pode agilizar muito seu trabalho.

Artigos
150 visualizações
Artigos
150 visualizações
A tecnologia por trás do deep fake de Deep Nostalgia
Carlos L. A. da Silva - 22 de março de 2021Serviço do My Heritage permite "animar" fotos do passado, trazendo vida para seus antepassados. Como isso é possível?

Artigos
138 visualizações
Artigos
138 visualizações
Como se tornar um Engenheiro DevOps em 2021
Carlos L. A. da Silva - 1 de março de 2021A consultora de DevOps e evangelista Nana Janashia apresenta um passo a passo de tudo que você precisa saber para dominar o DevOps em 2021.
2 Responses
Deixe um Comentário
Mais publicações

Notícias
148 visualizações
148 visualizações
Quanto ganha um programador? Confira uma das maiores pesquisas salariais realizadas no Brasil
Redação - 23 de fevereiro de 2021
Artigos
116 visualizações
116 visualizações

Artigos
134 visualizações
134 visualizações

Dicas
120 visualizações
120 visualizações
Muito bacana, obrigado 😀
Pingback: Função para Validar Inscrição Estadual e Formulário (VBA) | Guia do Excel:: Seu melhor site sobre excel do básico ao VBA