Page 1 of 1

No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 2:24 pm
by jvtecheto
Hola amigos:

Perdon por no ser un tema de Fivewin, pero ...

No existe DEFAULT en Harbour.?

aquello que se hacia en Clipper en los parametros de las funciones.
Code: Select all  Expand view


FUNCTION CualquierCosa(nCantidad,lValor)

DEFAULT lValor := .T. // No existe en Harbour.

// Codigo....

RETURN nCantidad
 


Como se asignaria ese valor por defecto , caso que no se especifique.?

Repito perdon por no ser de Fivewin.

Saludos y Enhorabuena a este grupo tan numeroso y colaborativo, no cambieis.

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 2:36 pm
by cnavarro
Intenta asi
Code: Select all  Expand view

   hb_default( lValor, .T. )
 

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 3:08 pm
by jvtecheto
Gracias por tu interes Cristobal.

No tengo error de compilacion, pero no funciona bien, sino especifico el valor por defecto en la funcion, el programa se queda esperando sin hacer nada.

El codigo es este, es una funcion de conversion de pesetas a Euros y viceversa que realice en su dia en clipper. Y ahora como estoy mirando de volver a
Xbase con Harbour, jaja, ya he visto a mas de uno y me han dado envidia. :D
FUNCTION Ptas2Eur(nCantidad,lEuro) // Si .T. Ptas -> Euro, .F. Euro->Ptas

Local nEntero,nDecimal
Local c2Decimales,c3Decimal

// DEFAULT lEuro:=.T. error en Harbour
hb_default( lEuro, .T. )
// De Ptas. a Euros
IF lEuro
nEntero:=INT(nCantidad / EURO) // parte entera
nDecimal:=( (nCantidad / EURO)-nEntero ) * 1000
c2Decimales:=SUBSTR(STR(nDecimal,3),1,2)
c3Decimal:=SUBSTR(STR(nDecimal,3),3,1) // cogemos el 3er decimal
IF VAL(c3Decimal) >= 5 // sumar 0,01
nDecimal:=(VAL(c2Decimales))/100 + 1/100
ELSE
nDecimal:=VAL(c2Decimales)/100
ENDIF
nCantidad:=nEntero+nDecimal
ELSE
nCantidad:=ROUND((nCantidad * EURO),0)
ENDIF

RETURN (nCantidad)



Ya se que habran funciones mucho mejor estructurdas y rapidas :) , pero me gustaba hacermelo a mi a mi manera.
Os puedo asegurar que funcionaba bien.

Saludos.

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 3:17 pm
by cnavarro
Disculpa, Intenta asi
Code: Select all  Expand view

   hb_default( @lValor, .T. )
 


también puedes usar algo habitual

Code: Select all  Expand view

if hb_IsNil( lValor )
   lValor := .T.
endif
 

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 5:22 pm
by jvtecheto
Ahora si, perfecto Cristobal, ambas soluciones.

Repito gracias.

Saludos.

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 6:21 pm
by Xevi
Siempre te puede servir If(...

Code: Select all  Expand view

lValor := If( lValor = Nil, .T., lValor )
 


Otra forma de hacer tuDefault

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 10:06 pm
by surGom
Yo hice esta prueba
Code: Select all  Expand view
static prueba
//etc te

 MENUITEM "Ocasionales..."       ACTION  prueba() ;

///ETC

 static function prueba()
 
 default nprueba := 100

 MsgStop(nprueba)
 return nil


y muestra 100

Con Harbour3.2

Me intrigo porque tengo varios sistemas con harbour y utilizo el DEfault en varias ocasiones.
Ahora que estoy escribiendo no tendrás que compilar xhb.lib?

Luis

Re: No existe DEFAULT en Harbour

PostPosted: Sat Jan 13, 2018 10:47 pm
by cnavarro
Luis, yo también creo que si

Re: No existe DEFAULT en Harbour

PostPosted: Tue Jan 16, 2018 9:31 am
by mastintin
si que existe ...
en harbour/include/common.ch
Code: Select all  Expand view


#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn> ] => ;
                                IF <v1> == NIL ; <v1> := <x1> ; END ;
                                [; IF <vn> == NIL ; <vn> := <xn> ; END ]

 


si quieres que funcione con la igualdad , incluye en el archivo :
Code: Select all  Expand view


#xcommand DEFAULT <uVar1> := <uVal1> ;
               [, <uVarN> := <uValN> ] => ;
                  If <uVar1> == nil ; <uVar1> := <uVal1>;END ;
                [ ; If <uVarN> == nil ; <uVarN> := <uValN>;END ]

 

Re: No existe DEFAULT en Harbour

PostPosted: Tue Jan 16, 2018 11:01 am
by Antonio Linares
FWH proporciona DEFAULT en FiveWin.ch:

Code: Select all  Expand view

#xcommand DEFAULT <uVar1> := <uVal1> ;
               [, <uVarN> := <uValN> ] => ;
                  If( <uVar1> == nil, <uVar1> := <uVal1>, ) ;;
                [ If( <uVarN> == nil, <uVarN> := <uValN>, ); ]
 

Re: No existe DEFAULT en Harbour

PostPosted: Tue Jan 16, 2018 1:48 pm
by Rick Lipkin
This is how I look for passed values that may be null .. that goes also for Sql values that may be nil as well ..

Code: Select all  Expand view

If empty(lValue)
   lValue := .t.
Endif
 


Rick Lipkin

Re: No existe DEFAULT en Harbour

PostPosted: Tue Jan 16, 2018 6:27 pm
by carlos vargas
Por defecto tanto clipper como harbour por si solo:
Code: Select all  Expand view

#include "common.ch"
DEFAULT cVar TO "carlos"
 


con fivewin:
Code: Select all  Expand view

#include "fivewin.ch"
DEFAULT cVar := "carlos"
 


salu2
carlos vargas

Re: No existe DEFAULT en Harbour

PostPosted: Tue Jan 16, 2018 6:29 pm
by cnavarro
Si, el tema es este ( no digo que sea el único con el que funcione )
Code: Select all  Expand view

#include "common.ch"