Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

VBScript Sub vs. Function

I know the basic advantage of a function is that you can return a value from a function by setting the value of a function within its code. That makes a function basically the same as a Sub with this added feature.

What does a Sub offer over a Function, speed? Is there any reason not to use funtions exclusively and just forget Subs altogether? This might make it somewhat easier for those that work both in VBScript and JavaScript.
0
newsomer
Asked:
newsomer
  • 6
  • 3
1 Solution
 
fritz_the_blankCommented:
My understanding is that it is just convention. I have taken what is essentiall a sub but called it a function and it works fine.

Fritz the Blank
0
 
newsomerAuthor Commented:
I have the same experience. Thank you for your comment but I am looking for a more definitive answer.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
newsomerAuthor Commented:
Found the following in your first link (I couldn't reach it throught our firewall but got it through my anonymizer account):

  . . . when should you use subs or functions?
  basically, since Subs aren't expected to return
  anything they run a miniscule amount quicker
  than the same code defined as a function. You
  won't notice it, in fact benchmarking programs
  wouldn't register much, but a good programmer
  saves processor cycles wherever he can, so if
  you don't want a return value, always use a Sub.

I am not so sure I agree with the comment about using Subs instead of Functions. Saving processing cycles while using such a blunt tool as VBScript is like emptying your ashtray in your Hummer to save gas.

Thank you for your efforts.
0
 
fritz_the_blankCommented:
Glad to have helped.

Any reason for the grade of B? We could have gone on like this for awhile longer if necessary...


Fritz the Blank
0
 
newsomerAuthor Commented:
Hmmm, I see by your profile you are used to getting all A's. Tell me where I can go to change this.

I did think about it and did have reasons but don't know if you are interested in the details and I am not interested in making it an issue.
0
 
fritz_the_blankCommented:
It is up to you. We don't get paid here, but rather, volunteer our time free of charge to help others out. If you don't feel that the answer that you received here answered your question fully, then that's fine. We can't really do anything with these points anyway--they have more do to with prestige and as a sign of appreciation from those we helped. I would be curious, however, as to what you think I could have added here to make you happier.

Fritz the Blank
0
 
Computer101Commented:
Grade changed as requested

Computer101
E-E Admin
0
 
fritz_the_blankCommented:
Thanks to all,

Fritz the Blank
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now