Discussion:
Duplicated procedures
(too old to reply)
evilaro
2008-11-12 12:49:51 UTC
Permalink
To All:

I just made a mistake, that took me several hours to
find.

I had 2 procedures with the same name on a form
and both had slight differences... which made me go
crazy, because I was looking at the good one,
but the one been activated was the other...


So....

Is there a routine to try to find duplicated names of
functions and procedures???


And..

On the same line...
It looks like to me that a procedure or a function work the
same way... Is there a difference?.

If not .. in order to make it standard , which one I should use
procedure or function.

Thanks

Emilio
Marilyn Price
2008-11-12 13:21:35 UTC
Permalink
Post by evilaro
I just made a mistake, that took me several hours to
find.
I had 2 procedures with the same name on a form
and both had slight differences... which made me go
crazy, because I was looking at the good one,
but the one been activated was the other...
So....
Is there a routine to try to find duplicated names of
functions and procedures???
Well, if you're using the Source Editor to look at the code, then they
will probably be listed together in the treeview on the left side of the
screen.....
Post by evilaro
And..
On the same line...
It looks like to me that a procedure or a function work the
same way... Is there a difference?.
If not .. in order to make it standard , which one I should use
procedure or function.
Back in the Stone Ages <g>, the difference between a function and a
procedure was that a function _must_ return a value, while a procedure
couldn't. And the only way you could call a function was to provide a
landing place for whatever it returned, like:

x = int(y) // int() is a function that returns a value

These days, the line between the two has blurred to the point it's
invisible. However, a procedure still can't directly return a value,
while a function _may_ return a value and, depending on how it is
called, may still be required to return a value.

Personally, I find it easier to just make everything a function. That
way, if I need to return a value, I can (and provide a landing place for
the returned value). However, I can also just return and call it
without a DO...

Also, the word function is shorter than procedure (by one letter <g>),
so it's a little less typing....
--
Marilyn Price
M. P. Data
evilaro
2008-11-12 21:27:19 UTC
Permalink
Post by Marilyn Price
Well, if you're using the Source Editor to look at the code, then they
will probably be listed together in the treeview on the left side of the
screen.....
True... and it is not a bad idea to check now and them...
but relies on my eyes... and some equal funtions can scape from my
discerning ;)
Post by Marilyn Price
Back in the Stone Ages <g>, the difference between a function and a
procedure was that a function _must_ return a value, while a procedure
couldn't. And the only way you could call a function was to provide a
x = int(y) // int() is a function that returns a value
These days, the line between the two has blurred to the point it's
invisible. However, a procedure still can't directly return a value,
while a function _may_ return a value and, depending on how it is
called, may still be required to return a value.
Personally, I find it easier to just make everything a function. That
way, if I need to return a value, I can (and provide a landing place for
the returned value). However, I can also just return and call it
without a DO...
Marilyn...

Thanks for all this information..

Emilio
Marilyn Price
2008-11-13 12:42:03 UTC
Permalink
Post by evilaro
Post by Marilyn Price
Well, if you're using the Source Editor to look at the code, then they
will probably be listed together in the treeview on the left side of the
screen.....
True... and it is not a bad idea to check now and them...
but relies on my eyes... and some equal funtions can scape from my
discerning ;)
True <sigh>.

I guess we need it to jump up and smack us in the face occasionally...
Post by evilaro
Thanks for all this information..
You're welcome!
--
Marilyn Price
M. P. Data
Bruce R. Roland
2008-11-13 00:12:56 UTC
Permalink
evilaro

One thing I did forget to mention or point out in my last post on this subject is that using a MSGBOX() to trap code errors will only work in function and method code. You cannot use it within object/class definition/instantiation (excuse my grammer here I have a hard tim getting that word right) code

Bruce.
Bruce R. Roland
2008-11-13 00:05:28 UTC
Permalink
evilaro

One method I use very often when writing code - especially with respect to mem variables - to locate mem variables I may have declared at one point and then discontinued the use of later is the search and replace - Ctrl-R.

With Ctrl-R I can enter the name of a mem variable - or an object, code command or any other text - and quickly go through the entire code to find all occurences of the entered search string.

