Get decimal picture

Get decimal picture

Postby sambomb » Fri May 10, 2013 1:14 pm

Code: Select all  Expand view
Redefine Get      oGt[4];
         Var      cStr[5] ;
         Update;
         ID       108;
         Picture  "999,999.99" ;
         of       oDlg

         
Procedure ChangePicture()        
   cMascara := "999,999.999"
   oGt[4]:cPicture := cMascara
   oGt[4]:oGet:Picture := cMascara
   oGt[4]:Refresh()
Return

With this the picture is changed, but only if I press "." ( dot ) before the first decimal be filled I can add the third decimal.

Sample:
List of pressed keys
123.456 = OK     => 123.456
12345.678 = OK   => 12,345.678
123456.789 = OK  => 123,456.789
123456789 = Fail => 123,456.780
1234567.89 = Fail => 123,456.790
12345678.9 = Fail => 123,456.790

 


In the TGet class I found this in the KeyChar method, I tried to implement this but with no success.

Code: Select all  Expand view

   if ::oGet:Type == "N" .and. ( Chr( nKey ) == "." .or. Chr( nKey ) == "," )
      if ::oGet:Clear()
         #ifndef __XHARBOUR__
            ::oGet:DelEnd()
         #endif
      endif

      ::oGet:ToDecPos()

 
Last edited by sambomb on Fri May 10, 2013 5:44 pm, edited 1 time in total.
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby Antonio Linares » Fri May 10, 2013 2:01 pm

Try this:

Procedure ChangePicture()
cMascara := "999,999.99"
oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:oGet:VarGet() // not sure about this one
oGt[4]:oGet:SetText( oGt[4]:oGet:buffer )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Get decimal picture

Postby sambomb » Fri May 10, 2013 2:29 pm

Application
===========
Path and name: C:\TRADE9\TradeNFe.EXE (32 bits)
Size: ********* bytes
Time from start: 0 hours 0 mins 50 secs
Error occurred at: 10/05/2013, 11:28:12
Error description: Warning BASE/1004 Message not found: TCLIPGET:SETTEXT

Stack Calls
===========
Called from: source\rtl\tobject.prg => TCLIPGET:ERROR(172)
Called from: source\rtl\tobject.prg => TCLIPGET:MSGNOTFOUND(205)
Called from: source\rtl\tobject.prg => TCLIPGET:SETTEXT(0)
Called from: G:\prog\fivewin\RCA Trade\Versao9.0\Source\DlgVenda.prg => DETALHEPRODUTO(17114)


oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:oGet:VarGet() // not sure about this one
oGt[4]:oGet:SetText( oGt[4]:oGet:buffer ) //-- 17114
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby sambomb » Fri May 10, 2013 2:34 pm

oGt[4]:oGet:SetText( oGt[4]:oGet:buffer ) //-- 17114
oGt[4]:SetText( oGt[4]:oGet:buffer ) //-- Fixed the error, but still don't work properly
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby kok joek hoa » Fri May 10, 2013 6:13 pm

Dear Sambomb

Try

Procedure ChangePicture()
cMascara := "999,999.999"
oGt[4]:cPicture := cMascara
oGt[4]:oGet:Picture := cMascara
oGt[4]:setfocus()
oGt[4]:Refresh()
Return

Regards,
kok
kok joek hoa
 
Posts: 117
Joined: Tue Jan 03, 2006 6:18 pm

Re: Get decimal picture

Postby sambomb » Fri May 10, 2013 6:37 pm

Kok, I change the picture in the valid of a get before this get, so I don't need to Set the focus on the Get since it is already here and if I use the SetFocus() I'll have a new trouble.

oGt[3]:bValid call the ChangePicture() when the focus go to the oGt[4]
The ChangePicture() in the sample is simplified to focus on the problem, but instead of cMascara := "999,999.999" I test what picture I need to use and define in the var.
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby sambomb » Mon May 13, 2013 2:43 pm

Anyone else has a guess?
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby James Bott » Mon May 13, 2013 3:42 pm

Your error seems to be with the clipboard object, and I am not sure why there is a clipboard object.

Perhaps you can build a small self-contained sample program that shows the problem?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Get decimal picture

Postby ADutheil » Mon May 13, 2013 4:03 pm

Have a look at this
Code: Select all  Expand view
#include "fivewin.ch"

FUNCTION TEST
LOCAL aGets := array(2)
LOCAL aVars := { "999,999.999", 1234.567 }
LOCAL oDlg

