Computer Science Canada Procedure Problems |
Author: | ProgrammingFun [ Fri Jan 15, 2010 8:05 pm ] | ||
Post subject: | Procedure Problems | ||
What is it you are trying to achieve? I am trying to call a procedure which uses another procedure which is declared later on. What is the problem you are having? I am making a program which has a lot of buttons. Sometimes, one of my buttons on a certain page calls to a procedure which is declared after the current procedure which I am using. Is there any way to get around this problem without having to create duplicates of all existing procedures? What have you tried to solve this problem? I have tried importing the procedures but this produces the same error. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1.1 |
Author: | TerranceN [ Fri Jan 15, 2010 8:33 pm ] | ||
Post subject: | RE:Procedure Problems | ||
Yes you can! You can use the forward and body keywords, here is an example using similar code to yours:
Hope that helps. |
Author: | ProgrammingFun [ Fri Jan 15, 2010 8:37 pm ] | ||||
Post subject: | Re: RE:Procedure Problems | ||||
TerranceN @ Fri Jan 15, 2010 8:33 pm wrote: Yes you can! You can use the forward and body keywords, here is an example using similar code to yours:
Hope that helps. Thank you so much! So I would declare
|
Author: | TerranceN [ Fri Jan 15, 2010 8:45 pm ] | ||||||||
Post subject: | RE:Procedure Problems | ||||||||
No, the important part is not the brackets (they are optional on procedures, but I use them because they are mandatory in other languages so I am used to it). The important part is forward and body You declare a 'prototype' of the function (or procedure, but when I say function I mean both) with the forward keyword. A prototype just tells turing that a function like this exists, and how you are supposed to call it. For example:
You tell turing what the function does by using the body keyword. This can be anywhere in the same file.
Therefore you can call it before you tell turing what it does.
I hope that makes it more clear. EDIT: Also note that if you use a function with prameters, you have to include them in both the forward and body ex
|
Author: | ProgrammingFun [ Fri Jan 15, 2010 8:51 pm ] |
Post subject: | Re: Procedure Problems |
Yes, this made things a lot easier for me. Just one more question (for now ![]() will this also work in .TU files and when they are imported and if so, will this change the way in which I export procedures from a .TU file? Thank you very much. |
Author: | TerranceN [ Fri Jan 15, 2010 9:30 pm ] | ||
Post subject: | RE:Procedure Problems | ||
If it works in a module, it shouldn't matter what file it is in (unless there in an importing error). I tried this in a module and it worked. I don't know about classes but I'm pretty sure it is the same. So no, there is no difference when you export.
Hope this helps. |
Author: | ProgrammingFun [ Sat Jan 16, 2010 9:07 am ] |
Post subject: | RE:Procedure Problems |
Yes, I tried it and it works. Thank you for your help. |