In your case I would say that getting in the routine of checking code for duplicates or the use of certain code using search and replace (CTRL-R ) (you don't actually have to replace you can simply search) may be of help in finding such a duplication.

The other problem is of course knowing that there is a duplication in the first place. I often use MSGBOX() to set a trap in my code when I am having a problem to tell me when and if a certain point in the code is reached or what a value might be at a particular point. I simply insert a MSGBOX() at a strategic place in my code which tells me that a certain point in the code has been reached and if needed what the value of something is at that point in the code. By methodicaly placing the MSGBOX() and moving it through the code I can often get a better idea of what is happening when and if what I expect to hapen is happening. Very often I can find my errors a lot quicker by using MSGBOX() to stop my code and tell me where it is at and what is happening at that point in the code.

In your case it sounds like this method of using a MSGBOX would have greatly helped in that had you set a MSGBOX() to trip in the function you knew about, when tyhe MSGBOX did not trip it would have told you immeadiately that your code was never reaching that function. Thus you would have known to look elsewhere for the problem rather than chasing you tail.

Try using the MSGBOX as a trap for analyzing code behaviorand code results. I think you will fiond this a very helpful way of locating problems and bugs with your code.

Hope this helps.

Bruce
Marilyn Price
2008-11-13 12:44:30 UTC
Permalink
Post by Bruce R. Roland
In your case I would say that getting in the routine of checking code
for duplicates or the use of certain code using search and replace
(CTRL-R ) (you don't actually have to replace you can simply search)
may be of help in finding such a duplication.
Or just search using Ctrl-F
--
Marilyn Price
M. P. Data
Bruce R. Roland
2008-11-14 05:15:06 UTC
Permalink
Post by Marilyn Price
Post by Bruce R. Roland
In your case I would say that getting in the routine of checking code
for duplicates or the use of certain code using search and replace
(CTRL-R ) (you don't actually have to replace you can simply search)
may be of help in finding such a duplication.
Or just search using Ctrl-F
--
Marilyn Price
M. P. Data
Marilyn

Thanks for the feedback on Ctrl-F. I hadn't been aware of that but now that you pointed out the find with out the replace it will be something I will use often.

Thanks

Bruce
Marilyn Price
2008-11-14 12:51:41 UTC
Permalink
Post by Bruce R. Roland
Thanks for the feedback on Ctrl-F. I hadn't been aware of that but
now that you pointed out the find with out the replace it will
be something I will use often.
Thanks
You're welcome! Personally, I have a tendency to forget that Ctrl-R
exists and mumble to myself every time I really wanted to do a search
and replace and not just a search <g>.
--
Marilyn Price
M. P. Data
Bruce R. Roland
2008-11-13 12:37:51 UTC
Permalink
Your commets are highly appreciated...
I also use the MSGBOX to trap where the program is moving ;)
msgbox('Has entered the routine')
MSgbox('should arrive here')
msgbox('This function is no longer used')
Etc....
But in this case the problem was that I did not even think
that there was another function with the same name.
Regards
Emilio
Emilio

The biggest problem I think we all have as programmers is in assuming what our code is doing and not taking the time to ensure it is doing what we think it is. Your use of the MSGBOX() as a trap is a good routine to get into to ascertain what is actually happening.

But if you are like me sometimes I am just too dense to comprehend what those MSGBOX() traps are telling me for a while. Sometimes I just have to sit back and think about what the code is supposed to do and what the MSGBOX() traps are telling me is happenening for a while before it sinks in. After all, codeing is 90% thinking and only 10% actual codeing.

Often when I set a trap to see where the code is going and find out it is not going where I think it is or doing what I think it is, the only way to find out what it is doing is by using the search and replace (ctrl-R) to look for a key code that I am thinking the code is executing or wanting the code to go to - to see where the code is located in the code which then shows me duplicates or other areas where the code could be going that I did not expect. I can then set additional MSGBOX() traps to confirm that is or is not where the code is going and thereby focus in on the problem.

I would suggest to all progremmers to get in the routins of using the search and replace (Ctrl-R) to specifically look for duplicate functions and to look for mem variable or blocks of code which may have been used in the development stages of the code but later changed - or which the use of was discontinued - every time code is written or modified. This can help avoid run problems and help find code which is no longer in use in the code and give you the opportunity to clean it out.

While such a routine is time consuming - don't underestimate the value of doing so either.

Bruce
evilaro
2008-11-13 10:14:14 UTC
Permalink
Bruce:


Your commets are highly appreciated...

I also use the MSGBOX to trap where the program is moving ;)

msgbox('Has entered the routine')
MSgbox('should arrive here')
msgbox('This function is no longer used')

Etc....

But in this case the problem was that I did not even think
that there was another function with the same name.

Regards

Emilio
Post by Bruce R. Roland
evilaro
One method I use very often when writing code - especially with respect to
mem variables - to locate mem variables I may have declared at one point
and then discontinued the use of later is the search and replace - Ctrl-R.
With Ctrl-R I can enter the name of a mem variable - or an object, code
command or any other text - and quickly go through the entire code to find
all occurences of the entered search string.
In your case I would say that getting in the routine of checking code for
duplicates or the use of certain code using search and replace (CTRL-R )
(you don't actually have to replace you can simply search) may be of help
in finding such a duplication.
The other problem is of course knowing that there is a duplication in the
first place. I often use MSGBOX() to set a trap in my code when I am
having a problem to tell me when and if a certain point in the code is
reached or what a value might be at a particular point. I simply insert a
MSGBOX() at a strategic place in my code which tells me that a certain
point in the code has been reached and if needed what the value of
something is at that point in the code. By methodicaly placing the
MSGBOX() and moving it through the code I can often get a better idea of
what is happening when and if what I expect to hapen is happening. Very
often I can find my errors a lot quicker by using MSGBOX() to stop my code
and tell me where it is at and what is happening at that point in the
code.
In your case it sounds like this method of using a MSGBOX would have
greatly helped in that had you set a MSGBOX() to trip in the function you
knew about, when tyhe MSGBOX did not trip it would have told you
immeadiately that your code was never reaching that function. Thus you
would have known to look elsewhere for the problem rather than chasing you
tail.
Try using the MSGBOX as a trap for analyzing code behaviorand code
results. I think you will fiond this a very helpful way of locating
problems and bugs with your code.
Hope this helps.
Bruce
Loading...