1. Martin H Rmz
  2. PowerBuilder
  3. Saturday, 12 May 2018 21:51 PM UTC

Hello Friends, I have a doubt if I am doing this wrong, since I explain to you in I have 5 variables that I want to verify that they are not empty/null and I want to store them in a string and then launch a message with the empty variables that I am concatenating, as you see I am using choose case for each of the variables and I am putting it that it must always be a position within the array, because if I don't put the position always passes the first one and it goes to the next position, my question here is: is it possible to do it with a single line of code this?
or I'm doing it the right way.

Thank you for your recommendations, Greetings

 
String as_Fields[] =  {'AAAA','BBBB', 'CCCCC' , 'DDDDD', 'EEEEE'}
For ll_positionAt=1 to 5
Choose Case True 
Case (Len(Trim(ls_field)) = 0  Or  IsNull(ls_field))  And ll_positionAt= 1
ls_Campo +=  as_Fields[ll_positionAt] + ','
Case (Len(Trim(ls_field1)) = 0  Or IsNull(ls_field1)) And ll_positionAt = 2
ls_Campo +=  as_Fields[ll_positionAt] + ','
Case (Len(Trim(ls_field​2)) = 0  Or IsNull(ls_field2)) And ll_positionAt = 3
ls_Campo +=  as_Fields[ll_positionAt] + ','
Case (Len(Trim(ls_field​3)) = 0  Or IsNull(ls_field3)) And ll_positionAt = 4
ls_Campo +=  as_Fields[ll_posicionAt] + ','
Case (Len(Trim(ls_field​4)) = 0 Or IsNull(ls_field​4)) And ll_positionAt = 5
ls_Campo += as_Fields[ll_positionAt] + ','
End Choose  
Next
 
Michael Kramer Accepted Answer Pending Moderation
  1. Sunday, 13 May 2018 19:27 PM UTC
  2. PowerBuilder
  3. # 1

Hi Martin,

I the the same logic appearing five times. My first action would therefore be to rewrite to remove the duplication.

I expect "small" strings in ls_field, ls_field1, .. ls_field4 => Not too costly to create a temporary copy of these strings in an "input" array to leverage the FOR-loop.

Here is my take on your logic. The comment is to help future code readers understand the logic.


long ll_fieldCount
string ls_input[]
String as_Fields[] =  {'AAAA', 'BBBB', 'CCCCC', 'DDDDD', 'EEEEE'}

ls_input = {ls_field, ls_field1, ls_field2, ls_field3, ls_field4}
ll_fieldCount = UpperBound(ls_input)

for ll_positionAt = 1 to ls_fieldCount
   if ls_input[ll_positionAt] <> '' then
      // Non-empty string => Ignore
   else
      ls_Campo += as__Fields[ll_positionAt] + ','
   end if
next

HTH /Michael

Comment
  1. Michael Kramer
  2. Tuesday, 15 May 2018 19:39 PM UTC
PB compiler told me of 2 typos in my code snippet:





Wrong prefix:  ls_fieldCount => ll_fieldCount (end-value in for loop)

Dual underscore: as__Fields => as_Fields (else statement)





Sorry /Michael

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.