×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Something for the weekend #6: VFP functions
2

Something for the weekend #6: VFP functions

Something for the weekend #6: VFP functions

2
(OP)
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

RE: Something for the weekend #6: VFP functions

(OP)
Note re spoilers

If you are one of the first to post a reply, consider using [spoiler] tags to hide the answer from casual viewers. To use this tag, type [spoiler] at the start of the answer, and [/spoiler] 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

RE: Something for the weekend #6: VFP functions

Spoiler:

PI().

RE: Something for the weekend #6: VFP functions

Well, same result everytime on MY machine?
if so,

Spoiler:

?os()

if same everytime on ANY Machine?

Spoiler:

?pi()

Ez Logic
Michigan

RE: Something for the weekend #6: VFP functions

(OP)

Quote:

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:

Spoiler:


SET DECIMALS TO 2
x2 = PI()
SET DECIMALS TO 4
x4 = PI()
? x2 && 3.14
? x4 && 3.1416

Any comments on that?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Something for the weekend #6: VFP functions

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

RE: Something for the weekend #6: VFP functions

There are many of those, aren't there?

Spoiler:

? 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.
http://www.tek-tips.com/viewthread.cfm?qid=1746336
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.

RE: Something for the weekend #6: VFP functions

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.

RE: Something for the weekend #6: VFP functions

(OP)

Quote:

"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

RE: Something for the weekend #6: VFP functions

(OP)
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

RE: Something for the weekend #6: VFP functions

Consider this:

Spoiler:

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.

RE: Something for the weekend #6: VFP functions

(OP)
Olaf,

You are completely correct (although I'm not sure I understand why):

Spoiler:

? x2 && 3.14
? x4 && 3.1416
? x2 = x4 && .T.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Something for the weekend #6: VFP functions

Spoiler:


IsColor()
(Unless you have a video card older than VGA.)

RE: Something for the weekend #6: VFP functions

Spoiler:

RAISEEVENT()

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: Something for the weekend #6: VFP functions

(OP)
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

RE: Something for the weekend #6: VFP functions

Here are a few:

Spoiler:


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

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

Tamar

RE: Something for the weekend #6: VFP functions

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

Bye, Olaf.

RE: Something for the weekend #6: VFP functions

Quote:

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?)

Well, NOW it's a safe assumption. But there was a Mac version of VFP3. Nobody took it seriously, and for good reason, but it did exist.

RE: Something for the weekend #6: VFP functions

Quote (danfreeman)

Well, NOW it's a safe assumption. But there was a Mac version of VFP3. Nobody took it seriously, and for good reason, but it did exist.

I just tested SYS(13) in Mac VFP3. It returns "READY" even though I have no printer connected to the computer.

mmerlinn

http://mmerlinn.com

Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

RE: Something for the weekend #6: VFP functions

Quote (Mike Lewis)

- 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.)

In Mac VFP3, this returns "32-bit Color QuickDraw" on my machine which eliminates SYS(2006) from the competition.

mmerlinn

http://mmerlinn.com

Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

RE: Something for the weekend #6: VFP functions

Quote:

I just tested SYS(13) in Mac VFP3. It returns "READY" even though I have no printer connected to the computer.

That's correct and it's because VFP does not communicate directly with the printer (in either Windows or Mac). It communicates with the print spooler, which is always present whether there's a printer at the end of it or not.

RE: Something for the weekend #6: VFP functions

(OP)
Just to recap on some of the above points ...

