Have you defined these variables (BG0, BG1, etc.)? Because if not, DIM those arrays, since they're treated as doubles.