David Poiron Posted August 16, 2021 Share Posted August 16, 2021 I'm really struggling with escaping quotes properly. I want to perform some actions on symbols that have a certain record format field, but I cannot seem to get the criteria to work using ForEachObject. Im using selCriteria:=concat('CPA Products'.'Serial'=,RF1) as the criteria where selCriteria is the selection criteria and RF1 is a string variable for the record format field contents. Because of all the record format quotes, I cannot seem to get it to work no matter how I try to escape them. Any help would be appreciated. Quote Link to comment
Julian Carr Posted August 16, 2021 Share Posted August 16, 2021 Here's an example that might help: Procedure T; VAR s1 : STRING; BEGIN s1 := Concat('(', '''My Plug-in''','.','''My Field Name''','=','''CS''', ')'); AlrtDialog(s1); END; Run(T); Quote Link to comment
Pat Stanford Posted August 16, 2021 Share Posted August 16, 2021 Or my favorite, CHR(39) 😉 CHR(39) puts in ascii character which is the single quote. So my version would look something like: selCriteria:=Concat(CHR(39),'CPA Products',CHR(39)'.',CHR(39),'Serial',CHR(39),'=',RF1); I just use CHR(39) where quotes are actually needed in the final string. To debug, I use AlrtDialog(selCriteria); to see what is actually being produced. double and triple single quotes are great after you get them working correctly, but they are such a pain to try and read and differentiate. CHR(39) is typing a little more, but you then know exactly what you are doing at a glance. 1 Quote Link to comment
Julian Carr Posted August 16, 2021 Share Posted August 16, 2021 I recall years ago someone wrote a script that would create these strings. Can't find it though. Quote Link to comment
Sam Jones Posted August 16, 2021 Share Posted August 16, 2021 Per Pat's suggestion of using chr(39), you can make a "const" declaration of "k39"= chr(39)" which makes is example a tiny bit easier to implement; CONST k39 = chr(39) VAR asdfasdf BEGIN selCriteria:=Concat(k39, 'CPA Products', k39, '.', k39, 'Serial', k39, '=', RF1); END; Suggestion: spaces after commas have no effect but make the function parameters easier to read. Pat is missing a comma after the second CHR(39). That happens to me all the time setting up criteria strings. 1 Quote Link to comment
Pat Stanford Posted August 16, 2021 Share Posted August 16, 2021 Thanks for the extra hint Sam. You could even set the Const to be something like a capital Q so it is not even any extra characters to type. Julian, now that you mention it, that sounds vaguely familiar to me also. A quick search didn't turn up anything in my archives either though. I will keep looking. I want to say that perhaps is was not done in VS, but rather though BBEdit or something else? 1 Quote Link to comment
David Poiron Posted August 16, 2021 Author Share Posted August 16, 2021 (edited) This ended up working with a CONST Q=CHR(39); selCriteria := CONCAT(Q,'CPA Products',Q,'.',Q,'Serial',Q,'=',Q,RF1,Q); Thanks as always! Edited August 16, 2021 by David Poiron 1 Quote Link to comment
Recommended Posts
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.