Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6670 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

FMP8A on Windows XP

There's probably an answer to this somewhere on the forum, but I've looked and can't find it.

Problem: I'm trying to copy and paste four fields from an existing record in table "A" to a new record in (unrelated)table "B" via a script. Copy and paste seems to work fine but I'm wondering if there is a more elegant/appropriate method that would achieve the same results? I experimented with Set Field but I guess I don't know enough about it. :confused: TIA LM

Posted (edited)

If the tables are truly unrelated, you might want to use script variables. Something like:

Set Variable [$$First; Value:TableA::Field1]

Set Variable [$$Second; Value:TableA::Field2]

Set Variable [$$Third; Value:TableA::Field3]

Set Variable [$$Fourth; Value:TableA::Field4]

Set Field [TableB::Field1; $$First]

Set Field [TableB::Field2; $$Second]

Set Field [TableB::Field3; $$Third]

Set Field [TableB::Field4; $$Fourth]

Edited by Guest
Made variables global
Posted (edited)

When you use set field script you should have a global field. or a vriable

Script colud be like this

set filed [TableA::Filed; global field]

Got lay out

set field [table B::field; global field

Go to layout[original]

Edited by Guest
Posted (edited)

Get to know the Set Field command. It is one of the most commonly used commands in the world of FM. I would bet that most experienced developers rarely if ever use copy/cut and paste. I hardly ever find a reason to use it myself.

Edited by Guest
Posted

Perhaps Ted it would make more sense if you told why developers avoid it?

The reason is that Copy/Paste should be reserved for inter applicational movements of data, while the avarage scripts hardly ever falls in that category.

Worstcase scenario is the user having stored something to paste later, the script will then make it evaporate into thin air by overwriting.

I regard it as a bad developer habit to use copy/paste at all in scripts. If the user might grap something for other applications should it be done deliberately by hand!

--sd

Posted (edited)

If you have FM8, K1200's method is good, but if you're doing the whole process in one script, use script variables, not globals. (I.e. use $, not $$.) Script variables disappear once your script is done, which means one less thing to have to manage.

Also note that if you're moving data from one file to another, global variables won't help, as they are file-specific.

At any rate, LM is using FM7, so he can't use variables. But as sherif pointed out, you can do the same thing using global fields instead of $$First, $$Second etc.

Edited by Guest
Oops... I just noticed that your profile says FM7 but your question was using FM8, so yes, variables would work just fine.

This topic is 6670 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.