There are clearly several functions that return information about the environment, and which always return the same value when running under Visual FoxPro for Windows. (And isn't it amazing that at least one person here was able to test these under VFP 3.0 for Mac?)

When I started this thread, the function I had in mind was PI(). At first, I was worried that this function is sensetive to SET DECIMALS. But that only affects how the returned value is displayed, not how it is stored internally. But I was confused by the following:

SET DECIMALS TO 2
x2 = PI() && X2 should be 3.141592653589793
? x2 && displays 3.14, as expected
SET DECIMALS TO 4
? x2 && still displays 3.14, not 3.1416, as expected
SET DECIMALS TO 18
? x2 && still displays 3.14


So the precision of the value stored in the variable reflects the setting at the time the variable was created, not what's in force when it's displayed.

And yet:

? STR(x2, 16, 15) && displays 3.14159265358979

You can see why I was confused.

Whatever .... PI() was the function I had in mind, as several of you immediately realised.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Something for the weekend #6: VFP functions

>So the precision of the value stored in the variable reflects the setting at the time the variable was created, not what's in force when it's displayed.
That's not the whole truth, eg consider:

CODE -->

Set Decimals To 2
lnPi = Pi()*1.0000
?lnPi 

Unlike any other language VFP considers a side calculation of the precisions of values involved. Unfortunately it's not always as nice, eg in division.

Bye, Olaf.

RE: Something for the weekend #6: VFP functions

Only for fun.
I guess this are the rules :
1) Variables
a) Multiplication
Number of decimal = sum(number of decimals)
b) Division
Number of decimals = max(SET(Decimals) + 2, sum(number of decimals))

2) Constants
a) Double constants
Number of decimals = max(SET(Decimals) , sum(number of decimals))
b) Integer constants
If the result is an integer then Number of decimals = 0
Else Number of decimals = SET(Decimals)

This is my test

CODE --> Foxpro

LOCAL setdec
setdec = SET("Decimals")
doit(0)
doit(1)
doit(2)
doit(3)
doit(4)
SET DECIMALS TO &setdec

PROCEDURE doit
LPARAMETERS setdec
LOCAL lnx
CLEAR
SET DECIMALS TO setdec
?"Set decimals to",SET("Decimals")
?
?"Multiplication"
lnx = PI()
? "lnx " , lnx
lnx = lnx * 1
? "lnx = lnx * 1" , lnx 
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx 
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx 
lnx = lnx * 1.00
? "lnx = lnx * 1.00" , lnx 
? "multiplication between two double constants","3.1*3.1=", 3.1 * 3.1
?
? "Division"
lnx = PI()
? "lnx " , lnx
lnx = lnx / 1
? "lnx = lnx / 1" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.00
? "lnx = lnx / 1.00" , lnx 
lnx = lnx / 1.000
? "lnx = lnx / 1.000" , lnx 
lnx = lnx / 1.0000
? "lnx = lnx / 1.0000" , lnx 
lnx = lnx / 1.00000
? "lnx = lnx / 1.00000" , lnx 
lnx = lnx / 1.000000
? "lnx = lnx / 1.000000" , lnx 
? "division between two double constants","3.1/3.1=", 3.1 / 3.1

?
?"Multiplication"
lnx = 1
? "lnx " , lnx
lnx = lnx * 1
? "lnx = lnx * 1" , lnx 
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx 
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx 
lnx = lnx * 1.00
? "lnx = lnx * 1.00" , lnx 
? "multiplication between two integer constants","2*1=", 2*1,"1*2=", 1*2
?
? "Division"
lnx = 1
? "lnx " , lnx
lnx = lnx / 1
? "lnx = lnx / 1" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.00
? "lnx = lnx / 1.00" , lnx 
lnx = lnx / 1.000
? "lnx = lnx / 1.000" , lnx 
lnx = lnx / 1.0000
? "lnx = lnx / 1.0000" , lnx 
lnx = lnx / 1.00000
? "lnx = lnx / 1.00000" , lnx 
lnx = lnx / 1.000000
? "lnx = lnx / 1.000000" , lnx 
? "division between two integer constants","2/1=", 2/1,"1/2=", 1/2

WAIT
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: Something for the weekend #6: VFP functions

We can't be too thankful or proud of this feature, though: Consider this bad example about the ^ operator:

CODE

