Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

procedure executes without being called 1

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
Disclaimer: My FoxPro 2.5 skills are weak at best, it's been over 2 years since I last worked with this language. And the last time was the first time I ever programmed in FoxPro. I'm a c# dev most of the time. on to the problem...

I have a de-normalized table. where there are a series of columns for each day of the week. example:
[tt]amo | bmo | cmo | atu | btu | ctu | awe | bwe | cwe | ...[/tt]

there are always the same number of columns per day so I decided to create a set of procedures which loads an array for each day of the week.

my first procedure is monday
Code:
PROCEDURE get_columns_for_monday
   PARAMETER the_id, the_array

   select amo, bmo, cmo;
   from table;
   where id = the_id;
   INTO ARRAY the_array;

example of calling the code
Code:
DIMENSION days[1]
DO get_columns_for_monday WITH 1, days
this returns the correct values

add a procedure for tuesday
Code:
PROCEDURE get_columns_for_tuesday
   PARAMETER the_id, the_array

   select atu, btu, ctu;
   from table;
   where id = the_id;
   INTO ARRAY the_array;
calling [tt]get_columns_for_monday[/tt] I get values for [tt]get_columns_for_tuesday[/tt]

here is the complete code example
Code:
SET DEFAULT TO [directory]
CLEAR

id = 1
DIMENSION mondays[1]
DO get_columns_for_monday WITH id, mondays

&& this incorrectly returns 4,5,6. the correct result is 1,2,3

int i = 1
DO WHILE i <= ALEN(mondays)
   @i,1 SAY mondays[i]
   i = i + 1
ENDDO

&& should return 1, 2, 3
PROCEDURE get_columns_for_monday
   PARAMETER the_id, the_array

   select amo, bmo, cmo;
   from table;
   where id = the_id;
   INTO ARRAY the_array;

&& should return 4, 5, 6
PROCEDURE get_columns_for_tuesday
   PARAMETER the_id, the_array

   select atu, btu, ctu;
   from table;
   where id = the_id;
   INTO ARRAY the_array;
What I can't explain is that when I either remove or comment out [tt]get_columns_for_tuesday[/tt], or switch the positions of [tt]get_columns_for_tuesday[/tt] and [tt]get_columns_for_monday[/tt] the results are correct.
Any ideas on how to avoid this behavior, and/or what I'm doing wrong.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I have a vague memory that in FoxPro 2.x, there was a limit on the length of a procedure name and anything after that length was ignored. That would account for what you're seeing.

However, you're really doing this the hard way. Even if you don't want to normalize the data (which is, of course, the best long-term solution), you can write a single procedure that accepts the day abbrev as a parameter and fills the specified array with the data for that day. Try something like this:

Code:
PROCEDURE get_day_columns
   PARAMETER cDay, the_id, the_array

   PRIVATE cField1, cField2, cField3

   cField1 = "a" = m.cDay
   cField2 = "b" + m.cDay
   cField3 = "c" + m.cDay

   select &cField1, &cField2, &cField3 ;
   from table;
   where id = the_id;
   INTO ARRAY the_array

RETURN

I also hope your table isn't really called "table"

Tamar
 
can't change the db. links to too many "other" things. believe me it's on my list to upgrade the whole program, unfortunately it's not my call:)

no it's not called table. the tables/fields are very cryptic and figured simple examples would be easier to follow.

didn't know about the dynamic field names, this will make it much easier to query. thank you

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
works perfectly!

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top