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

Invalid function error & filter problems 1

Status
Not open for further replies.

mmerlinn

Programmer
May 20, 2005
745
US
[ ]

Can anyone tell me what is going wrong here?

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
GO 2
[/blue]
[/tt]

[tt][blue]
z = 2
SELECT mytable
SET FILTER TO myfilter
GO z
[/blue]
[/tt]

Both of the above work fine.

NONE of the following work.

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
GO TOP
[/blue]
[/tt]

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
GO BOTTOM
[/blue]
[/tt]

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
GO BOF()
[/blue]
[/tt]

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
GO EOF()
[/blue]
[/tt]

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
SKIP
[/blue]
[/tt]

These throw error #11 "Invalid function argument value, type, or count." in the last line.

AND the FILTER is set to OFF in the same line.

In the COMMAND window they ALL work.


mmerlinn


"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 Steven Raymond
 
What is the value of myfilter? And, if you have created a logical condition as a string, such as:
Code:
myfilter = "field1 = 5"

don't you have to use macro substitution? Such as:

Code:
SET FILTER TO &myfilter

Teresa
 
[ ]

I am not where I can double check the SET FILTER TO line.

However, before I posted, I did the following in every case:

[tt][blue]
SELECT mytable
SET FILTER TO myfilter
x = SET('FILTER')
GO whatever
y = SET('FILTER')
[/blue][/tt]


In every case, [tt][blue]x[/blue][/tt] was correct. In the first two cases [tt][blue]y[/blue][/tt] always equaled [tt][blue]x.[/blue][/tt] In all other cases [tt][blue]y[/blue][/tt] was empty.



mmerlinn


"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 Steven Raymond
 
[ ]
When I did the above in the command window, [blue][tt]y[/tt][/blue] always equaled [blue][tt]x[/tt][/blue] ( [blue][tt]y[/tt][/blue] was never empty.)

mmerlinn


"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 Steven Raymond
 
These two statements seem to contradict each other:
mmerlinn said:
I am not where I can double check the SET FILTER TO line.
mmerlinn said:
In every case, x was correct.

If you can't check the filter, how do you know that x is correct?

Anyway, it seems that you are saying that the "GO" statement (except a GO to a particular record number) erases the filter in a program but not in the command window.

Teresa
 
One issue for sure. You can't say GO BOF() or GO EOF(). That will always error.

Otherwise, it appears that the problem is in the filter. Have you tried stepping through the code in the Debugger, so you can see exactly what's going on?

Use the FILTER() function to find out what the filter is set to.
 
[ ]
Teresa

Re-read what I said. I was not inconsistent.

Here are the steps I took:

1) Discovered I had an error problem.
2) Tested, tested, and retested, both in the program and in the command window.
3) Posted the problem in this thread (from the computer that FoxPro is installed on in Oregon).
4) At home I saw the first replies.
5) Made two posts (from home in Washington on a different computer that does not have FoxPro installed) to clarify what I had posted the day before.
6) Now back in Oregon on the computer FoxPro is installed on.

As far as the GO (and SKIP) statement erasing the FILTER, that is exactly what is happening in the program, but not in the command window.

Also note that GO is moving the record pointer only in the command window and when specifying an absolute record in the program. SKIP moves the record pointer in the command window but throws the error noted above when used in the program and does not move the record pointer.

Tamar

After rereading the specifications for GO/GOTO, EOF(), and BOF() in my manual, I realized that you are correct about EOF() and BOF(). Like how can GO move to the logical value that EOF() and BOF() return? Therefore I should get errors using them this way. I will make sure all such instances are eradicated from my programs. What floors me is how I could even think of doing such a stupid thing after 13 years of programming with FoxPro.

However, that still does not answer why GO TOP, GO BOTTOM, and SKIP all throw errors, fail to move the record pointer, and erase the FILTER.

To the best of my knowledge, the only way any of them should throw an error is when there is a typo in the line they are in. I have also checked for typos by using all lower case. Case makes no difference - same error is still being thrown.

**********

If I get a chance, I will do some more testing in the next day or so and see if I can isolate any clue to solve this dilema.

mmerlinn


"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 Steven Raymond
 
I feel fairly certain that the problem is that you have something in the filter expression that's causing the error when you attempt to move the record pointer.

I also realized after my last post that this is the old FoxPro section, so the debugging tools are a lot weaker. Nonetheless, you should be able to use the Debug and Trace windows to figure out what's going on.

I'm not sure whether the FILTER() function exists in your version, but SET("FILTER") should work.

Tamar
 
[ ]

FILTER() is available to me. I just never have used it (Did not realize it was there). I have always used SET("FILTER") as noted above.

Will cut & paste an exact snippet when I get back to where the code is run.

mmerlinn


"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 Steven Raymond
 
[ ]
Ok, here is the code.

[blue][tt]
PARAMETERS qOldValue
PRIVATE ALL LIKE z*

zworkarea = SELECT()
zcurrwin = FORMAT(WOUTPUT())

IF EMPTY(ALIAS())

********************
*
* If this hits, it probably means that the screen
* program has not opened any tables.
* Remedy by resetting environment and setting screen
* to automatically open files.
*
********************

=NOGO(LINE(), zworkarea, zcurrwin, '', 'W_screen EMPTY(ALIAS) error')
ENDIF

********************
*
* If filters do not work correctly check order of
* of all related tables. If any order is wrong,
* then all tables default to end of file,
* ignoring filter conditions.
* Also make sure incoming table is correct.
*
********************

DO CASE
CASE zcurrwin == 'Widmarks'

CASE zcurrwin == 'Wtoothcnt'

CASE zcurrwin = 'Wpixfile'
= FilterOff(ALIAS()) && Turn off filters for parent & all child tables
IF LEN(p_ourptnum) > 2
= TWININFO('Get')
= TWININFO('Save', '') && Blank out wiwinstack field in wininfo table
SET FILTER TO ;
LEFT(p_ourptnum, 2) == LEFT(pixfile.pfpicnum, 2) ;
AND LEFT(p_famname, 2) == pixfile.pffamgrp ;
AND NOT DELETED(ALIAS())
ENDIF

= WIN_RSTORE()

RETURN

CASE zcurrwin = 'Wshipping'

CASE zcurrwin = 'Webayparm'

CASE zcurrwin = 'Webayinfo'

CASE zcurrwin = 'Wpimerge'

CASE zcurrwin = 'Wpiunam'

CASE zcurrwin = 'Wvehidx'

ENDCASE

SELECT (zworkarea)

RETURN
[/tt]
[/blue]

*****************

This is the program where the error happens. Errors always hit the [red]red[/red] lines.

[blue][tt]
********************
*
* Restore environment and current window to previous state
*
* SYNTAX:
* = Win_Rstore()
*
* CALLed by:
* NB_VALID()
* SCRNSETUP()
* V_PB()
*
********************

PRIVATE ALL LIKE z*

zworkarea = SELECT()

zfound = TWinInfo('Get')

IF zfound AND NOT EMPTY(m.wiwinstack)
IF EMPTY(cfamname) OR m.cfamname = cfamname
zmemo = m.wiwinstack
DO WHILE NOT EMPTY(zmemo)
z = ATXLEFT(zmemo, ',')
zmemo = ATXRIGHT(zmemo, ',')
= TSELECT(z)
z = ATXLEFT(zmemo, ';')
zmemo = ATXRIGHT(zmemo, ';')
GO VAL(z)
ENDDO

SELECT(zworkarea)

= WLOAD(ALIAS())
ELSE
zfound = .F.
ENDIF
ELSE
&& Needed when wiwinstack is empty and record is found
zfound = .F.
ENDIF

SELECT(zworkarea)

IF EMPTY(zfound)
IF EOF()
[red]GO TOP[/red]
ELSE
[red]SKIP 1[/red]
ENDIF

IF EOF()
[red]GO BOTTOM[/red]
ELSE
[red]SKIP -1[/red]
ENDIF

IF BOF()
[red]GO TOP[/red]
ENDIF

= WLOAD()
ENDIF

RETURN zfound
[/tt]
[/blue]

**************

The above reduced to its simplest reproducible error conditions is:

[blue][tt]

SELECT pixfile

SET FILTER TO
SET FILTER TO ;
LEFT(p_ourptnum, 2) == LEFT(pixfile.pfpicnum, 2) ;
AND LEFT(p_famname, 2) == pixfile.pffamgrp ;
AND NOT DELETED(ALIAS())

[red]GO TOP[/red]

RETURN
[/tt]
[/blue]

The above resets the filter to "" and does not move the record pointer. If I substitute BOTTOM or SKIP for the TOP, the results are the same.

As soon as I get more time I will play with this some more. It must be something real simple that is totally escaping me.


mmerlinn


"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 Steven Raymond
 
[ ]
Mike

Turns out that [red]p_famname[/red] was not being set correctly at all. Once set properly, everything worked as it should.

However, I did rework the FILTER expression along the lines of your suggestion. I did it mainly because of the DELETED(ALIAS()) issue which I have run into before in SQL statements.

I did have a problem with your example, though. It has an ODD number of quotes, so I was somewhat confused as to what you meant.

I changed my original FILTER expression to this:

[tt][blue]
zalias = ALIAS()
zcmd = "SET FILTER TO LEFT(pixfile.pfpicnum, 2) == LEFT(p_ourptnum, 2) ;
AND pixfile.pffamgrp == LEFT(p_famname, 2) ;
AND NOT DELETED(zalias)"
&zcmd
[/blue]
[/tt]

Because of my confusion I was not clear as to whether this is what you meant or not.

mmerlinn


"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 Steven Raymond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top