PDA

View Full Version : Really Indirect Addressing


ABC123

dik_coleman
09-02-2006, 08:08 AM
Is it possible to construct a 'script line' that can address a table using character variables??

"What?"; you say..........

Consider a matrix: 3 by 3
Rows named: A,B,C
Cols nameed: D,E,F

Data boxes named: AD, AE, AF and BD, BE, BF and CD, CE, CF

Table record has ten fields, nine (all char): same as data boxes and one logical field.
Table only has one record -- it's a temp data stg tbl.

On a form:

Radio Button1: Choices: A,B,C ------------- Character var
Radio Button2: Choices: D,E,F ------------- Character var
Radio Button3: Choices: 1,2,3,4,5,6,7,8,9 --- Character var

Radio Button4: Choices: Key, Work -------- Logical Var Key=.t., Work=.f.
The logical field is used to determine display color and to disable the box to prevent changing the value.

Make a choice for each button : eg A, F, 3, Key

Trim and combine the row/col vars into one char var 'AF' (named--newvar) and the value into newval.


After opening the table -- t=table.open("tablnam")
then
is it possible to say:

t.change(begin)
t.newvar=newval
t.change(end)

Don't consider the verbage, just the concept....

I get no errors, but nothing happens to the table contents.

D

Tom Cone Jr
09-02-2006, 08:35 AM
Instead of:

t.change(begin)
t.newvar=newval
t.change(end)

The indirection you need is supplied by the eval() function.

Here's an example made with AlphaSports:


t = table.open("customer")
?t.lastname
= "Graham "

dim a as C = "Last"
dim b as C = "name"
dim fieldname as C
fieldname = a + b
?fieldname
= "Lastname"
?eval("t." + fieldname)
= "Graham "

t.change_begin()
eval("t." + fieldname) = "Jones"
t.change_end(.t.)
?t.LASTNAME
= "Jones "

Tim Kiebert
09-02-2006, 08:40 AM
Try
t.change(begin)
evaluate_template("t."+newvar +"="+s_quote(newval))
t.change(end)

Edit: Tom answered faster and is simpler. The connection must be slower from Oz. :)

Tom Cone Jr
09-02-2006, 08:56 AM
Tim, actually my answer was wrong, but has just now been corrected. -- t

dik_coleman
09-04-2006, 08:08 PM
Thanx a bunch guys....
Don't know where you find the answers, but glad you do.

D

Richard Froncek
10-30-2007, 12:36 PM
Code follows:

'newname contains 10261445 (mmddhhmm)
newname = eval(newname)
ui_msg_box("New Name", str(newname)) ' correctly displays the date-time
'File.rename("C:\transorders\transord.zip","C:\transorders\eval(newname).zip") ' 1
'File.rename("C:\transorders\transord.zip","C:\transorders\newname.zip") ' 2

Neither '1' or '2' is the desired result. The desired result is to have 10261445 as the file name.
The purpose of course is to correctly identify the file(s) in the folder, else they all have the same name.
So the question is, "How does one actually get the evaluated name as the name of the file?
Dick

Stan Mathews
10-30-2007, 12:44 PM
Note the way newname is used in the msg box, no surrounding quotes.....

"C:\transorders\eval(newname).zip" - enclosed in quotes this is exactly the text inside the quotes.

To substitute the value of the variable newname you have to stop and restart the literal text and concatenate the variable value in the middle.

File.rename("C:\transorders\transord.zip","C:\transorders\\"+newname+".zip")

Richard Froncek
10-30-2007, 12:51 PM
Thank you so much.
Dick