Jump to content
Developer Wiki and Function Reference Links ×

Structure for Variable within Lookup.


Recommended Posts

Just wondering if anyone can help me with the SetWSCellFormula command. I was trying this:

Procedure Test;

VAR

FL :String;

SN,TN :Integer;

WSH :Handle;

Begin

SN:=1;

TN:=10;

WSH:=CreateWS(Concat('Test',Date(2,1)),10,5);

While SN<=TN Do

Begin

Case SN of

1: FL:='A';

2: FL:='B';

3: FL:='C';

4: FL:='D';

5: FL:='E';

6: FL:='F';

7: FL:='G';

8: FL:='H';

9: FL:='I';

10: FL:='J';

End;

SetWSCellFormula(WSH,SN,0,SN,0,'=Database((R IN [''TestRecord'']) & ([''TestRecord''.''FieldA'']=FL))');

SN:=SN+1;

End;

End;

Run (Test);

So the loop through seems to work fine although I only know this because I get 10 error message saying invalid factor. I've been struggling a lot with the SetWSCellFormula line, it works supremely well with the =database(R IN [''testrecord'']) by itself but I think I've broken it with a lookup with a variable.

Thanks in advance, especially if you read this far!

James

Link to comment

You can't use variables directly in the criteria. You need to use the Concat function to make a single string that is exactly the criteria you want and then use that string as the criteria.

MyCriteria:=Concat('=Database((R IN [''TestRecord'']) & ([''TestRecord''.''FieldA'']=FL))');

SetWSCellFormula(WSH,SN,0,SN,0,MyCriteria);

I have not looked at this extremely closely, but make sure all of your quotes and escaped quotes are correct.

Link to comment

Expanding on Pat's observations, these are my 2 cents which are based on a working script.

MyCriteria:= Concat('=DATABASE((''TestRecord''.''FieldA''=', FL, '))');

SetWSCellFormula(WSH,SN,0,SN,0,MyCriteria);

You do not need 'R IN [''TestRecord'']' because the second argument implies FieldA is in TestRecord.

Make sure you type 2 single quotes '' and not just a double quote "

Link to comment

I just realized that the default font does not help in showing the two single vs double quotes. So here it is again:

[font:Courier New]

Expanding on Pat's observations, these are my 2 cents which are based on a working script.

MyCriteria:= Concat('=DATABASE((''TestRecord''.''FieldA''=', FL, '))');

SetWSCellFormula(WSH,SN,0,SN,0,MyCriteria);

You do not need 'R IN [''TestRecord'']' because the second argument implies FieldA is in TestRecord.

Make sure you type 2 single quotes '' and not just a double quote " [/font]

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...