? .123*.123
? .123^2 
For highest precision computing you should SET DECIMALS TO 18 (the output of .123^2 then also doesn't differ from .123*.123 in the numeric output, just in the indentation.

I did set decimals to 18 as default for a module computing percentages of ingredients of formulas/recipes, which even may need recursion.
You would still need to consider small corrections in cases of not having a 100% sum and overall it wasn't simple to come up with something acceptable.

Bye, Olaf.

RE: Something for the weekend #6: VFP functions

I guess the rule for power is
Number of decimals (b ^ e) = max(SET(Decimals) , number of decimals(b))

CODE --> Foxpro

LOCAL setdec
setdec = SET("Decimals")
doit(0)
doit(1)
doit(2)
doit(3)
doit(4)
SET DECIMALS TO &setdec

PROCEDURE doit
LPARAMETERS setdec
LOCAL lnx
CLEAR
SET DECIMALS TO setdec
?"Set decimals to",SET("Decimals")
?
?"Multiplication"
lnx = PI()
? "lnx = " , lnx,"lnx ^ 2 = " , lnx ^ 2,"lnx ^ 2.231 = " , lnx ^ 2.231
lnx = lnx * 1
? "lnx = lnx * 1" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.00
? "lnx = lnx * 1.00" , lnx ,"lnx ^ 2 = " , lnx ^ 2
? "multiplication between two double constants","3.1*3.1=", 3.1 * 3.1,"3.1 ^ 2 =",3.1 ^ 2
?
? "Division"
lnx = PI()
? "lnx = " , lnx
lnx = lnx / 1
? "lnx = lnx / 1" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.00
? "lnx = lnx / 1.00" , lnx 
lnx = lnx / 1.000
? "lnx = lnx / 1.000" , lnx 
lnx = lnx / 1.0000
? "lnx = lnx / 1.0000" , lnx 
lnx = lnx / 1.00000
? "lnx = lnx / 1.00000" , lnx 
lnx = lnx / 1.000000
? "lnx = lnx / 1.000000" , lnx 
? "division between two double constants","3.1/3.1=", 3.1 / 3.1

?
?"Multiplication"
lnx = 1
? "lnx = " , lnx,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1
? "lnx = lnx * 1" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.0
? "lnx = lnx * 1.0" , lnx ,"lnx ^ 2 = " , lnx ^ 2
lnx = lnx * 1.00
? "lnx = lnx * 1.00" , lnx ,"lnx ^ 2 = " , lnx ^ 2
? "multiplication between two integer constants","2*1=", 2*1,"1*2=", 1*2,"1 ^ 2 =",1 ^ 2
?
? "Division"
lnx = 1
? "lnx = " , lnx
lnx = lnx / 1
? "lnx = lnx / 1" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.0
? "lnx = lnx / 1.0" , lnx 
lnx = lnx / 1.00
? "lnx = lnx / 1.00" , lnx 
lnx = lnx / 1.000
? "lnx = lnx / 1.000" , lnx 
lnx = lnx / 1.0000
? "lnx = lnx / 1.0000" , lnx 
lnx = lnx / 1.00000
? "lnx = lnx / 1.00000" , lnx 
lnx = lnx / 1.000000
? "lnx = lnx / 1.000000" , lnx 
? "division between two integer constants","2/1=", 2/1,"1/2=", 1/2

WAIT
ENDPROC 

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: Something for the weekend #6: VFP functions

(OP)
I'll just wind down this thread. Thanks to everyone who took part. The original question was an easy one, but it led to a lot of interesting discussion, which is always good.

I'm running out of ideas for brain-teasers, so next time we have one of these threads, perhaps someone else can come up with an interesting question.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Something for the weekend #6: VFP functions

I have something, that might be a good question, I'll need to investigate a bit to see, whether the answer still is valid.

Bye, Olaf.

RE: Something for the weekend #6: VFP functions

Quote (Olaf Doschke)

I have something, that might be a good question
I just wait to see it !

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: Something for the weekend #6: VFP functions

I'll post it later - evening in CET, perhaps tomorrow morning. It'll have a little code with it, which I need to prepare.

Bye, Olaf.

RE: Something for the weekend #6: VFP functions

(OP)
Sounds interesting, Olaf. I suggest you make it a new thread.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Something for the weekend #6: VFP functions

This is only a little joke.
Create suspense, as in a thriller smile

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

RE: Something for the weekend #6: VFP functions

Of course this will have a new thread.

As a teaser: It's about Error 111.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close