Page 1 of 1

Using wheel in a Get

Posted: Wed Oct 03, 2012 6:32 pm
by rdonnay
Here's a sample program that uses the wheel to increment or decrement the value in a Get.

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], nNum := 100

@ 0,0 DCGET nNum PICT '99999999' EVAL {|o|o:wheel := {|a,b,o|ChangeValue(a,b,o,@nNum)}}

DCREAD GUI FIT TITLE 'Wheel test'

RETURN nil

* --------

PROC appsys ; return

* --------

STATIC FUNCTION ChangeValue( a, b, oGet, nNum )

IF b[2] > 0
  nNum ++
ELSE
  nNum --
ENDIF

oGet:setData()

RETURN nil

Re: Using wheel in a Get

Posted: Fri Oct 05, 2012 1:19 am
by skiman
Hi Roger,

Looks as this will also work with dates.

Re: Using wheel in a Get

Posted: Fri Oct 05, 2012 5:23 am
by rdonnay
Yes, it does. Here is a sample.

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], nNum := 100, dDate := Date()

@ 0,0 DCGET nNum PICT '99999999' EVAL {|o|o:wheel := {|a,b,o|ChangeValue(a,b,o,@nNum)}}

@ 2,0 DCGET dDate PICT '99999999' EVAL {|o|o:wheel := {|a,b,o|ChangeValue(a,b,o,@dDate)}} ;
      POPUP {|d|DC_PopDate(d,,,,,,2)}


DCREAD GUI FIT TITLE 'Wheel test'

RETURN nil

* --------

PROC appsys ; return

* --------

STATIC FUNCTION ChangeValue( a, b, oGet, xValue )

IF b[2] > 0
  xValue ++
ELSE
  xValue --
ENDIF

oGet:setData()

RETURN nil

Re: Using wheel in a Get

Posted: Sat Oct 06, 2012 11:14 am
by unixkd
The Static Function ChangeValue can be modified as shown below to avoid passing xValue to the function

FUNCTION ChangeValue( a, b, oGet)
Local xValue := oGet:getData()
IF b[2] > 0
xValue ++
ELSE
xValue --
ENDIF

oGet:setData(xValue)

RETURN nil

You can now define a generic block for GET ..... EVAL as follows:
#define WHEEL_BLOCK {|o|o:wheel := {|a,b,o|ChangeValue(a,b,o)}}

You can now code anywhere as follows:
@ .... GET .... EVAL WHEEL_BLOCK

Re: Using wheel in a Get

Posted: Sat Oct 06, 2012 12:42 pm
by rdonnay
You can now define a generic block for GET ..... EVAL as follows:
#define WHEEL_BLOCK {|o|o:wheel := {|a,b,o|ChangeValue(a,b,o)}}
Excellent!

Re: Using wheel in a Get

Posted: Sun Oct 07, 2012 6:36 am
by unixkd
The ChangeValue function can be modified further to be able to deal with fields such as zipcode, telephone etc using a modified version of your DC_NUMINCR() function as shown below:
*
FUNCTION ChangeValue( a, b, oGet)
Local xValue := oGet:getData()
IF ValType(xValue) = "C"
xValue := IF( b[2] > 0, PPS_NUMINCR( xValue ), PPS_NUMINCR( xValue,nil,nil,1 ))
Else
IF( b[2] > 0, xValue ++, xValue -- )
EndIf
oGet:setData(xValue)
RETURN nil
*
*
FUNCTION PPS_numincr ( cVarName, cLoVal, cHiVal, nFlag )
STATIC cVar := ''
LOCAL nVarLength, nNumStart, nNumEnd, nVarPointer, cNewString
DEFAULT nFlag := 0
IF Empty(cVarName)
cVarName := cVar
ENDIF
nVarLength := LEN(cVarName)
nVarPointer := nVarLength
DO WHILE nVarPointer>0
IF SUBSTR(cVarName,nVarPointer,1)>='0' ;
.AND. SUBSTR(cVarName,nVarPointer,1)<='9'
EXIT
ENDIF
nVarPointer--
ENDDO
nNumEnd := nVarPointer
DO WHILE nVarPointer>0
IF (SUBSTR(cVarName,nVarPointer,1)<'0' ;
.OR. SUBSTR(cVarName,nVarPointer,1)>'9') .AND. ;
SUBSTR(cVarName,nVarPointer,1)#' '
EXIT
ENDIF
nVarPointer--
ENDDO
nNumStart := nVarPointer+1
If nFlag == 0
cNewString := STRTRAN(STR(VAL(SUBSTR(cVarName,nNumStart, nNumEnd-nNumStart+1))+1,nNumEnd-nNumStart+1),' ','0')
Else
cNewString := STRTRAN(STR(VAL(SUBSTR(cVarName,nNumStart, nNumEnd-nNumStart+1))-1,nNumEnd-nNumStart+1),' ','0')
EndIf
cVar := SUBSTR(cVarName,1,nNumStart-1)+cNewString+;
SUBSTR(cVarName,nNumEnd+1,nVarLength-nNumEnd)
IF !Empty(cLoVal) .AND. !Empty(cHiVal) .AND. cVar > cHiVal
cVar := cLoVal
ENDIF
RETURN cVar