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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable substitution within a loop

Status
Not open for further replies.

stanmurphy

Technical User
Oct 14, 2000
89
Hello All,

I am using the code below to clear a number of text boxes on my form. I tried the eval because I heard that a &variable will only be evaluated once in a loop. The eval seems to be working the same way. Does anyone know of another way to accomplish this task, that is, performing variable substitution within a loop?


FOR boxcount = 2 TO 7 && clear the names boxes on Appointment Form
eval("thisform.text"+(ALLTRIM(STR(boxcount)))+".value = ' '")
ENDFOR

 
try this..

for boxcount = 2 to 7
thisform.Text&boxcount..value = ''
endfor

notice the .. Please let me know if this helped you :)

Tekno
Wireless Toyz
Ypsilanti, Michigan
 
correction for the above post

for boxcount = 2 to 7
nCount = ltrim(str(boxcount))
thisform.text&nCount..value = ''
endfor
Please let me know if this helped you :)

Tekno
Wireless Toyz
Ypsilanti, Michigan
 
Thank you so much. It works wonderfully!!! I hadn't realized that I could put an & in the middle of a statement and end the & with a period.
 
Oops. I was wrong. It isn't working. this is what the help file for & says and this is my problem.

Macro substitution statements that appear in DO WHILE, FOR, and SCAN are evaluated only at the start of the loop and are not reevaluated on subsequent iterations. Any changes to the variable or array element that occur within the loop are not recognized.


Any suggestions????
 
What this help means is:

lcFor = "I = 1 to 10"
FOR &lcFor
lcFor = "I = 1 to 20"
?I && Executes 10 times
lcTst = ["]+tran(I)+["]
?&lcTst && This WILL print 1 thru 10
ENDFOR


lcWhile = ".T."
DO WHILE &lcWhile
lcWhile = ".F."
* Infinite loop.. never ends
ENDDO
 
HI
If your intention is to clear all the textbox controls..

Method 1:
*********
ThisForm.SetAll("Value","","TextBox")

Method 2:
*********
FOR EACH m.oThis IN ThisForm.Controls
IF m.oThis.BaseClass == 'TextBox'
m.oThis.Value = ""
ENDIF
ENDFOR

Method3
*******
If these text boxes are bound to table..
APPEND BLANK
ThisForm.Refresh will clear the values. It depends on your way of coding

Method4:
********
If you are using memory variables as control source..
Then..
SCATTER MEMVAR BLANK
ThisForm.Refresh
This can clear all your text box values..

:)





Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top