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

Substituting variables into statements 1

Status
Not open for further replies.

stanmurphy

Technical User
Oct 14, 2000
89
0
0
Hello all,

Is it possible to substitute multiple variables into a statement such as:

thisform.text1.value = m.columnX_rowY

where X and Y are the variables?

I have tried something like:

thisform.text1.value = m.column&X.._row&Y..

but it doesn't work.

Can anyone help, please.

Thank you.

Stan
 
What do you mean by substitute? You can use functions to evaluate and provide different variable based on analysis. Ie, IIF() ThisForm.Text1.Value = IIF(x = 1, x, y) this says if x = 1 then use the value of variable x if not then use the value of variable y. Perhaps a bit more of explanation of what you are doing would help. What is the variation of the value of thisform.text1.value based upon?
 
I have 68 text boxes arranged as a grid of colums and rows. Each text box is named for the row and column it is in. I.E. TextBox1_1, TextBox1_2, etc. In the click event of each text box I DO a program (the same program for all boxes), sending as parameters the row and column of the text box I've clicked on (they are stored in the text box's comment).

I want the program to be generic, so I want it to use the row and column parameters it receives to modify properties of the specific text box that called it.

How do I incorporate the row and column info into a statement.

For instance, in this called program, how would I write a statement that in one line would set the backcolor of the calling text box to red?

As in: FormName.textboxROW_COL.backcolor = rgb(255,0,0)
 
So is the function of this code to turn the background of the text box red when clicked?
 
It really doesn't matter what the function of the code is. I may want to do any number of things with it. That's why I put it in a generic program called by all the text boxes, so I can easily modify the program as my needs dictate.

The question is how to reference the particular text box using two different variables to insert it's name into a single statement.
 
In the test I did I had 2 text box's and in the click event used: DO myprg.prg WITH (This.Name)

In myprg.prg I have at the very top:
PARAMETERS lcTextBoxName

(this will set the lcTextBoxName to the name of the text box)
 
Stan,
It is possible.
But the values you use for macro substitutions should be string values.
So, if, say, your X=5 and Y=64,
and you want to get a command which evaluates to

thisform.text1.value = m.column05_row64 ,

you should do something like this:

XX=RIGHT('0'+ALLTRIM(STR(X,2)),2)
YY=RIGHT('0'+ALLTRIM(STR(Y,2)),2)
thisform.text1.value = m.column&XX._row&YY

Stella
 
Thank you Stella, it works perfectly!! :)

and thank you also for your assistance robsuttonjr
 
Another note: using bindevents you can bind a single snipet of code to every click event without editing every textbox. This is only available in FoxPro 8 however. You can even determine if the bound event fires your code before the default event code or after.
 
stanMurphy,

Try the following. But, I don't recommend it as a good way.

x='1'
y='2'
cCmd='FormName.'+'text'+x+y+'.backcolor=rgb(255,255,0)'
&cCmd


Best way is to define your own text box class and use it on your form.

Foxbldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top