Author |
Message |
mike200015
|
Posted: Sun Feb 27, 2005 11:39 am Post subject: Procedure |
|
|
in a program im making, i have 2 procedures that have code which are very similar, except for about 10 lines, in a few different spots, so is there a way to make a procedure for the stuff that are similar, and then i can just add in the lines that are different? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 27, 2005 11:44 am Post subject: (No subject) |
|
|
Pass parameters into your procedure.
If the lines that are different are just different because they use different variables, you can pass the variable into the procedure.
If the lines that are different really are different, you can wrap them inside an if statement and use a boolean parameter to determine whether to go inside that if statement or not. |
|
|
|
|
![](images/spacer.gif) |
mike200015
|
Posted: Sun Feb 27, 2005 11:52 am Post subject: (No subject) |
|
|
yea the lines are like totally different .. not just like a different colour or sumtin.. but its not like 1 big chunk in the middle thats different, i have like 5 lines in 1 spot.. and like 3 lines in another etc. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 27, 2005 12:05 pm Post subject: (No subject) |
|
|
Then it's up to you to decide whether you should wrap those lines in if statements (using a boolean parameter) or make a whole new procedure. Personally, I wouldn't decide on number of lines of each method, I would make my decision based on what I'm trying to do with either procedure. If the purpose is the same or very similar, I'd go with the boolean method.
Also, look for ways that you can clump those different lines together, so as to use less if statements. |
|
|
|
|
![](images/spacer.gif) |
mike200015
|
Posted: Sun Feb 27, 2005 12:09 pm Post subject: (No subject) |
|
|
kk... thnx for ur help ![Exclamation Exclamation](images/smiles/icon_exclaim.gif) |
|
|
|
|
![](images/spacer.gif) |
person
|
Posted: Sun Feb 27, 2005 6:05 pm Post subject: (No subject) |
|
|
im not so sure that this is gonna help u but cant u just make wats same a procedure? |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Sun Feb 27, 2005 6:18 pm Post subject: (No subject) |
|
|
not necessarily, because if what's different is inside a for loop for example, and he's usin' the for loops for his array's, then he cant put everything else in a proc. |
|
|
|
|
![](images/spacer.gif) |
ssr
![](http://siruisite.port5.com/ssr.jpg)
|
Posted: Sun Feb 27, 2005 7:08 pm Post subject: (No subject) |
|
|
I donno
may be u can make numerous procs depending on the different codes
and make a large proc which include ifs, and put down teh small procs
8)
may be
just may be.... |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|