Re: Array subscripts with expressions
Posted in 1997
Jacob Salomon wrote: } } Hi folks, } } I need to do some array operations and don't like to create extra } variables to maintain a lot. Here is a record variable; te purpose is } probably obvious but irrelevant to the problem at hand: } } define win_stack record } win_stack_size smallint, # Number of elements in stack } top_win_num smallint, # Pointer to window atop stack } win_name array[200] of char(10) # Array of window names } end record } } Now, later in the code I want to reference the "top" element on the } stack, so I use the top_win_num as the array subscript. Since it is a } member of a record variable, I need to use the complete qualification: } } let win_stack.win_name[win_stack.top_win_num] = cur_win_name } } The compiler objects to this, with the following 2 error messages. } } | } | Subscripts may contain only INTEGER or SMALLINT variables. } | See error number -4346. } |____________________________________^ } | } | A grammatical error has been found on line 122, character 38. } | The construct is not understandable in its context. } | See error number -4373. } } Hmm... Interesting. The -4373 is pointing to the smallint member } variable, which is clearly a smallint. The element itself is a smallint, but the reference is the record.element, which the 4gl context parser is puking on. } } I then tried defining another simple smallint variable and used this } code: } let lc = win_stack.top_win_num # Get copy for syntax problem } let win_stack.win_name[lc] = cur_win_name } } The compiler permits this. That's exactly the suggestion I was going to mention. } } Whatsamattawithya, 4GL? Can't parse an expression in a subscript? } No. } As an experiment, I tried putting a function call inside the subscript, } just to see what the compiler would do. } } let win_stack.win_name[array_cur()] = cur_win_name } | } | The symbol "array_cur" does not represent a defined variable. } | See error number -4369. } |____________________________________^ } | } | A grammatical error has been found on line 126, character 38. } | The construct is not understandable in its context. } | See error number -4373. } } Huh? I am really surprised that 4GL can't seem to handle this. I had a } recollection (real old) that this did once work. } I understand that only the simple numerics work as array elements. } I obviously have a workaround - use that stupid simple variable. } } Any cleaner ways? Does anyone else share that memory or was it wishful } thinking on my part? That local variable is not really that bad of a work-around. Particularly if you use local variables and/or always assign the value just before the call.