A DIM inside a if/endif structure is only used inside that structure. You will likely need to use GLOBAL instead of DIM.