Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Collection 1

Status
Not open for further replies.

myan

Programmer
Feb 12, 2002
8
GB
I want to acces a number of text controls on a form in a for next loop

Each control is delimited by a number eg txtAdd1, txtAdd2 etc

I was hoping a loop similar to

for lnCnt = 1 to 3
lcControlName = "txtAdd"+transform(lnCnt)
thisform.controls(lcControlName).value = lnCnt
next

obviously this does not work but what would?

many thanks
Paul
 
Paul

Untested but :-

for lnCnt = 1 to 3
[tab]lcControlName = "txtAdd"+transform(lnCnt)
[tab]IF thisform.controls(lcControlName).Name = lcControlName
[tab][tab]* code
[tab]ENDIF
next

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
myan

LOCAL lcControlName
FOR I = 1 TO THISFORM.ControlCount
lcControlName = "text"+TRANSFORM(i)
ENDFOR

But you want to replace the value with the control number? I don't understand.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
hej !
for lnCnt = 1 to 3
lcControlName = "txtAdd"+transform(lnCnt)
thisform.controls(lcControlName).value = lnCnt
next

i'll change to:
for lnCnt = 1 to 3
lcControlName = "txtAdd"+alltrim(str(lnCnt))
thisform.controls(&lcControlName).value = lnCnt
next

or:
for lnCnt = 1 to 3
lcControlName = "txtAdd"+alltrim(str(lnCnt))
zm_n='thisform.controls('+lcControlName+').value = lnCnt'
&zm_n
next
Kind regards from Warsaw !!!!!
Monika (monikai@yahoo.com)
 
Chris your method is the one that I was using, i was looking for a method where i didnt have to go through all the controls on the form.

Mike the lnCnt number was just an example of setting the control to a value. I'm actually attempting to loop through a number of address fields and back filling with address info.

Monikai I was hoping your ideas would work but alas no, vfp 7 does not allow you to use an index of type string in the controls collection. Help does not say what type index is!

So currently I'm looping through all the controls on the form until I get a match.

Any other ideas
Paul
 
Try something like:

for lnCnt = 1 to 3
lcControlName = "text"+transform(lnCnt)
ThisForm.&lcControlName..value = 'Dave' + transform(lnCnt)
next
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top