Using wheel in a Get

This forum is for posting of useful information
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Using wheel in a Get

#1 Post 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
The eXpress train is coming - and it has more cars.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Using wheel in a Get

#2 Post by skiman »

Hi Roger,

Looks as this will also work with dates.
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Using wheel in a Get

#3 Post 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
The eXpress train is coming - and it has more cars.

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Using wheel in a Get

#4 Post 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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Using wheel in a Get

#5 Post 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!
The eXpress train is coming - and it has more cars.

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Using wheel in a Get

#6 Post 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

Post Reply