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

Something for the weekend #6: VFP functions 2

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
An easy one this time. I expect we'll see some good replies before the end of Friday.

Can you think of any built-in VFP function that is always guaranteed to return exactly the same result every time you use it?

Just to be clear, the function will either take no parameters; or, if it takes one or more parameters, it will return the same result regardless of what parameters you pass.

Off-hand, I can think of one possible contender, although I'm not completely sure of it.

Before you post a reply, please see my note below re spoilers.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Note re spoilers

If you are one of the first to post a reply, consider using
tags to hide the answer from casual viewers. To use this tag, type [ignore]
[/ignore]
at the start of the answer, and [ignore]
[/ignore] at the end. Note that the tag is delimited by square brackets, not angle brackets.

Alternatively, you can use the spoiler icon on the toolbar - the one that looks like a birthday present wrapped in red ribbon.

To check that you have done this right, use the Preview facility before submitting your post.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, same result everytime on MY machine?
if so,
?os()

if same everytime on ANY Machine?
?pi()

Ez Logic
Michigan
 
Well, same result everytime on MY machine?

No, sorry - not allowed. It has to always be the same - regardless of the computer, VFP version, Windows version, day of the week, whatever.

The other suggestions are what I had in mind. But consider this:

[tt]SET DECIMALS TO 2
x2 = PI()
SET DECIMALS TO 4
x4 = PI()
? x2 && 3.14
? x4 && 3.1416[/tt]

Any comments on that?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Set Decimals" changes the value you see displayed on the screen, not the actual value.
 
There are many of those, aren't there?

? MEMORY() && since foxpro became "Visual" always returns 640 - You will get different results for MEMORY(n) though.
? ALANGUAGE(laLang) && aside of the name of the resulting array, the value will always be the same, as the language doesn't change. It will differ in different VFP versions though.
If you take SYS(n) with a specific n as one function, there are several SYS() functions returning a constant result. If you see it as one function, the result obviously varies with the main first parameter.
Of course on of these syss functions is
? SYS(12) && as mentioned in MEMORY()
? SYS(9) && serial number, will differ in different versions, of course. This is also displayed in the "About Microsoft Visual FoxPro" dialog.
...

Bye, Olaf.
 
I didn't write that link in there.

Not the first time it happens, it links to this same thread.

I was wrong on at least one function mentioned. And I see which function I forgot now. Shame on me. Didn't thought about it.

Bye, Olaf.
 
"Set Decimals" changes the value you see displayed on the screen, not the actual value.

That's right. So, how do you explain the code I posted? The last two lines appear to show different results, even though DECIMALS is set to 4 for both of them.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Olaf,

Your first suggestion is good. As far as I can see, it meets the requirements.

However, I'm less happy with your other suggestions, because they will return different values in different environments (VFP version, etc).

SYS(n) for a given n is OK, if it always returns the same value, but the only one I can think of is the one you quoted. Do you know any others.

In order to widen the discussion, I'm prepared to accept any functions that return a different value in FPD or FPW (or even Foxbase), provided the returned value is constant in Visual Foxpro.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Consider this:

SET DECIMALS TO 2
x2 = PI()
SET DECIMALS TO 4
x4 = PI()
? x2 && 3.14
? x4 && 3.1416
? 100*x2 && 314.16, so the other digits are still stored in x2. Numeric variables have a precision stored with them.

Bye, Olaf.
 
RAISEEVENT()

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Earlier, Olaf mentioned that some SYS() functions would qualify - assuming you accept that the first parameter makes it a unique function (in other words, SYS(1) is a different function than SYS(2), and so on).

I've just been looking through the list of SYS() functions, and I see that a lot of them always return an empty string. These are essentially functions that perform some task; the returned value is irrelevant. Examples include SYS(1500) - Activate a System Menu Item; SYS(1023) - Disable Help Diagnostic Mode; and SYS(3056) - Read Registry Settings.

I also spotted:

- SYS(13) - Printer Status - "For versions of Visual FoxPro running on Windows, SYS(13) always returns READY." (Is it safe to assume that Visual Foxpro will always run under Windows?)

- SYS(2006) - Current Graphics Card - "Returns the type of graphics card and monitor you are using." On my system, the returned value is "Color/Color". Can we assume that would always be the same? (Dan suggested something similar.)

Anyway, I hope some of you find this sort of thing interesting. I certainly do.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Here are a few:

SYS(23)
SYS(24)
SYS(13)
PRINTSTATUS()

I can probably dig up some more, but I'll leave some fun for others.

Tamar
 
Some system variables are also constant since a very long time, eg _Mac and _Windows.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top