Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating Index String
Message
From
29/11/2001 17:02:58
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00587680
Message ID:
00587755
Views:
29
>Here what I got after your response. I am still doing some wrong.
>
>lcNdxStr = 'INDEX ON ' + ALLTRIM(indextable.indexexp) + ' TAG ' + ALLTRIM(indextable.ctag) + ALLTRIM(region.c_region_id). This create INDEX ON ALLTRIM(indextable.indexexp) TAG ORGTWN. However my problem is when I go to add the for statement. What I need to happen is that it say FOR indextable.indexfilt = Alltrim(region.c_region_id). The For statement is based on what is stored in indextable.indexfilt that the field in the table (such as c_region) and the other portion to the right of the equal is stored in region.c_region_id. I hope I've made myself clear.
>
>Thanks

Milt --


It looks like you're trying to do a data-driven mechanism for reindexing and that's a robust approach.

Current thinking on indexing suggests avoiding the FOR clause. The advantage is that it's easy to set up a filtered view of data using one.

The disadvantages are that these indexes are not Rushmore optimizable. That, and the fact that you may have a number of different fields to filter on can lead to an unnecessary number of indexes.

The preferred approach is to index on fields individually that you'd use in a FOR clause. Then, just set a filter on the table in code. Or, use an updateable view.

It's hard to figure out from your description what problem you're running into with the FOR clause.

When I've constructed statements on the fly for macro sub and run into a problem, the resulting string usually tells the story.

Here are a couple thoughts:

1. Remember that if you're comparing the field value to a literal, the literal must be properly formatted in the final string. (Sometimes you have to go through some pretty ugly assigments to get the result you want.)

So, string literals must be quoted within the string:
"FOR myTable.cMyField = 'Hello, World'"

Logicals and numbers shouldn't be:
"myTable.lMyField = .T."
"myTable.nMyField = 2.00"

Date and time values need to be formatted properly:
"myTable.dMyField = {01/03/2001}"

2. If you're referring to a field in another table, that table must be open when you attempt to reindex or you'll get an error.

3. If you're referring to a variable, that variable must have a value when you attempt to reindex. It's easy to forget the quotes when equating to a string literal. Then, VFP interprets the statement as a variable rather than as a literal and you'll get a variable not found error message.

4. Both sides of the equation must evaluate to the same data type, or you'll get a data type mismatch.

HTH,

Jay
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform