Results 1 to 15 of 15

Thread: Subs and Functions

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Subs and Functions

    what is the difference between the 2 ? ohter than subs cant return any result While functions do ...
    - regards -
    - razzaj -

  2. #2
    AIS_DK
    Guest
    That's it! I don't belive there are any differences besides that.

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Posts
    198
    >subs cant return any result While functions do ...

    That is the difference.

  4. #4
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    There is no other difference

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Megatron knows the answer

  6. #6
    Matthew Gates
    Guest
    Originally posted by da_silvy
    Megatron knows the answer

    So do I .


    A sub is code that does not need to return anything.
    (Example:

    Private Sub Message(msg)
    Msgbox msg
    End Sub

    Usage

    Message "Hello" )


    And a function returns something.
    (Example:

    Private Function Message(msg As String) As String
    Message = msg
    End Function

    Usage

    Msgbox Message("Hello"))

  7. #7

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    i know that already .but functions dont need to return anything.
    they can , but they dont have too. so question is.

    in terms of Memory Usage , Processing speed etc ...
    - regards -
    - razzaj -

  8. #8
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Originally posted by razzaj
    i know that already .but functions dont need to return anything.
    they can , but they dont have too. so question is.

    in terms of Memory Usage , Processing speed etc ...
    A very good question, indeed. I have often wondered about this myself.
    I am speculating, but I would assume that functions require more resources(just thinking the MS way of things).
    Donald Sy - VB (ab)user

  9. #9
    AIS_DK
    Guest
    Functions ALWAYS returns something!!

    It just a matter of what, if you are changing the value, the function will either return false, "", 0 or nothing, which depends on the function declaration. So it returns something.

    If you call a function, either by Call or just by its name, it will still return something, the return value just won't be stored, and consequensly therefore be destroyed.

    So functions will ofcourse use more resources then subs.

  10. #10
    Megatron
    Guest
    Originally posted by da_silvy
    Megatron knows the answer
    That's right

    Sub's do not return a value, while functions do. If you don't explicitly specify a return value, it will return Empty.

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    The difference between a subroutine and a function is that the
    name of a subroutine is a way for the subroutine to be identified and called.
    For a function, its name doubles as variable declaration
    that may be returned to the calling program.

  12. #12
    a function will always take up more memory than a sub will, when you declare a function you are also declaring a variable, if you don't set the functions return type then it is set as a variant. Either way it declares a variable by the same name as the function therefore taking up more memory, if you do not need a block of code to return something then use a sub. and BTW, subs can return values also, just not the same way functions do
    Matt Bradbury

    An optimist will claim the glass is half full.
    A pessimist that it is half empty.
    I just think the glass is too big.

  13. #13
    AIS_DK
    Guest
    Subs CAN'T return values.

    They can however modify varibles parsed on to them with the byref statement, but so can functions.

    Modidifying a variable parsed on by referece is not the same as returning a value from a function call.

  14. #14

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    since we all agree on this. now is ther a way to call a sub , and not without having VB wait for it finish ( this could be a sub or a function ).
    - regards -
    - razzaj -

  15. #15
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    You either must use api create thread or make an ax exe.

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