Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Test for presence of field"

Test for presence of field

Current user: [none]
Register / Log In · Help

Posted By Post

Charles Welling

25-Sep-2006 06:22

I'd like to know if a field is present in a format before executing some commands in a macro. So far I had to use a loop that goes through all the field definitions of the current format, which is remarkably slow. I tried the following line (and similar ones):

if ActiveWindow.FieldDefinitions.Item("MyField").name="MyField" then ....

which in my opinion should generate some error if "MyField" is NOT present in the current format, but it always returns the correct name even if the field does not exist in that format. It looks as if specifically addressing a field in a Window object "sees" the field even if it's not there (it is in the database though).

Anyone having a bright idea?

Charles

bert

25-Sep-2006 08:20

Charles,
This gives in fieldlist a list of the current fields in a format.
Check with instr if the field you need is in the current format...!
regards
bert

Set d=ActiveWindow.FieldDefinitions
fieldlist=""
For each fd in d
    fieldlist=fieldlist & "," & fd.Name
Next

fieldlist = mid(fieldlist,2)

bert

25-Sep-2006 08:21

(nice time in above message - it was in this country 10:20...)

Charles Welling

25-Sep-2006 09:08

Thank you for your prompt reply Bert. The time of the message is GMT, but it was sent at GMT+1 (7.22) actually. But yes, I'm an early riser (5.15 AM to be exact).

But as I had already mentioned in my question: I do use a loop as you suggest as well. But in larger formats this loop takes noticeable time to be executed and my question was: does anyone have a solution to test DIRECTLY for the presence of a field, so without any loops.

Charles

Paul Irvine

25-Sep-2006 09:31

Charles

Try using the FieldDefinition Index property. If the field doesn't exist then the Index value is 0, otherwise it is the index in the FieldDefinitions collection (1 or greater)

if ActiveWindow.FieldDefinitions.Item("MyField").Index<>0 then ....

Paul

Charles Welling

25-Sep-2006 10:33

See? I knew there would be somebody out there who'd know the solution. Perfect!
Thanks Paul.

Charles

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home