General information
Category:
Coding, syntax & commands
I have two list boxes, lstsource and lstSelected. I have a set of record that list in the lstSource and selected into the lstSelected list box, click save will save into the cRight character field such as '1100000000' once the 1st, and second record have chosen.
Code for lstSource list box
Select cno,cname FROM cmenu;
where !EMPTY(cname) order by cno into cursor mycursor
* AddItem To LstSource.
With Thisform
.lstSource.Clear
select mycursor
go top
do whil !eof()
.lstsource.additem(STR(cno,3)+" "+cname)
select cmenu
skip
endd
Endwith
In my Add Button:
nCnt = 1
DO WHILE nCnt <= THISform.lstSource.ListCount
IF THISform.lstSource.Selected(nCnt)
THISform.lstSelected.AddItem(THISform.lstSource.List(nCnt))
THISform.lstSource.RemoveItem(nCnt)
ELSE
nCnt = nCnt + 1
ENDIF
ENDDO
Once I Selected, I click save Button
Code in the save Button:
LOCAL cRight
cRight =SPACE(80)
lc_Right =''
Add_right =''
ln_cnt=1
FOR ln_cnt = 1 TO .LstSelected.ListCount
ln_no = VAL(SUBSTR(Thisform.lstSelected.List(ln_cnt),1,3))
Lc_Right = SuBSTR(cRight,1,ln_no-1)+StrTran(SUBSTR(cRight,ln_no,1),' ','1')+;
SUBSTR(cRight,ln_no+1,10)
add_right = lc_right
cRight = lc_right
ENDFOR
* Update those with blank char with '0'
SELECT Sys_Usr
IF .Rec_no <> 0
GO .Rec_No
DO Whil !Rlock()
Endd
Replace usr_right WITH add_right
Replace usr_right WITH STRTRAN(usr_right,' ','0')
UNLOCK
Endif
Endwith
All these code are not problem. but the problem when i retrieve the record while
It cannot remove the lstsource list box and give the wrong result.
The source of retrieve record and add into the lstselected
WITH Thisform
SELECT Sys_Usr
GO .Rec_no
cRight = usr_Right
i = 1
FOR i = 1 TO LEN(cRight)
ll_no = SUBSTR(cRight,i,1)
IF ll_no ='0'
LOOP
Endif
.lstSelected.AddItem(THISform.lstSource.List(i))
.lstSource.RemoveItem(i)
ENDFOR
For Example : my cRight '1010100000' that means the 1st record and third record, the
fifth record should be selected and list into the lstselected but it give
the wrong result, it come out '10010010000' for me, I think the code
of .lstSource.RemoveItem(i), it remove the wrong item.
Any one can help me on this and any other to shorter the coding, coding provide will better.
Sorry for english. Thanks
Endwith
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only