<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Development is my life &#187; Programming Field</title>
	<atom:link href="http://www.acidrazor.com/blog/tag/programming-field/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acidrazor.com/blog</link>
	<description>a resource of everything I know about Web Development or related technology including some articles I find interesting</description>
	<lastBuildDate>Tue, 17 Nov 2009 09:55:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>The difference between a Sub and a Function</title>
		<link>http://www.acidrazor.com/blog/the-difference-between-a-sub-and-a-function/</link>
		<comments>http://www.acidrazor.com/blog/the-difference-between-a-sub-and-a-function/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:04:35 +0000</pubDate>
		<dc:creator>AcidRaZor</dc:creator>
				<category><![CDATA[Classic ASP]]></category>
		<category><![CDATA[Programming 101]]></category>
		<category><![CDATA[Correct Syntax]]></category>
		<category><![CDATA[Hobbyists]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Mistake]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Programming Field]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://www.acidrazor.com/blog/?p=23</guid>
		<description><![CDATA[During the last several years in the programming field I have seen Junior&#8217;s (even more seasoned guys) make the simple mistake of using Function&#8217;s for everything. Some even used Sub&#8217;s&#8230; I suspect it&#8217;s because they didn&#8217;t know any better.
True, nowadays with the advent of .NET and PHP languages that instill (or force for that matter) [...]]]></description>
			<content:encoded><![CDATA[<p>During the last several years in the programming field I have seen Junior&#8217;s (even more seasoned guys) make the simple mistake of using Function&#8217;s for everything. Some even used Sub&#8217;s&#8230; I suspect it&#8217;s because they didn&#8217;t know any better.</p>
<p>True, nowadays with the advent of .NET and PHP languages that instill (or force for that matter) you to use the correct syntax for each moment, I feel as hobbyists who won&#8217;t necessarily go to school to learn this, might not be clued up.</p>
<p>Simply stated. a Function returns a value, a Sub does not.</p>
<p>An example of this in Classic ASP:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">Dim</span> myVariable <span style="color: #006600; font-weight: bold;">:</span> myVariable <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;AcidRaZor&quot;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">If</span> checkIfTrue<span style="color: #006600; font-weight:bold;">&#40;</span>myVariable<span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">Then</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;This is indeed true&quot;</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">Function</span> checkIfTrue<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #0000ff; font-weight: bold;">var</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #990099; font-weight: bold;">Dim</span> ret <span style="color: #006600; font-weight: bold;">:</span> ret <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">false</span>
<span style="color: #990099; font-weight: bold;">If</span> <span style="color: #0000ff; font-weight: bold;">var</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;AcidRaZor&quot;</span> <span style="color: #990099; font-weight: bold;">Then</span>
return <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
&nbsp;
checkIfTrue <span style="color: #006600; font-weight: bold;">=</span> ret
&nbsp;
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Function</span></pre></td></tr></table></div>

<p>An example of a Sub would be:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">Dim</span> myVariable <span style="color: #006600; font-weight: bold;">:</span> myVariable <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;AcidRaZor&quot;</span>
&nbsp;
saveThisName myVariable
&nbsp;
<span style="color: #0000ff; font-weight: bold;">Sub</span> saveThisName<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #0000ff; font-weight: bold;">var</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #990099; font-weight: bold;">Session</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;nameSaved&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">var</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Sub</span></pre></td></tr></table></div>

<p>This spills over (and hopefully answers some of your questions) into the new versions of .NET and beyond. Returning variables from Function&#8217;s or just processing data with Sub&#8217;s. Soon the student will become the teacher <img src='http://www.acidrazor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidrazor.com/blog/the-difference-between-a-sub-and-a-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
