@ 60,20 GET aGet[2] VAR nVar SIZE 100,24 PIXEL OF oDlg RIGHT;
VALID ChangePic( oDlg, aGet )
static function ChangePic( oDlg, aGet )
WITH OBJECT aGet[ 2 ]
if !( "@Z 999.99" $ :cPicture )
:cPicture := ;
:oGet:picture := "@Z 999.99"
:Refresh()
endif
END
return .t.
Otto wrote:Do you mean something like this?
// TGetNumeric class
#include "fivewin.ch"
function Main()
local oDlg, oGet
local nVar :=0
local nVar1:=0.75
local aGet:= array(2)
local cGetNumeric
SetGetColorFocus()
DEFINE DIALOG oDlg SIZE 400,150 PIXEL TRUEPIXEL TITLE FWVERSION
cGetNumeric := TGetNumeric ():New(20,20,, oDlg)
ACTIVATE DIALOG oDlg CENTERED
return nil
CLASS TGetNumeric FROM TGet
data nDecimals,nValue
METHOD Init
METHOD keyPress( nKey )
METHOD SetValue( nNewValue )
METHOD GetNumericValue()
METHOD SetNumericValue( nNewValue )
METHOD SetDecimals( nDecimals )
END CLASS
METHOD Init CLASS TGetNumeric
::nDecimals := 2 // Set the number of decimal places
::SetValue(0) // Initialize the value to 0
return self
METHOD keyPress( nKey ) CLASS TGetNumeric
LOCAL nLen, cValue, nCursorPos
::keyPress( nKey ) // Call base class method
IF nKey >= K_0 .AND. nKey <= K_9 // Check if the pressed key is a digit
cValue := STR(::nValue, 7, ::nDecimals) // Convert numeric value to string
nCursorPos := MAX( 0, RAt( ".", cValue ) - 1 ) // Get cursor position
::SetText( cValue ) // Update control with formatted value
::setSel( nCursorPos + 1, nCursorPos + 1 ) // Set cursor position
ENDIF
return nil
METHOD SetValue( nNewValue ) CLASS TGetNumeric
LOCAL cFormattedValue
cFormattedValue := STR(nNewValue, 7, ::nDecimals) // Format the numeric value
::SetText( cFormattedValue ) // Update control with formatted value
::setSel( 7 - ::nDecimals, 7 - ::nDecimals ) // Set cursor position
RETURN NIL
METHOD GetNumericValue() CLASS TGetNumeric
RETURN VAL( ::GetText() )
METHOD SetNumericValue( nNewValue ) CLASS TGetNumeric
::SetValue( nNewValue )
RETURN NIL
METHOD SetDecimals( nDecimals ) CLASS TGetNumeric
::nDecimals := nDecimals
RETURN NIL
#include "fivewin.ch"
FUNCTION Main()
LOCAL oDlg, aGet := array(2)
LOCAL nVar1 := 0.75
LOCAL nVar := 0
SetGetColorFocus()
DEFINE DIALOG oDlg SIZE 400,150 PIXEL TRUEPIXEL TITLE FWVERSION
@ 20,20 GET aGet[1] VAR nVar1 SIZE 100,24 PIXEL picture "@E999.99" OF oDlg RIGHT ;
@ 60,20 GET aGet[2] VAR nVar SIZE 100,24 PIXEL picture "@E999.99" OF oDlg RIGHT;
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
#include "Fivewin.ch"
#include "xbrowse.ch"
FUNCTION Main()
LOCAL oDlg1, oGet := array(4), nVar := {' 0',' 0',' 0',' 0'}, oBot1
SET CONFIRM ON
DEFINE DIALOG oDlg1 TITLE "Ingreso de datos" SIZE 300,100 PIXEL RESIZABLE
@ 05,25 GET oGet[1] var nVar[1] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,55 GET oGet[2] var nVar[2] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,85 GET oGet[3] var nVar[3] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,115 GET oGet[4] var nVar[4] PICTURE "@9" OF oDlg1 PIXEL right
@ 25,20 BUTTON oBot1 PROMPT "&Ok" OF oDlg1 SIZE 30,10 ACTION oDlg1:End() PIXEL
oGet[1]:bLostFocus := {|| (oGet[1]:Assign(),oGet[1]:cText := STR(VAL(oGet[1]:cText) /100,6,2), oGet[1]:Refresh()) }
oGet[2]:bLostFocus := {|| (oGet[2]:Assign(),oGet[2]:cText := STR(VAL(oGet[2]:cText) /100,6,2), oGet[2]:Refresh()) }
oGet[3]:bLostFocus := {|| (oGet[3]:Assign(),oGet[3]:cText := STR(VAL(oGet[3]:cText) /100,6,2), oGet[3]:Refresh()) }
oGet[4]:bLostFocus := {|| (oGet[4]:Assign(),oGet[4]:cText := STR(VAL(oGet[4]:cText) /100,6,2), oGet[4]:Refresh()) }
oGet[1]:bGotFocus := {|| (oGet[1]:cText := STR(VAL(oGet[1]:cText) *100,6), oGet[1]:Refresh(),oGet[1]:SelectAll()) }
oGet[2]:bGotFocus := {|| (oGet[2]:cText := STR(VAL(oGet[2]:cText) *100,6), oGet[2]:Refresh(),oGet[2]:SelectAll()) }
oGet[3]:bGotFocus := {|| (oGet[3]:cText := STR(VAL(oGet[3]:cText) *100,6), oGet[3]:Refresh(),oGet[3]:SelectAll()) }
oGet[4]:bGotFocus := {|| (oGet[4]:cText := STR(VAL(oGet[4]:cText) *100,6), oGet[4]:Refresh(),oGet[4]:SelectAll()) }
ACTIVATE DIALOG oDlg1 CENTERED
xbrowse(nVar)
RETURN nil
cmsoft wrote:Silvio:
Algo asi te puede servir?
O al menos que te de un inicio
Tengo que
- Code: Select all Expand view RUN
#include "Fivewin.ch"
#include "xbrowse.ch"
FUNCTION Main()
LOCAL oDlg1, oGet := array(4), nVar := {' 0',' 0',' 0',' 0'}, oBot1
SET CONFIRM ON
DEFINE DIALOG oDlg1 TITLE "Ingreso de datos" SIZE 300,100 PIXEL RESIZABLE
@ 05,25 GET oGet[1] var nVar[1] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,55 GET oGet[2] var nVar[2] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,85 GET oGet[3] var nVar[3] PICTURE "@9" OF oDlg1 PIXEL right
@ 05,115 GET oGet[4] var nVar[4] PICTURE "@9" OF oDlg1 PIXEL right
@ 25,20 BUTTON oBot1 PROMPT "&Ok" OF oDlg1 SIZE 30,10 ACTION oDlg1:End() PIXEL
oGet[1]:bLostFocus := {|| (oGet[1]:Assign(),oGet[1]:cText := STR(VAL(oGet[1]:cText) /100,6,2), oGet[1]:Refresh()) }
oGet[2]:bLostFocus := {|| (oGet[2]:Assign(),oGet[2]:cText := STR(VAL(oGet[2]:cText) /100,6,2), oGet[2]:Refresh()) }
oGet[3]:bLostFocus := {|| (oGet[3]:Assign(),oGet[3]:cText := STR(VAL(oGet[3]:cText) /100,6,2), oGet[3]:Refresh()) }
oGet[4]:bLostFocus := {|| (oGet[4]:Assign(),oGet[4]:cText := STR(VAL(oGet[4]:cText) /100,6,2), oGet[4]:Refresh()) }
oGet[1]:bGotFocus := {|| (oGet[1]:cText := STR(VAL(oGet[1]:cText) *100,6), oGet[1]:Refresh(),oGet[1]:SelectAll()) }
oGet[2]:bGotFocus := {|| (oGet[2]:cText := STR(VAL(oGet[2]:cText) *100,6), oGet[2]:Refresh(),oGet[2]:SelectAll()) }
oGet[3]:bGotFocus := {|| (oGet[3]:cText := STR(VAL(oGet[3]:cText) *100,6), oGet[3]:Refresh(),oGet[3]:SelectAll()) }
oGet[4]:bGotFocus := {|| (oGet[4]:cText := STR(VAL(oGet[4]:cText) *100,6), oGet[4]:Refresh(),oGet[4]:SelectAll()) }
ACTIVATE DIALOG oDlg1 CENTERED
xbrowse(nVar)
RETURN nil
Claro que es muy mejorable, pero al menos para comenzar
Otto wrote:Use STRTRAN()
Otto wrote:Yes, see this line.
oGet[1]:bGotFocus := {|| (oGet[1]:cText := STR(VAL(oGet[1]:cText) *100,6), oGet[1]:Refresh(),oGet[1]:SelectAll()) }
Cesar, changed the GETs to character that you get the inputstyle you wanted.
Otto wrote:Before saving, use VAL()
#include "Fivewin.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
Function main()
local nWd := GetSysMetrics(0) * .58
local nHt := GetSysMetrics(1) / 2.5
local oDlg,oFont,oBold
local oBrw,oBar
local oBtn:=array(3)
local aData:= {}
local cCod_temp:= "00001" // to demo
local oDbf
local cDir:= cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
RddSetDefault( "DBFCDX" )
SetHandleCount( 100 )
FWNumFormat( "E", .t. )
SET DATE FORMAT "dd-mm-yyyy"
SET DELETED ON
SET CENTURY ON
SET EPOCH TO year( date() ) - 20
SET MULTIPLE OFF
oFont := TFont():New( "Tahoma", 0, 18,, )
oBold := TFont():New( "Tahoma", 0, 16,,.t. )
// Creation Dbf for Demo test
Build_Dbf(cDir) // create dbf
// Open dDbf
oDbf:=TSample():New()
oDbf:setorder(1)
oDbf:Gotop()
// take the records for cCod_temp
aData := oDbf:DbfToArray( , { ||FIELD->cod == cCod_temp } )
DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL ; //TRUEPIXEL
TITLE "test numeric" ;
FONT oFont COLOR CLR_BLACK, CLR_WHITE ;
STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
WS_MINIMIZEBOX)
//---------------------------------------------------------------------//
DEFINE BUTTONBAR oBar OF oDlg SIZE 80,70 BOTTOM NOBORDER 2015
DEFINE BUTTON oBtn[1] OF oBar ;
FILENAME "DLG_NO";
PROMPT "Add" TOOLTIP "Esci" ;
ACTION Modify(oBrw,1,oFont)
DEFINE BUTTON oBtn[2] OF oBar ;
FILENAME "HLP_DLG";
PROMPT "Modify" TOOLTIP "Aiuto" ;
ACTION Modify(oBrw,2,oFont) GROUP
DEFINE BUTTON oBtn[3] OF oBar BTNRIGHT ;
FILENAME "DLG_OK";
PROMPT "Exit" ;
TOOLTIP "Conferma i dati" ;
ACTION ( oDlg:end( IDOK ) )
//--------------------------------------------------------------------------//
@ 2, 5 XBROWSE oBrw OF oDlg ;
COLUMNS 2,3,4,5;
HEADERS "Peso1","Peso2","Peso3","Peso4" ;
COLSIZES 90,90,90,90 ;
ARRAY aData ;
SIZE -5,-60 PIXEL STYLE FLAT NOBORDER
WITH OBJECT oBrw
:lHScroll := .f.
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oDlg:resize(), ChangeButtons( oBar ) )
return nil
//------------------------------------------------------------------//
function ChangeButtons( oBar )
AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
FUNCTION Modify(oBrowse,nMode,oFont) // cesar test
LOCAL oDlg1, oGet := array(4)
local nVar := {' 0',' 0',' 0',' 0'}, oBot1
local nRecord:= oBrowse:nArrayAt
local ntest1,ntest2,ntest3,ntest4
local cPicture:="@Z 999.99"
local aGet:= array(4)
local nWd := GetSysMetrics(0) * .58
local nHt := GetSysMetrics(1) / 4
local oBtn1,oBtn2,oBar
IF nMode==2 //modify
ntest1 := Str(oBrowse:aArraydata[nRecord][2])
ntest2 := Str(oBrowse:aArraydata[nRecord][3])
ntest3 := Str(oBrowse:aArraydata[nRecord][4])
ntest4 := Str(oBrowse:aArraydata[nRecord][5])
Endif
SET CONFIRM ON
DEFINE DIALOG oDlg1 SIZE nWd, nHt PIXEL ;
TITLE "test numeric" ;
FONT oFont COLOR CLR_BLACK, CLR_WHITE ;
STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
WS_MINIMIZEBOX)
//-------------------------------------------------------------------//
DEFINE BUTTONBAR oBar OF oDlg1 SIZE 70,70 2015 BOTTOM NOBORDER
DEFINE BUTTON oBtn1 OF oBar ;
FILENAME "DLG_NO";
PROMPT "Annulla" TOOLTIP "Esci" ;
ACTION ( oDlg1:end( IDCANCEL ) )
DEFINE BUTTON oBtn2 OF oBar BTNRIGHT ;
FILENAME "DLG_OK";
PROMPT "Conferma" ;
TOOLTIP "Conferma i dati" ;
ACTION ( oDlg1:end( IDOK ) )
//-------------------------------------------------------------------//
@ 70, 20 GET aGet[1] VAR ntest1 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 82 GET aGet[2] VAR ntest2 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 245 GET aGet[3] VAR ntest3 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 295 GET aGet[4] VAR ntest4 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
aGet[1]:bLostFocus := {|| (aGet[1]:Assign(),aGet[1]:cText := STR(VAL(aGet[1]:cText) /100,6,2), aGet[1]:Refresh()) }
aGet[2]:bLostFocus := {|| (aGet[2]:Assign(),aGet[2]:cText := STR(VAL(aGet[2]:cText) /100,6,2), aGet[2]:Refresh()) }
aGet[3]:bLostFocus := {|| (aGet[3]:Assign(),aGet[3]:cText := STR(VAL(aGet[3]:cText) /100,6,2), aGet[3]:Refresh()) }
aGet[4]:bLostFocus := {|| (aGet[4]:Assign(),aGet[4]:cText := STR(VAL(aGet[4]:cText) /100,6,2), aGet[4]:Refresh()) }
aGet[1]:bGotFocus := {|| (aGet[1]:cText := STR(VAL(aGet[1]:cText) *100,6), aGet[1]:Refresh(),aGet[1]:SelectAll()) }
aGet[2]:bGotFocus := {|| (aGet[2]:cText := STR(VAL(aGet[2]:cText) *100,6), aGet[2]:Refresh(),aGet[2]:SelectAll()) }
aGet[3]:bGotFocus := {|| (aGet[3]:cText := STR(VAL(aGet[3]:cText) *100,6), aGet[3]:Refresh(),aGet[3]:SelectAll()) }
aGet[4]:bGotFocus := {|| (aGet[4]:cText := STR(VAL(aGet[4]:cText) *100,6), aGet[4]:Refresh(),aGet[4]:SelectAll()) }
ACTIVATE DIALOG oDlg1 CENTERED ;
ON INIT ( oDlg1:resize(), ChangeButtons( oBar ) )
IF oDlg1:nresult == IDOK
oBrowse:aArraydata[nRecord][2]:= ntest1
oBrowse:aArraydata[nRecord][3]:= ntest2
oBrowse:aArraydata[nRecord][4]:= ntest3
oBrowse:aArraydata[nRecord][5]:= ntest4
endif
RETURN nil
//------------------------------------------------------------------------------------//
Function Build_Dbf(cDir)
local lAppend := .F.
FIELD cod
local aFields := { { "Cod", "C", 5, 0 },;
{ "test1", "N", 6, 2 },;
{ "test2", "N", 6, 2 },;
{ "test3", "N", 6, 2 },;
{ "test4", "N", 6, 2 }}
IF !lIsDir(alltrim(cDir))
IF !lMkDir(cDir)
MsgAlert("Attention")
ENDIf
ENDIf
if File( cdir+"sample.dbf" )
if !File( cdir+"sample.cdx" )
USE &(cdir+"sample") NEW EXCLUSIVE ALIAS DB
INDEX ON Cod TAG COD FOR !Deleted()
CLOSE DB
endif
else
DbCreate( cdir+"sample.dbf", aFields, "DBFCDX", .T., "DB" )
lAppend := .T.
INDEX ON Cod TAG COD FOR !Deleted()
CLOSE DB
endif
/// add test
if lAppend
USE &(cdir+"sample") NEW EXCLUSIVE ALIAS DB
INDEX ON Cod TAG COD FOR !Deleted()
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 0.10
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.70
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 0.75
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.50
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 1.2
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.4
CLOSE DB
Endif
RETURN NIL
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
CLASS TXData from TDatabase
DATA cDbfPath init cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
ENDCLASS
CLASS TSample from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TSample
Default lShared := .t.
::super:New(,::cDbfPath + "Sample" ,"DBFCDX", lShared)
if ::use()
::setOrder(1)
::gotop()
endif
RETURN Self
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 107 guests