Results 1 to 6 of 6

Thread: Call Statements

  1. #1

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Call Statements

    I'm working on a text-based game for my Computer Science class, and I've been having difficulty getting the concept of call statements. Can someone please explain them and how they work, or post a link that would do the same? Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Mar 2007
    Location
    New Jersey
    Posts
    30

    Re: Call Statements

    a call statement allows you to "call" a function. Example:
    vb Code:
    1. public sub TestSub()
    2.     msgbox("You just called me!")
    3. end sub
    4.  
    5. public sub Main()
    6.    call testsub
    7. end sub
    Also if you want to call a function you can leave out the word call and just have "testsub". If the sub/function has parameters then you would put them within parentheses after the name of the sub/function. Hope that helps.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Call Statements

    Quote Originally Posted by BinaryCode
    Also if you want to call a function
    You call a sub, not a function.
    you can leave out the word call and just have "testsub". If the sub/function has parameters then you would put them within parentheses after the name of the sub/function.
    If you use Call. If not you don't use the parentheses.
    Code:
    Call Sub(parameters)
    but
    Sub parameters
    
    Sub(parameters) will throw an error.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Call Statements

    In full, using call is best for functions that don't return values. Either a Function or a Sub..

    If you use it with a function with a return value, it won't cause an error, but the return value won't matter, it will be discarded.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    Junior Member
    Join Date
    Mar 2007
    Location
    New Jersey
    Posts
    30

    Re: Call Statements

    ya, basically Call allows you to enter the code within a sub or function. With a function you can return a value and a sub cannot. Here is an example of what chem was talking about:
    vb Code:
    1. public function Test() as boolean
    2.     'this function will return true to the call
    3.     test = true
    4. end function
    5.  
    6. public sub Main()
    7. dim temp as boolean
    8.  
    9.     'this will just call the function, but the returned value will not do anything
    10.     call test
    11.  
    12.     'this will call the function and then put the value of the return into the variable
    13.     temp = test
    14. end sub

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Call Statements

    A function that doesn't return a value is a sub with a few wasted instructions. there's no reason to prepare the stack to receive a null value that's going to be discarded. There's also no reason to call (which is deprecated) a sub, since it does about the same thing - prepares the stack to receive a value it never receives.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width