I am doing this wrong in For choose case


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  

Question Tags: 


Michael Kramer answered I am doing this wrong in For choose case


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
      ls_Campo += as__Fields[ll_positionAt] + ','
   end if

HTH /Michael

Michael Kramer's picture

PB compiler told me of 2 typos in my code snippet:

  1. Wrong prefix:  ls_fieldCount => ll_fieldCount (end-value in for loop)
  2. Dual underscore: as__Fields => as_Fields (else statement)

Sorry /Michael