Ques on usage of ?

Team,
Here is my problem; Consider the below assign statement

xyz = "some string " + <<input value from a field from UI>> + " some string".

Scenario 1: If <<input value>> is "Test" then the value of xyz would be "somestring Test somestring"
Scenario 2: If <<input value>> is ? then the value of xyz change to ? (my requirement - the ans should be "somestring ? somestring")

Hope i don't confuse anyone. Not sure if it a simple question, currently i have a solution for the above problem by solving it using "QUOTER" function. Like to know if this can be solved by any other means.

Thanks in advance..!
 

LarryD

Active Member
My simplistic solution was not deemed 'best practices', so removed and you should see next post (Tom B's nice solution).
 

tamhas

ProgressTalk.com Sponsor
Note that, in addition to Tom's approach working with ? when concatenation doesn't, it is also considered best practice since you end up with a single string for the whole statement, which can be more easily translated. You may not need to translate today, but you never know about tomorrow.
 

D.Cook

Member
I never thought of that method Tom, nice one.

In the past I've just wrapped the potentially undefined string in a basic user defined function like this:

Code:
function str returns char (vp_input as char):
   if vp_input eq ? then
      return "?".
   else
      return vp_input.
end.

somevar = "text" + str(inputValue) + "text".
 

andre42

Member
I also like Tom's method - I wasn't aware that substitute converts ? to "?". Very readable.
My usual approach is

Code:
xyz = "string1 " + (if inputValue = ? then "?" else inputValue) + " string2".
which is okay as long as inputValue is not a long expression. Might be a bit faster than substitute, though.
 

tamhas

ProgressTalk.com Sponsor
Whether something else works, substitute is best practice. It is clear and readable as to what is happening in the code, well-behaved around ? and other potential problems, makes a clearer relationship between the code and what is on the screen, and sets you up for translation should that ever be necessary. Why fight it?

Note, for example, that all of the work arounds assume one is dealing with a string ... are you going to remember to do it when the variable part of the expression is string(somenumber)?
 
Ya that's true... I met with a problem while using QUOTER function as well.. but got it resolved after using SUBSTITUTE function. I feel that usage of SUBSTITUTE function is the best practice. Thanks team..!
 
Top