DEFINE DIALOG oDlg RESOURCE "dlgtest"
    REDEFINE GET aGets[ 1 ] VAR aVars[ 1 ]  ID 101 OF oDlg VALID ChangePicture( aGets, aVars )
    REDEFINE GET aGets[ 2 ] VAR aVars[ 2 ] PICTURE aVars[ 1 ] ID 102 OF oDlg
ACTIVATE DIALOG oDlg
RETURN NIL

FUNCTION ChangePicture( aGets, aVars )        
   aGets[ 2 ]:oGet:Assign()
   aGets[ 2 ]:oGet:Picture := aVars[ 1 ]
   aGets[ 2 ]:oGet:UpdateBuffer()
   aGets[ 2 ]:Refresh()
RETURN .T.
 


tstget.rc
Code: Select all  Expand view
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
dlgtest DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
    DEFPUSHBUTTON   "OK", IDOK, 129, 7, 50, 14
    PUSHBUTTON      "Cancel", IDCANCEL, 129, 24, 50, 14
    EDITTEXT        101, 5, 21, 72, 14, ES_AUTOHSCROLL
    EDITTEXT        102, 5, 46, 93, 14, ES_AUTOHSCROLL
}
 
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Get decimal picture

Postby sambomb » Mon May 13, 2013 7:50 pm

James

Code: Select all  Expand view
****************************************************************************
FUNCTION Teste()
****************************************************************************

Local oDlgMsg
Private oGet := Array(2), cGet := Array(2)

   cGet[1] := Space(10)
   cGet[2] := 1

   DEFINE DIALOG  oDlgMsg;
          FROM    10, 20 TO 20, 60;
          TITLE   "Test";
          Of      oWnd

   @ 1.6,  2.0 GET      oGet[1];
               Var      cGet[1];
               picture  "@!";
               SIZE     80, 12;
               OF       oDlgMsg;
               Valid    ChangePicture()

   @ 2.6,  2.0 GET      oGet[2];
               Var      cGet[2];
               picture  "99,999.99";
               SIZE     80, 12;
               OF       oDlgMsg

   @ 3.6, 14.0 ButtonBmp;
               SIZE      45, 13;
               ACTION    oDlgMsg:End();
               OF        oDlgMsg;
               TEXTRIGHT;
               prompt    "Exit"

   oDlgMsg:lHelpIcon := .f.

   ACTIVATE DIALOG oDlgMsg CENTERED
   
RETURN nil
/*------------------------------------------------------------------------*/

Function ChangePicture()
Local cPicture := "99,999.999"

   oGet[2]:cPicture := cPicture
   oGet[2]:oGet:Picture := cPicture
   oGet[2]:Refresh()
   
Return  .T.


Tab to change the GET and then try to fill the second get with: 12345678 => must return 12,345.670 instead of the desirable 12,345.678.
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby sambomb » Mon May 13, 2013 7:56 pm

I found a workaround:

Code: Select all  Expand view
/*------------------------------------------------------------------------*/
   oGt[4]:cPicture := cMascara
   oGt[4]:oGet:Picture := cMascara
   
   //-- Remover o valid do controle atual para poder executar o pause()
   oBackupDlg := ActiveDialog()
   
   bBackupValid := "NAOPRECISA"
   
   //-- Identificar qual o controle que está com o foco
   For i := 1 to Len( oBackupDlg:aControls )
   
      If oBackupDlg:aControls[i]:lFocused

         //-- Obter o valid antigo
         Try
            bBackupValid := oBackupDlg:aControls[i]:bValid
            oBackupDlg:aControls[i]:bValid := {||SysRefresh()}
         Catch
            bBackupValid := "NAOPRECISA"
         End
         
         Exit
         
      End
   
   End
   
   Pause(0.1,.T.)//-- Create another dialog
   
   //--Restaurar o valid
   If ValType(bBackupValid) = "B" //-- Só é bloco se passar encontrar um objeto válido

      oBackupDlg:aControls[i]:bValid := bBackupValid
     
   End
   
   oGt[4]:Refresh()
/*------------------------------------------------------------------------*/

****************************************************************************
procedure Pause( nSeconds , lRefresh)
****************************************************************************

