FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Algoritmo Modulo 11
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Algoritmo Modulo 11
Posted: Wed Mar 22, 2023 11:56 AM
Buenas estimados

Por me ayudan a convertir 茅ste c贸digo a Fivewin
Code (fw): Select all Collapse
public String calculaDigitoMod11(String cadena, int numDig, int limMult, boolean x10)

{
int mult, suma, i, n, dig; 
if (!x10) numDig = 1;
for(n = 1; n <= numDig; n++) {
聽 聽suma = 0;
聽 聽mult = 2; 
聽 聽for(i = cadena.length() - 1; i >= 0; i--) {
聽 聽suma += (mult * Integer.parseInt(cadena.substring(i, i + 1)));
聽 聽if(++mult > limMult) mult = 2;
聽 聽 聽}
聽 聽if (x10) {
聽 聽 聽dig = ((suma * 10) % 11) % 10;
聽 聽 聽}
聽 聽else {
聽 聽 dig = suma % 11;
聽 聽} 聽 聽 聽 聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 聽if (dig == 10) {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cadena += "1";
聽 聽 聽 聽 聽 聽 聽}
聽 聽 聽 聽 聽 聽 聽if (dig == 11) {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cadena += "0";
聽 聽 聽 聽 聽 聽 聽}
聽 聽 聽 聽 聽 聽 聽if (dig < 10) {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cadena += String.valueOf(dig);
聽 聽 聽 聽 聽 聽 聽} 聽 聽 
}
聽 聽 return cadena.substring(cadena.length() - numDig, cadena.length());

}
Ejemplo de consumo del m茅todo:
Code (fw): Select all Collapse
聽 public String obtenerModulo11(String pCadena) {
聽 聽 String vDigito = calculaDigitoMod11(pCadena, 1, 9, false);
聽 聽 聽return vDigito;
}
Gracias por la ayuda
Saludos,



Adhemar C.
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Algoritmo Modulo 11
Posted: Wed Mar 22, 2023 01:41 PM
buenos dias mejor escribela en HB aca un ejemplo
Code (fw): Select all Collapse
****************************************************************************
* 聽calculo del modulo 11 para cualquier valor numerico o de caracteres
* 聽acepta caracteres o numeros enteros
* 聽este tiene dos excepciondes para el sri
* 聽si el digito verificador es 11 se le pone como 0
* 聽si el digito verificador es 10 se le pone como 1
* 聽Copyright Wilson 'W' Gamboa A
* 聽Fecha de creaci贸n 聽 聽 聽 聽 聽: 26 de Marzo del 2014
* 聽Fecha ultima Modificaci贸n 聽: 26 de Marzo del 2014
* 聽Parte del proyecto fe
****************************************************************************

function wg_modulo11( Num )

聽 聽 local cNum := if ( valtype( Num ) == 'C', alltrim( Num ), alltrim( str( int( Num ) ) ) )
聽 聽 local nLen := len( cNum )
聽 聽 local i
聽 聽 local cCar
聽 聽 local nCar
聽 聽 local Cnt 聽:= 0
聽 聽 local aMulti := { 2, 3, 4, 5, 6, 7}
聽 聽 local nDigitoMul
聽 聽 local nSub
聽 聽 local nSuma := 0
聽 聽 local nDigitoVerificador
聽 聽 local aResult := {}
聽 聽 local nCount 聽:= nLen

聽 聽 while nCount > 0
聽 聽 聽 聽 i 聽 聽= nCount
聽 聽 聽 聽 cCar = substr( cNum, i, 1 )
聽 聽 聽 聽 ncar = val( cCar )
聽 聽 聽 聽 ++Cnt
聽 聽 聽 聽 if Cnt > 6
聽 聽 聽 聽 聽 聽 Cnt = 1
聽 聽 聽 聽 end
聽 聽 聽 聽 nDigitoMul = aMulti[ Cnt ]
聽 聽 聽 聽 nSub 聽 聽 聽 = ncar * nDigitoMul
聽 聽 聽 聽 nSuma 聽 聽 聽+= nSub
聽 聽 聽 聽 nCount --
聽 聽 聽 聽 /*
聽 聽 聽 聽 aadd( aResult , ' i = ' + alltrim( str( i ) ) + ' cCar = ' + cCar + ' dig mult= ' + str( nDigitoMul,1 ) )
聽 聽 聽 聽 */
聽 聽 end

聽 聽 nMod = int ( nSuma % 11 )

聽 聽 nDigitoVerificador = 11 - nMod

聽 聽 //OJO alteraci贸n para el SRI

聽 聽 if nDigitoVerificador == 11
聽 聽 聽 聽 nDigitoVerificador = 0
聽 聽 end

聽 聽 if nDigitoVerificador == 10
聽 聽 聽 聽 nDigitoVerificador = 1
聽 聽 end

/*
聽 聽 聽 聽 aadd( aResult , ' sub = ' + alltrim( str( nSuma ) ) )
聽 聽 聽 聽 aadd( aResult , ' mod = ' + alltrim( str( nMod ) ) )
聽 聽 聽 聽 aadd( aResult , ' dig = ' + alltrim( str( nDigitoVerificador ) ) )

聽 聽 achoice( 1, 2, 15, 40, aResult )

*/


Return nDigitoVerificador
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Algoritmo Modulo 11
Posted: Wed Mar 22, 2023 02:50 PM

Muchas gracias estimado Wilson

Funcion贸 perfecto.

Saludos,



Adhemar C.

Continue the discussion