Big Oops!
jjames
Posts: 2,908
I just thought I'd share with everyone a mistake I made that sent me on a goose chase on trying to find the culprit. In my DEFINE_PROGRAM section, I had a function being called that returned a value. Here's a snippet:
After about 10 minutes looking at it, it finally clicked! So to fix the problem I created a STACK_VAR in the begining of the function and used that for the FOR loop. A stupid mistake on my part, but I just thought I'd share my embarassing moment in programming in hopes that others will at least learn from my mistake. Talk about a BIG OOPS!
FOR (nLOOP=1;nLOOP<=LENGTH_ARRAY(dv_TP);nLOOP++) { // Camera select feedback FOR(nLOOP1 = 1;nLOOP1<=LENGTH_ARRAY(nCAMERA_BTNS);nLOOP1++) [dv_TP[nLOOP],nCAMERA_BTNS[nLOOP1]] = (nCAM_SEL[nLOOP][fnGET_ROOM(nLOOP)] = nLOOP1) }Well, the panels can control multiple rooms so I need to know which room it was in. I could have used a simple room select variable, to keep track, but I was trying something new. Anyway... here's the function code:
DEFINE_FUNCTION INTEGER fnGET_ROOM (* Get which room is being controlled */ (INTEGER nPANEL) { FOR(nLOOP = 1; nLOOP <= 5; nLOOP++) { IF(nPNL_AV[nPANEL] == nAV_ZONE_MAP[nPANEL][nLOOP]) { RETURN nLOOP; BREAK; } } }Can anyone spot the culprit right away? It took me a little bit to actually find it. I'm passing a variable into the function (nLOOP), and the variabled used for the FOR loop is ... nLOOP. I didn't even think about the variable getting used in multiple places at the "same" time. Well, here's the thing: it didn't cause any runtime errors, or anything like that. I was stuck! I couldn't even "pause" the program in debug. I figured it had to be something in the DEFINE_PROGRAM, so I started commenting things out and looking to see what could have messed up my program.
After about 10 minutes looking at it, it finally clicked! So to fix the problem I created a STACK_VAR in the begining of the function and used that for the FOR loop. A stupid mistake on my part, but I just thought I'd share my embarassing moment in programming in hopes that others will at least learn from my mistake. Talk about a BIG OOPS!
0
Comments
My local variables all have "My" in their name and function call arguments all have "Arg" in their name. Globals have neither.