Calculator in Get

Calculator in Get

Postby karinha » Fri May 23, 2014 2:38 pm

maestro, que error és este?

viewtopic.php?f=17&t=3961

Gracias, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7822
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Calculator in Get

Postby lucasdebeltran » Fri May 23, 2014 3:20 pm

Joao,

Please try this:


Code: Select all  Expand view
/*
    =================================================================================
    GetCalc.prg - PopUp-Calculator               (c) copyright: Timm Sodtalbers, 2003
                                                             info@reportdesigner.info
                                                              www.reportdesigner.info
    ---------------------------------------------------------------------------------

    In order to activate the PopUp-Calculator when pressing the space key in numeric
    fields just add this lines in the KeyDown method of the tGet class:

      case nKey == VK_SPACE .AND. ::oGet:Type == "N"
           ShowCalculator( SELF )

    or if you only want to use the calculator with certain get fields:

      oGet:bKeyDown = {|nKey| IIF( nKey == VK_SPACE, ShowCalculator( oGet ), .T. ) }

    History:
    24.6.2003 - if the get field is <> 0 its value will be copied into the calculator
    22.6.2003 - first release

    =================================================================================
*/


#INCLUDE "FiveWin.ch"

#DEFINE SC_TITLE   " Fórmula:"
#DEFINE SC_ERROR1  "El resultado no cabe dentro del campo."
#DEFINE SC_ERROR2  "El valor es incorrecto."
#DEFINE SC_ERROR3  "valor incorrecto"
#DEFINE SC_STOP    "A T E N C I Ó N"


function Main()
   LOCAL oDlg, oGet, oGet2
   LOCAL cCad := "Testing    " // pad("Testing Gets",40)
   LOCAL nNum := 0
   LOCAL dDat := Date()

   Set century On
   Set Date Ansi
   Set Date format "mm/dd/yyyy"

   SET _3DLOOK ON

   DEFINE DIALOG oDlg TITLE "TGet from " + FWDESCRIPTION

   @ 1,    2 SAY "Text..:" OF oDlg
   @ 1,    6 GET oGet VAR cCad OF oDlg SIZE 60, 10 COLOR "W/G" PICTURE "@K"

   @ 1.8,  2 SAY "Number:" OF oDlg
   @ 2,    6 GET oGet2 VAR nNum OF oDlg SIZE 60, 10 PICTURE "9,999,999.99"
oGet2:bKeyDown = {|nKey| IIF( nKey == VK_SPACE, ShowCalculator( oGet2 ), .T. ) }


   @ 2.6,  2 SAY "Date:" OF oDlg
   @ 3,    6 GET oGet VAR dDat PICTURE "@E" OF oDlg SIZE 60, 10  // "@D"
   @ 3,    7 BUTTON "&Ok" OF oDlg SIZE 30, 12 ACTION oDlg:End()
   @ 3,   16 BUTTON "&Cancel" SIZE 30, 12 OF oDlg ACTION oDlg:End() CANCEL

   // TGet():SetColorFocus( nRGB( 200, 120, 120 ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil




*-- FUNCTION -----------------------------------------------------------------
*         Name: ShowCalculator
*  Description:
*       Author: Timm Sodtalbers
*-----------------------------------------------------------------------------
FUNCTION ShowCalculator( oCurGet )

   LOCAL oDlg, oBtn, oGet1, oSay1, aResult
   LOCAL lTake    := .F.
   LOCAL cBuffer  := oCurGet:oGet:Buffer
   LOCAL nHorzRes := GetSysMetrics( 0 )
   LOCAL oGetRect := oCurGet:GetRect()
   LOCAL nTop     := oGetRect:nTop - 62
   LOCAL nLeft    := IIF( oGetRect:nRight + 126 > nHorzRes, nHorzRes - 212, oGetRect:nLeft )
   LOCAL nDezimal := IIF( oCurGet:oGet:DecPos = -1 , ;
                          0, LEN( oCurGet:oGet:Buffer ) - oCurGet:oGet:DecPos )
   LOCAL cFormula := IIF( VAL( cBuffer ) = 0, "", ALLTRIM( cBuffer ) ) + SPACE( 200 )

   DEFINE DIALOG oDlg FROM 0, 0 TO 26, 200 PIXEL STYLE nOr( DS_MODALFRAME, WS_POPUP )

   @ 0, 0 SAY SC_TITLE OF oDlg SIZE 300, 7 PIXEL COLOR CLR_WHITE, RGB( 9, 104, 168 )

   @ 9, 2 GET oGet1 VAR cFormula OF oDlg SIZE 98, 10 PIXEL PICTURE "@S100"

   IF .NOT. EMPTY( cBuffer )
      oGet1:SetPos( LEN(ALLTRIM( cFormula )) + 1 )
   ENDIF
   oGet1:bChange := {|| SC_Result( SC_FormulaString( oGet1 ), nDezimal, cBuffer, oSay1 ) }

   @ 21, 2 SAY oSay1 PROMPT ALLTRIM( cFormula ) OF oDlg SIZE 98, 8 PIXEL COLOR CLR_GRAY RIGHT

   #IFDEF __HARBOUR__
      oGet1:bKeyDown = {|nKey,nFlags| ;
         IIF( nKey == VK_RETURN, ( oGet1:bChange := {|| .T. }, lTake := .T., oDlg:End() ), ) }
   #ELSE
      @ 9, 120 BUTTON oBtn PROMPT "..." OF oDlg SIZE 10, 10 PIXEL ACTION oDlg:End()
      oBtn:bGotFocus = {|| lTake := .T., oDlg:End() }
   #ENDIF

   ACTIVATE DIALOG oDlg ;
      ON INIT oDlg:Move( nTop, nLeft, 210, 62 )

   IF lTake = .T. .AND. .NOT. EMPTY( cFormula ) .AND. oCurGet:lFocused = .T.

      aResult := SC_Result( cFormula, nDezimal, cBuffer )

      IF EMPTY( aResult[2] )
         oCurGet:VarPut( aResult[1] )
         oCurGet:Refresh()
      ELSE
         MsgStop( aResult[2], SC_STOP )
      ENDIF

   ENDIF

