FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Mon May 11, 2015 11:04 PM
Code (fw): Select all Collapse
Se帽ores... Buenas noches

uso : fwh 15.01 + xharbour.com (12.3)

Requiero retornar un valor a trav茅s de una funci贸n, usando un par谩metro por referencia y obtengo valores diferentes si lo hago desde un GET:VALID 聽o silo hago invocando la funci贸n directamente :

FUNCTION capturaValorTexto(nCanTar,nUniMed,nPreAdi)

LOCAL oDlgBr1, 聽oCanTem, oBotAce
LOCAL oWndAct := GetWndDefault()
LOCAL lEstFun := .T.

nUniMed := 32 聽

set decimals to 6

PUBLIC cCanTem := SPACE(16)


DEFINE DIALOG oDlgBr1 TITLE HB_OEMTOANSI("Registro de cantidades") ;
聽 聽 聽 聽 聽 聽FROM 125, 100 TO 280,550 ;
聽 聽 聽 聽 聽 聽OF oWndAct PIXEL

聽 聽@ 25,05 SAY "Cantidad " 聽;
聽 聽 聽 聽 聽 聽PIXEL SIZE 60,20 ;
聽 聽 聽 聽 聽 聽COLOR CLR_BLUE FONT M->oFonAc1 OF oDlgBr1

聽 聽@ 15,70 GET oCanTem VAR cCanTem OF oDlgBr1 ; 聽 // cCanTem := "1*1" 
聽 聽 聽 聽 聽 聽PICTURE "XXXXXXXXXXXXXXXX" ;
聽 聽 聽 聽 聽 聽PIXEL SIZE 120,25 ;
聽 聽 聽 聽 聽 聽UPDATE ;
聽 聽 聽 聽 聽 聽COLOR CLR_WHITE,CLR_GREEN FONT M->oFonAc8 ;
聽 聽 聽 聽 聽 聽VALID ( convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi) 聽 ) 聽 
//esta es la funci贸n 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽1*1, 0 , 32 聽 聽 聽 聽 聽

聽 聽@ 50, 100 BUTTONBMP oBotAce PROMPT "Aceptar";
聽 聽 聽 聽 聽 聽 聽ACTION ( oDlgBr1:END() ) 聽;
聽 聽 聽 聽 聽 聽 聽SIZE 40,16 PIXEL OF oDlgBr1


ACTIVATE DIALOG oDlgBr1 聽CENTER ON INIT ( oCanTem:SetFocus() )

// VALORES RETORNADOS
ALERT(nCanTar) 聽// 0.031000
ALERT(M->xCanSug) // 0.031250

// INVOCANDO LA FUNCION DIRECTAMENTE

/* cCanTem := "1*1"
聽 聽nUniMed := 32 
聽 nCanTar := 0

convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi)

// VALORES RETORNADOS
ALERT(nCanTar) 聽// 0.031250
ALERT(M->xCanSug) // 0.031250 聽VARIABLE PUBLICA

*/


RETURN 聽lEstFun

//***************************************************************

FUNCTION convierteSartaValores(cCanTem,nCanTar,nUniMed,oDlgBr1,oBotAce,lEstFun,nPreAdi)


LOCAL nCanTmo := 0 聽, nvlrCa1 := nvlrCa2 := nvlrCa3 := 0
LOCAL nPosIni := 0
LOCAL nPosFin := 0 , cCanTe2 := ""
LOCAL nCanFac := 0

set decimals to 6

nPosIni := ATNUM('*',cCanTem,1)
cCanTe2 := SUBS(cCanTem,nPosIni+1)
nPosFin := ATNUM('*',cCanTe2,1)
IF nPosFin > 0
聽 聽nPosFin += nPosIni
ENDIF

// PARA EL EJP. CONVIERTE EL TEXTO "1*1" => 1
IF nPosIni > 0
聽 聽IF nPosFin > 0
聽 聽 聽 nvlrCa1 := VAL(SUBS(cCanTem,1,nPosIni-1))
聽 聽 聽 nvlrCa2 := VAL(SUBS(cCanTem,nPosIni+1,nPosFin-1))
聽 聽 聽 nvlrCa3 := VAL(SUBS(cCanTem,nPosFin+1))
聽 聽 聽 nCanTmo := ( nvlrCa1 * nvlrCa2 * nvlrCa3 )
聽 聽 聽 nCanFac := 聽nvlrCa1 * ( nvlrCa2 + nvlrCa3 )
聽 聽ELSE
聽 聽 聽 nvlrCa1 := VAL(SUBS(cCanTem,1,nPosIni-1))
聽 聽 聽 nvlrCa2 := VAL(SUBS(cCanTem,nPosIni+1))
聽 聽 聽 nCanTmo := ( nvlrCa1 * nvlrCa2 )
聽 聽 聽 nCanFac := nvlrCa2
聽 聽ENDIF

聽 聽M->vMenReg[3] := cCanTem
ELSE
聽 聽nCanFac := 0
聽 聽nCanTmo := VAL(cCanTem)
聽 聽nCanTar := nCanTmo
聽 聽M->xCanSug := nCanTar
聽 聽lEstFun := .F.
聽 聽RETURN .T.
ENDIF

nPreAdi := nCanFac

nCanTar := ( nCanTmo / nUniMed ) 聽// ESTA ES LA OPERACION FINAL => ( 1 / 32 )

