Thread: Sub-procedure

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    Sub-procedure

    How would you save a piece of code in one file in the same project and then execute it in another file?

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    it would help me a lot if I knew how because it would simplify a program that I want to write.

  3. #3
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    A bit vague but maybe you could use header files???

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Well i can foresee that the program would have a lot of if statements so how could i make it to do i such and such then do the sub procedure thingy.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    how could i make it to do i such and such
    Well, the i such and such thingy has been the subject of much research lately by some of the sharpest minds in programming, and no one has been able to crack its hidden mysteries yet.

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    If you want your program to start-up and run another program - FAQ: Run a program from within a program.

    If you want to break-up your program into more than one source file - FAQ: Multiple source files for one program

    EDIT -
    Or, maybe you just need a regular ol' function(). Everything in C/C++ is done in functions...

    Conceptually, a function is much like a sub-routine. When it is finished, the program returns to the line (or statement) following the function-call, and you can execute it as many times as you want, from multiple places throughout the program.

    So, typically instead of putting 25 lines of code in brackets following your if-statement, you would call a function that has all of that code in it. When the function ends, program-flow returns back to the main (or calling) function where it left-off. (And, that function can call another function, etc., etc., etc.)

    Read through the tutorials before you start trying this. A function can only return one variable. You have to use references or pointers if you want your function to affect more than one variable.
    Last edited by DougDbug; 11-08-2005 at 08:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hooked Procedure Early Return In/External Trigger
    By n00b3 in forum Windows Programming
    Replies: 4
    Last Post: 06-29-2008, 05:37 PM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. Replies: 0
    Last Post: 04-21-2006, 01:41 PM
  4. Window Procedure Question
    By shinobisot in forum Windows Programming
    Replies: 3
    Last Post: 01-15-2003, 11:38 AM
  5. Collision with quads?
    By SyntaxBubble in forum Game Programming
    Replies: 6
    Last Post: 01-18-2002, 06:17 PM