Resolved Using Scope Defined With Condition

JoseKreif

Member
Can scoped variables ever change at run time? Something isn't quite right right this.




Code:
do v-cnt = 1 to 3: /** master loop **/
     
   case v-cnt:
      when 1 then  &scoped-define STRM s-1.
      when 2 then  &scoped-define STRM s-2.
      when 3 then  &scoped-define STRM s-3.
    end.
     
    import stream {&STRM} unformatted v-data
    v-data = v-data + chr(12).
    put stream {&STRM} unformatted v-data skip.
   
  end. /** master loop **/
 

GregTomkins

Active Member
That looks bizarre to me. I think what will happen is, when you compile, the value of STRM will be set to the final assignment of s-3, and that's the only thing that will make it to the compiler on lines 9 and 11.

I didn't actually know you can specify multiple values for the same preprocessor define (I try to avoid preprocessor stuff as much as possible and generally view it as a code stench). But I guess this could be useful if you wanted to use different values at different points in the file. But in your case, the compiler will know nothing about v-cnt having 3 different possible values.
 

JoseKreif

Member
That looks bizarre to me. I think what will happen is, when you compile, the value of STRM will be set to the final assignment of s-3, and that's the only thing that will make it to the compiler on lines 9 and 11.

I didn't actually know you can specify multiple values for the same preprocessor define (I try to avoid preprocessor stuff as much as possible and generally view it as a code stench). But I guess this could be useful if you wanted to use different values at different points in the file. But in your case, the compiler will know nothing about v-cnt having 3 different possible values.

I forget that the value is precompiled. So changing at runtime shouldn't be possible.
Thanks
 

Stefan

Well-Known Member
If you are trying to use multiple variable streams, look into the STREAM-HANDLE option on the IMPORT statement.
 
Top