M->xCanSug := nCanTar 聽 聽 // VARIABLE PUBLICA

lEstFun := .T.

RETURN 

//***************************************************************

JOHNSON RUSSI
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Tue May 12, 2015 10:38 AM

No parece que est茅s modificando cCanTem desde la funci贸n

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Tue May 12, 2015 11:25 AM

Antonio..

La variable es "nCanTar" , convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi),
el hecho es que si la modifica pero la retorna redondeada a tres decimales

Posts: 601
Joined: Wed Jul 04, 2007 03:51 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Fri May 15, 2015 01:21 PM
Hola,
Prueba lo siguiente:

Code (fw): Select all Collapse
SET DECIMALS TO nDecimal // NUMERO DE DECIMALES QUE NECESITES
nCanTar := ( nCanTmo / nUniMed )
SET DECIMALS TO 3 // VUELVES AL VALOR


Espero te sirva la idea.
Saludos,
Ojeda Esteban Eduardo.

Buenos Aires - Argentina.

FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport

Skype: jreduojeda
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Sat May 16, 2015 12:48 AM

ya lo tengo definido...
set decimals to 6

el problema se da si llamo la funci贸n desde el action de un get... porque de forma directa funciona bien

Gracias por su respuesta....

Si alguien tiene el tiempo podemos programar una conexi贸n remota tipo team viewer y les muestro directamente el funcionamiento en el retorno de la funci贸n

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Sat May 16, 2015 05:33 PM
En tu c贸digo:

Code (fw): Select all Collapse
   @ 15,70 GET oCanTem VAR cCanTem OF oDlgBr1 ;   // cCanTem := "1*1" 
           PICTURE "XXXXXXXXXXXXXXXX" ;
           PIXEL SIZE 120,25 ;
           UPDATE ;
           COLOR CLR_WHITE,CLR_GREEN FONT M->oFonAc8 ;
           VALID ( convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi)   )


la variable cCanTem es la que se muestra en el GET.

Luego si el valor del GET tiene que cambiar entonces cCanTem deber铆a ser modificado.

Tal vez no estoy entendiendo el problema
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Sat May 16, 2015 08:53 PM

Antonio...

Buena tarde ...

La secuencia es esta :
1. Capturo un texto con este formato "11" -> un trozo de lamina de un metro --> en la variable "cCanTem"
2. el m茅todo convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi) , recibe la variable : cCanTem, como una sarta, la convierte en num茅rica y la regresa como numerica en la varibale @nCanTar ( asi nCanTar := VAL(1)
VAL(1) / 32 (valor final para este ejemplo)
3. El valor de retorno en nCanTar, es el que evalu贸 ---> ALERT(nCanTar) // 0.031000

/// resumen del c贸digo
@ 15,70 GET oCanTem VAR cCanTem OF oDlgBr1 ; // cCanTem := "1*1"
PICTURE "XXXXXXXXXXXXXXXX" ;
PIXEL SIZE 120,25 ;
UPDATE ;
COLOR CLR_WHITE,CLR_GREEN FONT M->oFonAc8 ;
VALID ( convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi) )

ACTIVATE DIALOG oDlgBr1 CENTER ON INIT ( oCanTem:SetFocus() )

// VALORES RETORNADOS
ALERT(nCanTar) // 0.031000
convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi)
ALERT(nCanTar) // 0.031250

Nota : Antonio como puede notar en el c贸digo inicial invoco la funci贸n convierteSartaValores(), desde el get y directamente y retorna estos valores : 0.031000 y 0.031250 respectivamente.

Nota: La variable que debe almacenar el valor final es nCanTar , que a su vez llega como par谩metro a la funci贸n :
FUNCTION capturaValorTexto(nCanTar,nUniMed,nPreAdi), ahora si declaro la variable nCanTar como local en este m茅todo el valor retornado por ambas invocaciones es igual (0.031250 ) => divisi贸n de 1 / 32 , con set decimals to 6

Johnson Russi

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Sun May 17, 2015 07:45 PM

ok entendido, entend铆 que el valor modificado ten铆a que llegar al GET

Tienes definido set decimals to 6 antes de llamar a la funci贸n capturaValorTexto() ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 411
Joined: Sun Jan 31, 2010 03:30 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Mon May 18, 2015 01:29 AM

Antonio

Buena noche

  1. Uso : "set decimals to 6" en todo el .prg
  2. Llegue a la siguiente conclusi贸n : si la variable nCanTar, usada asi : "VALID ( convierteSartaValores(cCanTem,@nCanTar,nUniMed,oDlgBr1,oBotAce,@lEstFun,@nPreAdi) )", es una variable local la retorna con los 6 decimales y si es publica(dese el inicio de la aplicaci贸n ) , la retorna modificada pero con tres decimales.
  3. Por Ahora , es la soluci贸n que le di... usarla como local y luego asign谩rsela a la variable final(la publica)
  4. Si usted considera ver el caso en ejecuci贸n estar茅 atento a su disposici贸n de tiempo para una asistencia remota

Gracias

Saludos

Johnson Russi Tello

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ayuda : Retorno de GET VALID + FUNCTION(@variable)
Posted: Mon May 18, 2015 07:15 AM

Johnson,

Si te funciona bien, eso es lo que cuenta :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion