Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get field names that in an index key expression
Message
 
To
01/06/2005 15:20:02
Kay Alexander
Pennsylvania Farm Bureau
Pennsylvania, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01019098
Message ID:
01019152
Views:
19
Improved version of the function :o))) (Thaks to Sergey)
Not very improved but...
CLOSE DATA ALL
CREATE CURSOR cTest (Fld N(5), Fld1 C(10), Fld3 L,Fld4 C(10))
INDEX ON STR(INT(Fld))+PADL(ALLTRIM(Fld1),10," ")+Fld4+TRANSFORM(Fld3) TAG cTest

c1 = GetIndexKeyFields("cTest", "cTest")
FOR asd = 1 TO c1.FieldsCount
    ? c1.FieldsDef[asd,1]
    ? c1.FieldsDef[asd,2]
    ? c1.FieldsDef[asd,3]
    ? c1.FieldsDef[asd,4]
NEXT


FUNCTION GetIndexKeyFields(cOrder, cAlias)
  LOCAL cOldAlias, cKey, aFlds[1], nFlds, aLns[1]
  LOCAL nCnt, oEmpty, nLns, nAt, lFlUsed, aUsd[1]
  oEmpty   = CREATEOBJECT("Empty")
  ADDPROPERTY(oEmpty, "FieldsCount", 0)
  ADDPROPERTY(oEmpty, "FieldsDef[1,4]", "")
  cOldAlias = ALIAS()
  IF .NOT. USED(cAlias)
     SELECT 0
     USE (cAlias) IN 0
     lFlUsed = .t.
  ENDIF
  
  SELECT (cAlias)
  cKey  = KEY(TAGNO(cOrder),cAlias)
  nFlds = AFIELDS(aFlds,cAlias)
******* Here I have no idea for better way to strip all function names
******* and all unneccesary symbols so ONLY the field names to stay
******* If you made up something just remove these lines
  nLns  = ALINES(aLns,cKey,7,[+])
  FOR nCnt = 1 TO nLns
      lFlExit = .t.
      nAt  = AT([(],aLns[nCnt])
      cKey = aLns[nCnt]
      DO WHILE nAt > 0
         cKey = SUBSTR(cKey, nAt + 1)
         nAt  = AT([(], cKey)
      ENDDO
      nAt     = AT([,], cKey)
      IF nAt > 0
         cKey = LEFT(cKey, nAt - 1)
      ENDIF
      cKey       = CHRTRAN(cKey, [)],[])
      aLns[nCnt] = UPPER(cKey)
  NEXT


  FOR nCnt =  1 TO nFlds
      IF ASCAN(aLns, UPPER(aFlds[nCnt,1]),1,-1,1,15) # 0
         oEmpty.FieldsCount = oEmpty.FieldsCount + 1
         DIMENSION oEmpty.FieldsDef[oEmpty.FieldsCount, 4]
         oEmpty.FieldsDef[oEmpty.FieldsCount, 1] = aFlds[nCnt,1]
         oEmpty.FieldsDef[oEmpty.FieldsCount, 2] = aFlds[nCnt,2]
         oEmpty.FieldsDef[oEmpty.FieldsCount, 3] = aFlds[nCnt,3]
         oEmpty.FieldsDef[oEmpty.FieldsCount, 4] = aFlds[nCnt,4]
      ENDIF
  ENDFOR
  IF lFlUsed
     USE IN (cAlias)
  ENDIF
  SELECT (cOldAlias)

RETURN oEmpty
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform