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!

Find the location of the column in the VFP table 2

Status
Not open for further replies.

bharons

Technical User
Jan 23, 2019
49
ID
Dear Expert..
I have a classic question. and I don't understand how to solve it, namely looking for a column where the contents of that column are exactly the same as the VFP textbox. The following is the coding that I use.

Code:
select crsResult3
lcVar = thisform.text1.value

for lnColumn = 1 to fCount()
   if Evaluate(Fields(lnColumn)) = lcVar 
     lnColumn = lnColumn + 1
   endif
endfor
ThisForm.text2.value = lnColumn

where I use textbox2 to see the column positions in the table.
If I use it with the Field() function, I can determine if the contents are in that column.
and the follow-up question is if the contents of the textbox are found in various tables, what coding do I apply to find the column position?

 
EinTerraner,

bharons is looking for a field that contains a searched value, the search value is not the field name, so this is not a search for a field name by a (partial) field name, but by content.
Think of it in the corner case of trying to search a value in all fields of a table and not only filtering records that have the value anywhere in any field, but also in which field.

As I said, it's not a usual question for SQL or also VFP xbase code.
 
EinTerraner,

bharons is looking for a field that contains a searched value, the search value is not the field name....
Ok: I got it. Mby i misunderstood the question. My english is not my natural language. Shame on me 😁

It means he'd like to scan the whole table to fins any specifig string odr substring?
In this case i used also AFIELDS(...) to create a list of all existing fields. Like this
Code:
SELECT(<alias>)
AFIELDS(TmpArr)
FOR Lc_I = 1 TO ALEN(TmpArr,1)
    DO CASE
    CASE TmpArr(Lc_I, 2) == "M" ;
    .OR. TmpArr(Lc_I, 2) == "C"
        LOCATE FOR AT(UPPER(MyString), UPPER(EVALUATE(<alias>+"."+TmpArr(Lc_I,1)))
        IF FOUND()
            ? "Record "+str(recno), "Field = "+TmpArr(Lc_I,1)
        ENDIF

    CASE TmpArr(Lc_I, 2) == "N"
    ENDCASE
ENDFOR
The funnie thing is... I had to use lately a similar search in a cpl FRX-Files
 
EinTerraner,

bharons is looking for a field that contains a searched value, the search value is not the field name, so this is not a search for a field name by a (partial) field name, but by content.
Think of it in the corner case of trying to search a value in all fields of a table and not only filtering records that have the value anywhere in any field, but also in which field.

As I said, it's not a usual question for SQL or also VFP xbase code

Ok: I got it. Mby i misunderstood the question. My english is not my natural language. Shame on me 😁

It means he'd like to scan the whole table to fins any specifig string odr substring?
In this case i used also AFIELDS(...) to create a list of all existing fields. Like this
Code:
SELECT(<alias>)
AFIELDS(TmpArr)
FOR Lc_I = 1 TO ALEN(TmpArr,1)
    DO CASE
    CASE TmpArr(Lc_I, 2) == "M" ;
    .OR. TmpArr(Lc_I, 2) == "C"
        LOCATE FOR AT(UPPER(MyString), UPPER(EVALUATE(<alias>+"."+TmpArr(Lc_I,1)))
        IF FOUND()
            ? "Record "+str(recno), "Field = "+TmpArr(Lc_I,1)
        ENDIF

    CASE TmpArr(Lc_I, 2) == "N"
    ENDCASE
ENDFOR
The funnie thing is... I had to use lately a similar search in a cpl FRX-Files
i used vfp 8, i got error missing ")" on statement:unsure:
 
Such errors are easily fixed by adding the missing bracket, bharons.

The code needs you to replace <alias> at several places with the alias or table name you want to search in. So if you want to try that alternative solution, first do that.
Also set a variable MyString to what you want to search.
 
If I understand correctly, you are asking for a given column in a grid control, what field is this being populated from? Is this correct? If so, you should be able to get the answer from the property:

Code:
?thisform.grdGrid.Column1.ControlSource
?thisform.text1.ControlSource

Another option would be to SCATTER the current record to an Array and then do an ASCAN on the array values.

Code:
SCATTER MEMO TO laValues
lnNdx = ASCAN(laValues, ALLTRIM(thisform.text1.value), 1, ALEN(laValues, 1), 1, 13)
?FIELDS(lnNdx)
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top