FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour funcion C a xBase
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
funcion C a xBase
Posted: Mon Apr 22, 2024 12:43 PM
Hola a todos, amigos del foro.

Tengo la necesidad de usar una funcion que esta hecha en C .

Se puede usar directamente? c贸mo ? o hay que pasarla a xBase?

En caso de que haya que pasarla, puede alguien darme una mano? no tengo idea de C.

Este es el codigo:
Code (fw): Select all Collapse
public bool validarRif(string sRif)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 bool bResultado = false;
聽 聽 聽 聽 聽 聽 int iFactor = 0;

聽 聽 聽 聽 聽 聽 sRif = sRif.Replace("-", "");
聽 聽 聽 聽 聽 聽 if (sRif.Length < 10)
聽 聽 聽 聽 聽 聽 聽 聽 sRif = sRif.ToUpper().Substring(0, 1) + sRif.Substring(1, sRif.Length - 1).PadLeft(9, '0');

聽 聽 聽 聽 聽 聽 聽string sPrimerCaracter = sRif.Substring(0, 1).ToUpper();

聽 聽 聽 聽 聽 聽 switch (sPrimerCaracter)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 case "V": iFactor = 1; break;
聽 聽 聽 聽 聽 聽 聽 聽 case "E": iFactor = 2; break;
聽 聽 聽 聽 聽 聽 聽 聽 case "J": iFactor = 3; break;
聽 聽 聽 聽 聽 聽 聽 聽 case "P": iFactor = 4; break;
聽 聽 聽 聽 聽 聽 聽 聽 case "G": iFactor = 5; break;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 if (iFactor > 0)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 int suma = ((int.Parse(sRif.Substring(8, 1))) * 2)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(7, 1))) * 3)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(6, 1))) * 4)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(5, 1))) * 5)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(4, 1))) * 6)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(3, 1))) * 7)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(2, 1))) * 2)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ((int.Parse(sRif.Substring(1, 1))) * 3)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ (iFactor * 4);

聽 聽 聽 聽 聽 聽 聽 聽 float dividendo = suma / 11;
聽 聽 聽 聽 聽 聽 聽 聽 int DividendoEntero = (int)dividendo;
聽 聽 聽 聽 聽 聽 聽 聽 int resto = 11 - (suma - DividendoEntero * 11);
聽 聽 聽 聽 聽 聽 聽 聽 if (resto >= 10 || resto < 1)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 resto = 0;
聽 聽 聽 聽 聽 聽 聽 聽 if (sRif.Substring(9, 1).Equals(resto.ToString()))
聽 聽 聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 bResultado = true;
聽 聽 聽 聽 聽 聽 聽 聽 }

聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 return bResultado;

聽 聽 聽 聽 }
Se ve muy sencilla y hasta se entiende, pero ya sabemos que en programaci贸n una coma o punto hace la diferencia entre bien y mal.

Como siempre, agradezco de antemano la ayuda que puedan prestarme.

Gracias !!
"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 03:55 PM

This is not C. C does not have a "string" type.

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 03:58 PM

Ok, it is C# under .NET.

Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 04:49 PM

Hello Enrico.

I really don't know anything about C or C# or .NET.

I got the function by searching on google.

If you can help me, I welcome your help.

"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 04:52 PM
Try asking to the AI. :-)
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 04:53 PM

Good idea, i will

Thanks!

"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: funcion C a xBase
Posted: Mon Apr 22, 2024 05:37 PM
Jos茅,

Mira a ver si esta te funciona bien: https://huggingface.co/chat/conversation/66269e0c7016e222bd762b89
Code (fw): Select all Collapse
FUNCTION validarRif( sRif )
聽 聽LOCAL bResultado :=.F.
聽 聽LOCAL iFactor := 0
聽 聽LOCAL sPrimerCaracter
聽 聽LOCAL suma
聽 聽LOCAL dividendo
聽 聽LOCAL DividendoEntero
聽 聽LOCAL resto

聽 聽sRif := StrTran( sRif, "-", "" )
聽 聽IF Len( sRif ) < 10
聽 聽 聽 sRif := Upper( Left( sRif, 1 ) ) + PadL( SubStr( sRif, 2 ), 9, '0' )
聽 聽ENDIF

聽 聽sPrimerCaracter := Upper( Left( sRif, 1 ) )

聽 聽DO CASE
聽 聽 聽 CASE sPrimerCaracter == "V"
聽 聽 聽 聽 聽iFactor := 1
聽 聽 聽 CASE sPrimerCaracter == "E"
聽 聽 聽 聽 聽iFactor := 2
聽 聽 聽 CASE sPrimerCaracter == "J"
聽 聽 聽 聽 聽iFactor := 3
聽 聽 聽 CASE sPrimerCaracter == "P"
聽 聽 聽 聽 聽iFactor := 4
聽 聽 聽 CASE sPrimerCaracter == "G"
聽 聽 聽 聽 聽iFactor := 5
聽 聽ENDCASE

聽 聽IF iFactor > 0
聽 聽 聽 suma := ( Val( SubStr( sRif, 9, 1 ) ) * 2 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 8, 1 ) ) * 3 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 7, 1 ) ) * 4 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 6, 1 ) ) * 5 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 5, 1 ) ) * 6 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 4, 1 ) ) * 7 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 3, 1 ) ) * 2 ) + ;
聽 聽 聽 聽 聽( Val( SubStr( sRif, 2, 1 ) ) * 3 ) + ;
聽 聽 聽 聽 聽( iFactor * 4 )

聽 聽 聽 dividendo := suma / 11
聽 聽 聽 DividendoEntero := Int( dividendo )
聽 聽 聽 resto := 11 - ( suma - DividendoEntero * 11 )
聽 聽 聽 IF resto >= 10.OR. resto < 1
聽 聽 聽 聽 聽resto := 0
聽 聽 聽 ENDIF
聽 聽 聽 IF SubStr( sRif, 9, 1 ) == Str( resto )
聽 聽 聽 聽 聽bResultado :=.T.
聽 聽 聽 ENDIF
聽 聽ENDIF

聽 聽RETURN bResultado
Based on the function logic, I'll calculate some valid RIFs and check if they are correct.

Here are a few examples:

1. `V123456780`
* `suma` = 142
* `dividendo` = 12.909090...
* `DividendoEntero` = 12
* `resto` = 0
* `SubStr( sRif, 9, 1 )` = "0" and `Str( resto )` = "0", so this RIF is valid.

2. `E123456781`
* `suma` = 143
* `dividendo` = 13.0
* `DividendoEntero` = 13
* `resto` = 0
* `SubStr( sRif, 9, 1 )` = "1" and `Str( resto )` = "0", so this RIF is not valid.

3. `J123456782`
* `suma` = 144
* `dividendo` = 13.090909...
* `DividendoEntero` = 13
* `resto` = 1
* `SubStr( sRif, 9, 1 )` = "2" and `Str( resto )` = "1", so this RIF is valid.

4. `P123456783`
* `suma` = 145
* `dividendo` = 13.181818...
* `DividendoEntero` = 13
* `resto` = 2
* `SubStr( sRif, 9, 1 )` = "3" and `Str( resto )` = "2", so this RIF is valid.

5. `G123456784`
* `suma` = 146
* `dividendo` = 13.272727...
* `DividendoEntero` = 13
* `resto` = 3
* `SubStr( sRif, 9, 1 )` = "4" and `Str( resto )` = "3", so this RIF is valid.

Please note that these calculations are based on the function logic provided, and the validity of the RIFs depends on the specific rules and regulations of the Venezuelan RIF system.
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion