1. A table is splitted in different groups ( index on group )
2. Inside a group, I have to switch 2 positions.
3. A visual display of the 2 selected records is added
- Code: Select all Expand view RUN
// ------------------
FUNCTION CHANGE_POS(cMonth)
LOCAL I := 0, h1, h2, nRecord1, nRecord2, cGroup1 := "", cGroup2 := ""
DBSELECTAREA( cMonth )
( cMonth )->(DBGOTOP())
I := 0
DO WHILE !EOF()
IF ( cMonth )->CHANGE = "X" // detects 2 selected records
// to change the position
I++
ENDIF
( cMonth )->(DBSKIP(+1))
ENDDO
IF I = 0
MsgAlert( "No records selected", "ERROR" )
RETURN( NIL )
ELSEIF I = 1
MsgAlert( "Only 1 record selected", "ERROR" )
RETURN( NIL )
ENDIF
I := 0
( cMonth )->(DBGOTOP())
DO WHILE !EOF()
IF ( cMonth )->CHANGE = "X" // selected for change
I++
IF I = 1
cGroup1 := ( cMonth )->GROUP // 1. selected group
nRecord1 := ( cMonth )->(RECNO()) // 1. selected record
h1 := FW_RecToHash()
ELSEIF I = 2
cGroup2 := ( cMonth )->GROUP // 2. selected group
nRecord2 := ( cMonth )->(RECNO()) // 2. selected record
h2 := FW_RecToHash()
ELSEIF I > 2 // 2 selections reached
EXIT
ENDIF
ENDIF
( cMonth )->(DBSKIP(+1))
ENDDO
IF cGroup1 <> cGroup2
MsgAlert( "Not possible, to change" + CRLF + ;
"the position using different groups !", "ERROR" )
RETURN( NIL )
ENDIF
// write data to the 2 selected records ( 1 to 2 and 2 to 1 )
( cMonth )->(DBGOTO(nRecord1))
FW_HashToRec( h2 )
( cMonth )->(DBGOTO(nRecord2))
FW_HashToRec( h1 )
( cMonth )->(DBGOTOP())
RETURN NIL
best regards
Uwe