1

Konu: Initialization of environmental parameters

Hello:

The MS help on how to deal with SET commands in the main file is this:

IF SET('TALK') = "ON"
   SET TALK OFF
   cTalkVal = "ON"
ELSE
   cTalkVal = "OFF"
ENDIF

I tried to be a little inventive, and instead did this:

vctalk = SET('TALK')
SET TALK OFF
.
.
READ EVENT
.
.
SET TALK &vctalk  && Resetting to previous values


While this worked from the Command window, it did not work when I run the program. I do not know if it is because the data in vctalk
is U (unidentified). Would be interesting to know why it did not work.


Now, there are a few other things to consider:

SET TALK ON | OFF | WINDOW [WindowName] | NOWINDOW

shows that there is not only  ON/OFF to take into consideration, but also WindowName and NOWINDOW. How would one change and reset that?

And, if one runs an app and then end it with a QUIT, is it at all necessary to reset the SET parameters?

Thank you for your help.

Hans L

2

Re: Initialization of environmental parameters

you could prefer below codes Hans,
first check the talk status then set your option on|off after then set back to first status

Visual Fox Pro
vctalk = SET('TALK')

if SET (TALK)='ON'
set talk OFF
READ EVENT
endif
SET TALK &vctalk  && Resetting to previous values

3

Re: Initialization of environmental parameters

Soykan, I am sorry, but I forgot to mention what did not work.

Everything worked up til SET TALK &vctalk, but SET TALK &vctalk gave an error message ("Syntax error").

Well, I tested by removing a lot of  stuff and only kept this in a separate prg file::

vctalk = SET('TALK')
SET TALK OFF
.
.
SET TALK &vctalk

Now, it works fine. No error message for SET TALK &vctalk. So, it has something to do with

DO twsmame.prg
READ EVENTS

I do not know what could happen. I do not use vctalk anywhere else, and just before SET TALK &vctalk, I check, and have "TALK OFF" and the data in vctalk is still U (unidentified).

Any suggestions about what might happen?

Regards,

Hans L

4

Re: Initialization of environmental parameters

use brackets () instead of & (macro)

Visual Fox Pro
vctalk = SET('TALK')

SET TALK OFF
.
.
SET TALK (m.vctalk)

5

Re: Initialization of environmental parameters

Will do!

Hans L

6

Re: Initialization of environmental parameters

Did you tried my suggestion ?

7

Re: Initialization of environmental parameters

SET TALK (m.vctalk) results in an error message in the simplified file I run (no DO twsmame.prg
READ EVENTS)

SET TALK &vctalk does not result in an error message in the same file.

Regards,

Hans L

8

Re: Initialization of environmental parameters

Maybe it does not work because vctalk is not really a name?

Hans L

9

Re: Initialization of environmental parameters

Visual Fox Pro
vctalk = Set('TALK')

 
Wait Window m.vctalk
 
If Set ('Talk')='ON'
    Set Talk Off
    &&READ EVENT or do what ever
Endif
Set Talk &vctalk

above codes works for me w/o error

10

Re: Initialization of environmental parameters

I had a CLEAR ALL in twsmame.prg, so when I had

twsmame.prg
READ EVENTS

the memory variables were cleared, so when the main file again got focus, it did, of course, crash.

Everything now works if I have &vctalk, but if I have (m.vctalk), I still get an error message.

It is not a big deal to use & here, because it is at the end of the entire program, and only a few SET ... are executed, and then QUIT.

Any comments? In any event, thank you for encouraging me to search for the resolution, Soykan,

Regards,

Hans L

11

Re: Initialization of environmental parameters

some Quotes (translated) from Cetin about using macros,

* first rules in macros "use if necessary " smile

* general pference is usage name expressions

* & is working 99%  but loosing speed and causing errors such as "unrecognized command"

* basically macros executings any strings like you written your hand

let us showing some examples

lcFields = "company, contact, cust_id"
lcTable = "customer "
lcColumn = "country"
lcValue = "USA"

* some picked values from users

lcSelect = "select "+m.lcFields + from " + ;
m.lcTable + " where " + m.lcColumn + "[" + m.lcValue +  "]"
&lcSelect

results is like below

Visual Fox Pro
select company, contact, cust_id from customer  where country = [USA]

at this point some sections needs macro but some of sections need 'name expression' instead of fixed and macro

first prefence for name expression : fileName, windowName, tableName, aliasName .. using between brackets ()

Visual Fox Pro
lcAlias = "customer"

select lcAlias && search for alias named lcAlias
select &lcAlias && mean : select customer - dont use!
select (lcAlias) && lcAlias is a name expression and written like select customer - use it !

let us examine below codes

Visual Fox Pro
lcFields = "company, contact, cust_id"

lcTable = "customer "
lcColumn = "country"
lcValue = "USA"
 
* some picked values from users
 
select &lcFields from (m.lcTable) where evaluate(m.lcColumn) = m.lcValue

we can also use like below

Visual Fox Pro
select &lcFields from (m.lcTable) where &lcColumn = m.lcValue

step by step examination

lcFields: a column list . we can not use instead of  'name expression' or  evaluate() . macro necassary smile

lcTable: table/cursor/alias name. each one specially for name expression smile

lcColumn: a column name , at the first look it seems we need 'name expression' but here we need column value not column name

if we cant use Name expression there is evaluate and macro alternatives so at the first sample we used evaluate() then macro.

another bad sample

Visual Fox Pro
lcFileName = getfile("TXT")

copy file &lcFileName to yeni.txt

above codes may be tested 100 times w/o error smile but customer can call you tomorrow ! why ?

may be you selected a file from folders which containing w/o space like "c:\temp\file.txt"  but customer may be be selected like "c:\Program files\my file.txt" smile

result is like below

Visual Fox Pro
copy file c:\Program files\my file.txt to new.txt

error ! just we need name expression smile

Visual Fox Pro
lcFileName = getfile("TXT")

copy file (m.lcFileName) to new.txt

12

Re: Initialization of environmental parameters

Okay, and the more I read (although I am not experienced), the more I think I understand that name expressions did not work in my case, because "ON" and "OFF'  are not names.

I will read the above from Cetin again later. Saved it.

Regards,

Hans L

13

Re: Initialization of environmental parameters

Hans,
Name expression wouldn't work in your case because it is not a 'name'. It is an 'ON/OFF' setting. You would need to use &. Clear all is the culprit. To protect such variables from clear all you could instead use a property. ie:

Visual Fox Pro
_screen.AddProperty('SetTalk', set('Talk') )

SET TALK OFF
.
.
READ EVENTS
.
.
local lcSetTalk
lcSetTalk = _screen.SetTalk
SET TALK &lcSetTalk  && Resetting to previous values

14

Re: Initialization of environmental parameters

Okay, great. First, I am glad I used what I used, so that I discovered the "Clear all", which could have caused other problems. Second, I have to read up on _screen and AddProperty and the like, since I have not used much ot it at all. However, I will use your suggestion here.

Thank you, Cetin.

Hans L