RETURN (.T.)


*-- FUNCTION -----------------------------------------------------------------
*         Name: SC_Result
*  Description:
*       Author: Timm Sodtalbers
*-----------------------------------------------------------------------------
FUNCTION SC_Result( cFormula, nDezimal, cBuffer, oSay )

   LOCAL nValue
   LOCAL cError := ""

   cFormula := STRTRAN( cFormula, ",", "." )

   IF TYPE( cFormula ) = "N"

      nValue := &( cFormula )

      IF LEN( cBuffer ) < LEN( ALLTRIM( STR( nValue, 100, nDezimal ) ) )
         cError := SC_ERROR1
      ENDIF

   ELSE
      cError := SC_ERROR2
   ENDIF

   IF oSay <> NIL
      oSay:SetText( IIF( EMPTY( cError), ALLTRIM(STR( nValue, 100, nDezimal )), SC_ERROR3 ) )
   ENDIF

RETURN { nValue, cError }


*-- FUNCTION------------------------------------------------------------------
*         Name: SC_FormulaString
*  Description:
*       Author: Timm Sodtalbers
*-----------------------------------------------------------------------------
FUNCTION SC_FormulaString( oGet )

   LOCAL cBuffer  := ALLTRIM( oGet:oGet:buffer )
   LOCAL nLastKey := oGet:nLastKey

   IF nLastKey > 96 .AND. nLastKey < 116
      nLastKey := nLastKey - 96 + 48
   ENDIF

/*
   IF nLastKey <> 8
      cBuffer := STUFF( cBuffer, oGet:nPos, 0, CHR( nLastKey ) )
   ENDIF
*/


RETURN ( cBuffer )
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Calculator in Get

Postby karinha » Fri May 23, 2014 4:46 pm

Gracias Lucas, funcionó perfecto. Very Thanks!!

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7822
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Calculator in Get

Postby albeiroval » Tue May 27, 2014 3:46 am

Hola,

Usandolo desde la lausula ACTION ,Con este codigo no funciona.

Code: Select all  Expand view

REDEFINE GET oGet[4] VAR aDatos[ _PRECIO ] ID 203 OF oDlg;
    PICTURE "@E 999,999.99";
    BITMAP ovarsis:BitMap[ BMP_GETCALC ];
    ACTION ( ShowCalculator(oGet[4]) )
 


Da el siguiente error :

Code: Select all  Expand view

   Called from: .\source\classes\TGET.PRG => (b)TGET_CREATEBUTTON( 487 )
 
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
User avatar
albeiroval
 
Posts: 370
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela

Re: Calculator in Get

Postby Silvio.Falconi » Tue May 27, 2014 7:12 am

REDEFINE GET oGet[4] VAR aDatos[ _PRECIO ] ID 203 OF oDlg PICTURE "@E 999,999.99"

oGet[4] :bKeyDown = {|nKey| IIF( nKey == VK_SPACE, ShowCalculator(oGet[4] ), .T. ) }


the user must only press space bar when the cursor is in this get
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Calculator in Get

Postby albeiroval » Tue May 27, 2014 1:40 pm

Silvio,

Ya lo habia probado de esa manera. Lo que queria era probarlo desde un boton en el GET.

Saludos,
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
User avatar
albeiroval
 
Posts: 370
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft, Garbi and 27 guests