?
Solved

VBScript Sub vs. Function

Posted on 2003-03-18
10
Medium Priority
?
610 Views
Last Modified: 2010-05-18
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
Comment
Question by:newsomer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8160056
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
 

Author Comment

by:newsomer
ID: 8160989
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!

 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 300 total points
ID: 8161322
0
 

Author Comment

by:newsomer
ID: 8161941
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8161961
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
 

Author Comment

by:newsomer
ID: 8163244
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8163277
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
 
LVL 1

Expert Comment

by:Computer101
ID: 8164009
Grade changed as requested

Computer101
E-E Admin
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8166557
Thanks to all,

Fritz the Blank
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question