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

using a variable for a filed name 1

Status
Not open for further replies.

benny7

Programmer
Oct 3, 2004
31
GB
I have 15 field with similar names. These just differ by the number at the end.
Currently I am using case statements to populate these fields. Is it possible to use a variable name as a field. If so I could use something like m.type_ + nvar = ...

Is there anything like that I can do?

for nvar = 1 to arraySize
do case
case nvar = 1
m.type_1 = val(tmpDenom(nvar,1))
case nvar = 2
m.type_2 = val(tmpDenom(nvar,1))
case nvar = 3
.......
 
Try macro substitution:
Code:
for nvar = 1 to arraySize
  lc = alltrim(str(nvar))
  m.type_&lc = val(tmpDenom(nvar,1))
next nvar
The & tells fox to evaluate the string expression which follows.

Evaluation stops when it reaches a period. The example from Help:
Code:
x = "Fox"
? "&x.Pro"
prints "FoxPro"

Geoff Franklin
 
While Geoff has told you how to do what you want, I have to ask why. Usually, when you have a series of fields with the same name and a digit at the end, it's a sign that your database isn't properly structured. What are you trying to represent here?

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top