Current Field Using «»

Local LCurrentWord
LCurrentWord = «»
SelectWithin «Words» NotContains LCurrentWord

Should be the same as

SelectWithin «Words» NotContains «»

Is there something I am missing as this is not working for me?

The selection criteria depends on what cell is active when the code is executed so the result could vary depending on that so I assume you controlled that. But more importantly, the value of «» is not fixed, but, I think, is evaluated for each row the selection statement is considering for inclusion in the selected group.

In your second selection, no records would ever be selected if the active cell were in the Words field.

My interpretation is that this attempts to select records in which the content of the active field is not contained in the Words field of the same record. If Words is the active field, each record is evaluated to see if Words does not contain itself.

Thre are 4 records. The Words field is the active field. The Words field has a unique value as compared to the other 3 records. I am wanting only the other 3 records to be selected.

If I use the simpler code, all records are selected. If I use the more complicated code, only the ‘other’ 3 records as selected. (as desired)

The «» should capture the value of the current field and use it in the evaluation of the formula, It is not working that way.

No. If the Words field is active, then «» is exactly equivalent to «Words». Writing

SelectWithin «Words» NotContains «»

is exactly the same as writing

SelectWithin «Words» NotContains «Words»

The longer version works because the value of a variable doesn’t change from one record to the next. The value of a field does, and «» is just a substitute for the name of the active field.

This would also have worked.

LCurrentWord = «»
SelectWithin «» NotContains LCurrentWord
1 Like

In my desire to think that we had a function that I could use in a formula that would equate to the value of the current cell, I did erroneously fall back on using the «» but of course that merely represents the current field rather than the value of the current cell.

Did I miss a method to easily grab the value of the current field without creating a local variable and assigning to it the value of the current field? There are so many functions that I’m always amazed at how many I’ve forgotten about.

It could be done with an Execute statement, but that just turns two simple statements into one complicated statement.

Execute "SelectWithin «Words» NotContains " + quoted(«Words»)

I would rather go with

Let LCurrentWord = «Words»
SelectWithin «Words» NotContains LCurrentWord

It’s a little more typing, but it doesn’t require the mental gymnastics of an Execute.

I think the problem here is a bit of misunderstanding of what the “current record” is. The current record is context sensitive. Of course in the default context the current record is the one you’ve clicked on, the one highlighted in the data sheet and/or displayed in a form. However, when you perform an operation that scans the database, the current record is temporarily switched to each record as the database is scanned. This applies to operations like select, find, formulafill, matrixes, and printing.

In your case you want to get the value of a field in the default context, then use that value in the scanned context. To do that, we need to grab the value in the default context and save it in a variable.

let LCurrentWord = «»

The variable is needed because the variable will retain the same value in both the default and scanned contexts. So we can use this variable to do the selection:

selectwithin «» notcontains LCurrentWord

Theoretically a function could be created that always returned the default context field value even when scanning. But there is no such function, and I think since using a variable works quite well this function isn’t necessary.