Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List Box
Message
 
To
02/10/2002 20:54:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00707174
Message ID:
00707196
Views:
18
The STUFF() and AT() functions are helpful for inserting or locating characters (or strings) within a string. There is also a multiselect feature associated with ListBox that (by holding the shift or CTRL and left clicks) allows you to loop through 'listcount':
cRight=[]
for c=1 to THISform.lstSource.ListCount
if THISform.lstSource.List(c).Selected=.t.
   cRight=cRight+[1]  && When selected
else
   cRight=cRight+[0]  && When Not selected
endif &&THISform.lstSource.List(c).Selected=.t.
* Note: This code has not been tested
endfor &&c=1 to THISform.lstSource.ListCount
I am just guessing at what you're trying to do. The STUFF and AT commands are very useful string manipulation tools.


>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
Imagination is more important than knowledge
Previous
Reply
Map
View

Click here to load this message in the networking platform