local oDlgPause, bAction
local nStart := GetTickCount()
local oDlgDef := GetWndDefault()

   Default nSeconds := 1, lRefresh := .f.

   if .not. lRefresh

      while GetTickCount() - nStart < ( 1000 * nSeconds )
         SysRefresh()
      end

   else
      bAction := { || WaitSeconds( nSeconds ) }

      DEFINE DIALOG     oDlgPause                       ;
             FROM       -10,-10 TO 1, 1                 ;
             STYLE      nOr( DS_MODALFRAME, WS_POPUP )  

      oDlgPause:nTop := -20
      oDlgPause:nLeft := -20

      oDlgPause:bStart := { || Eval( bAction, oDlgPause ),  oDlgPause:End(), SysRefresh() }

      ACTIVATE DIALOG oDlgPause

   end

Return NIL

/*------------------------------------------------------------------------*/
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby sambomb » Fri May 17, 2013 11:09 am

Antonio, James, Kok?
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Get decimal picture

Postby James Bott » Fri May 17, 2013 2:22 pm

Samir,

You need to add the UPDATE clause to the second GET.

Code: Select all  Expand view
  @ 2.6,  2.0 GET      oGet[2];
               Var      cGet[2];
               picture  "99,999.99";
               SIZE     80, 12;
               OF       oDlgMsg;
               UPDATE                      // add this
 


Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Get decimal picture

Postby nageswaragunupudi » Fri May 17, 2013 3:56 pm

Mr Samir
The code you posted in your first post itself is working well for me, in the sense that the picture is changed and the new picture is functioning successfully.
This is the simple program I tested.
Code: Select all  Expand view
function GetPic()

   local n1 := 0, n2 := 1.234
   local aGet[ 2 ]
   local oDlg


   DEFINE DIALOG oDlg SIZE 200,200 PIXEL

   @ 10,10 GET aGet[ 1 ] VAR n1 PICTURE "999,999.99" SIZE 60,12 PIXEL OF oDlg RIGHT ;
      VALID ChangePic( oDlg, aGet )
   @ 30,10 GET aGet[ 2 ] var n2 PICTURE "999,999.99" SIZE 60,12 PIXEL OF oDlg RIGHT ;
      VALID ( oDlg:Update(), .t. )
   @ 50,10 SAY n2 PICTURE "999,999.9999" SIZE 60,10 PIXEL OF oDlg UPDATE
   @ 70,10 BUTTON "OK" SIZE 30,14 PIXEL OF oDlg ACTION MsgInfo( Transform( n2, "999,999.9999" ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//

static function ChangePic( oDlg, aGet )

   WITH OBJECT aGet[ 2 ]
      if !( ".999" $ :cPicture )
         :cPicture := ;
         :oGet:picture := "999,999.999"
         :Refresh()
      endif
   END

return .t.
 

The logic is exactly the same as yours in the first posting.
Initially the picture of the second get is set to 2 dec. places.
The valid clause of the first get changes the picture of second get to 3 dec.places.

After the valid clause changes the picture of second get, I observed that the second get is behaving exactly the same way as if the changed picture was set originally.

This is the screen shot initially. First get has input focus.
Image

Entered some value in the first get and the focus shifted to second get. We can now see that the picture is changed successfully and see the value with 3 decimal places.
Image

You said:
With this the picture is changed, but only if I press "." ( dot ) before the first decimal be filled I can add the third decimal.
.....
.....
123456789 = Fail => 123,456.780

What I observed is different.
I now entered 123456789.
This is the result:
Image

In this case result of entering
123456789 = success = 123,456.789.

I tested with both Harbour and xHarbour and latest FWH.

You have also observed:
1234567.89 = Fail => 123,456.790
12345678.9 = Fail => 123,456.790

Actually pressing decimal after the cursor moves post decimal place is not common. After digits 123456 are entered the Get automatically moves the cursor to the right of the decimal place. After entering one digit and then press "." the behaviour is different in Harbour and xHarbour.

If we are not agreeable with the behaviour of what happens when we press '.' after crossing the decimal point, that has nothing to do with dynamically changing the picture. What I can definitely say is that it is the same behaviour whether the 3 decimal picture was originally specified or dynamically changed during program execution.

In my view, your original code was adequate to successfully change the picture. There is no need to keep on trying different alternatives. If you find that it does not, then may be it is an issue with the versions you are using.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Get decimal picture

Postby sambomb » Fri May 17, 2013 7:34 pm

James thx for the reply, I forgot the update clause only in the sample, in my code the Update is defined.

Code: Select all  Expand view

   cStr[4] := 0
   Redefine Get       oGt[4]                                ;
            var       cStr[4]                               ;
            Update                                          ;
            ID        107                                   ;
            of        oDlg                                  ;
            when      .not. Empty(cStr[3])                  ;
            Message   "Informe a quantidade a ser faturado"
 
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests