<?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>CalvinDude.com &#187; Science</title>
	<atom:link href="http://calvindude.com/dude/category/science/feed/" rel="self" type="application/rss+xml" />
	<link>http://calvindude.com/dude</link>
	<description>The Theological and Philosophical Musings of CalvinDude</description>
	<lastBuildDate>Mon, 30 Jan 2012 18:56:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Islands and Clouds</title>
		<link>http://calvindude.com/dude/2011/12/14/islands-and-clouds/</link>
		<comments>http://calvindude.com/dude/2011/12/14/islands-and-clouds/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 17:13:15 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=2097</guid>
		<description><![CDATA[Recently, a local radio DJ played Breaking Benjamin’s song Blow Me Away. One of the phrases in the song is, “Only the strongest will survive.” The song was originally written for the game Halo 2, so that lyric is somewhat fitting. However, I got to thinking about that lyric a bit, and me being me [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, a local radio DJ played Breaking Benjamin’s song <i>Blow Me Away</i>.  One of the phrases in the song is, “Only the strongest will survive.”  The song was originally written for the game Halo 2, so that lyric is somewhat fitting.</p>
<p>However, I got to thinking about that lyric a bit, and me being me I also merged those thoughts with a couple of other thoughts I’ve had.  See, I enjoy foreign languages even though I would never claim to be fluent in anything other than English (and sometimes, not even that!).  Most recently I’ve been brushing up on my Latin and Koine Greek.  One of the things that finally “clicked” in my head about languages is how you need to think conceptually instead of trying to map phrases one-to-one.  That’s not to say I didn’t know that already, but rather that it finally fully set in my mind that meaning transcends individual words.</p>
<p>In fact, when I recently read through <i>Gödel, Escher, Bach</i> by Douglas Hofstadter, he made a comment about how originally people thought we could make great progress toward mechanical interpretations of texts using computers.  Then, as we tried to do that and failed spectacularly, it became obvious that interpretation is more than just a substitution of words.</p>
<p>Just for fun, and to demonstrate my point, I ran the above paragraph through Google’s translate feature, translating it from English to Latin and then back to English again and it gave me this:</p>
<p>For when he recently read through <i>Gödel, Escher, Bach</i> by Douglas Hofstadter made to the mechanical devices of the people who first how we could make great progress of computers and using the interpretation of the texts. Then, as he could and the efforts of is to do spectacularly, so be it is a clear correlation of interpretation of speeches.</p>
<p>Not only is that mostly gibberish on par with the emails I get from those generous Nigerian princes, but if I try to piece together the meaning from the words presented it seems to me that it actually reverses my original meaning in the last sentence!</p>
<p>Now, some people are very strict with how they define and interpret words.  Word X means concepts A, B, <i>or</i> C, period.  If I were to make an analogy, I’d imagine these people as viewing the meaning of words similar to islands in the ocean.  There is the water of chaos that swirls around, but when you get to the word itself, the definition stands strong and immobile.  It is fixed, no matter what the ocean does.</p>
<p>However, I have become more and more convinced, over time, that words are more like clouds in the sky.  That is, they are still distinct units, but their edges are a bit fuzzier and a little malleable.  Note that I do not maintain that postmodern concepts of deconstructionism are sound, or that words have no actual meaning at all—anymore than I would say that a cloud has no shape or that a cloud could also be a fox.  Rather, it’s just that the definitions of words are “fuzzy” at times, as opposed to fixed islands of meaning.</p>
<p>Thus, I realize more and more that translation is at the <i>conceptual</i> level rather than the <i>word</i> level.  Some of the most difficult aspects of learning a foreign language is beginning to <i>think</i> like the native speaker.  Take just the simple example of word order.  In English, word order is critical; but in Latin, it is not important at all.  However, Latin does still have some preference for word order, such as having the verb come at the end of the sentence (English is typically subject-verb-object; Latin tends to subject-object-verb).  </p>
<p>To give an example of that in English, examine: “Susan goes to the bank.”  Here, “Susan” is the subject, “goes” is the verb, and “the bank” is the object (here, a prepositional phrase).  Latin word order would typically render it as “Susan, to the bank, goes.”  That makes sense in English, but it is awkward.  If every sentence was written that way, it would make English difficult to comprehend.</p>
<p>Since the structure of sentences helps to convey the meaning of the sentences in some languages (such as English), and falls into patterns of use in other languages, you can actually look at the structure of languages to see what information cultures think are most relevant.  In English, we want to know first who or what is doing the action of the sentence, then we want to know what they are doing, and finally we want to know what they are doing that action to.  In Latin, they wanted to know who or what was doing the action, then they wanted to know who or what the action was being done to, and only then did they want to know what action was being done.</p>
<p>Now, of course, this happens very quickly in speech.  Nevertheless, there is a preference for the order of information, and adjusting how information comes can cause some amount of mental stress when one is learning a foreign language.</p>
<p>So what does this have to do with Breaking Benjamin then and the line “only the strongest will survive” that I talked about clear at the beginning of this piece?  I’m glad you asked!  Consider these two sentences side-by-side:</p>
<blockquote><p>Only the strongest will survive.<br />
Only the strongest will survives.</p></blockquote>
<p>There is only one letter different between the two sentences, yet that one letter also determines whether or not the word “will” is a noun or a verb.  And the best part?  The letter that makes the determination is the absolute last letter in the sentence, and it’s not even part of the word that is changed!  In the first sentence, “will survive” is the verb, but in the second, “strongest will” is the noun.</p>
<p>Now the question that I find interesting is this.  If you were given those two sentences at different times in a conversation, at what point do you <i>know</i> whether “will” is a noun or a verb?  Granted, you would typically have a lot more context than just one of those two sentences.  Example: “You have to have a strong will to make it in the world.  Weak-willed people just cannot cut it.  Only the strongest will survives.”  Here, the surrounding context would most likely make you think “will” is a noun the instant it comes up.</p>
<p>Nevertheless, I would wager that if I <i>started</i> an essay with “Only the strongest will survives” and another one with “Only the strongest will survive”, you would read both of those essays and <i>automatically</i> adjust the meaning in your mind, most likely without even noticing you’d done so.  Indeed, I suspect that your brain provisionally holds a definition for the word “will” when it first encounters it, and then later on when it gains the rest of the knowledge needed, it “settles” on the grammatically correct interpretation.  All without you consciously wondering whether “will” is a noun or verb.</p>
<p>Ultimately, the word “will” as used above <i>must be a fuzzy word</i> as it is being used.  Your brain has to hold two potential meanings at the same time, and those meanings are in two different categories of words (noun and verb).</p>
<p>This brings to mind the dictionary argument too.  When we are asked, “What does such-and-so word mean?” we go the dictionary.  But dictionaries do not create meaning, rather they tell us how words are already being used.  And the danger someone can fall into is thinking that the primary definition of a word is how the word must be used in every instance.  (This is especially dangerous for first year Greek students who find Strongs’ Concordance.)</p>
<p>I thought of an illustration of the “dictionary fallacy.”  Suppose someone pulls up an English text—let’s use Stephen King’s <i>The Stand</i> since it’s got significant length.  This person randomly searches through the book and selects, again at random, one letter from one word.  This person says, “I will give you $1,000,000 if you guess what letter was randomly selected.”  In order to have the best shot at gaining the million dollars, what letter should you select?</p>
<p>By far, the most common letter in English is the letter “e.”  Hands down, your choice should be “e.”  But what are the odds that you would win the million dollars?  According to <a href = "http://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html" target = _blank>a study</a> done at Cornell, you would have only a 12.02% chance of winning the million dollars.  That means that even though the letter “e” is most frequent, if you pick “e” you will be wrong nearly 88% of the time.</p>
<p>The same thing most certainly happens with definitions too, especially with words like “will.”  For instance, look at the use of the word will here: “I will, of my own free will, that the will will be executed by Will.”  Indeed, this reminds me of the famous grammatically-correct sentence involving the word “buffalo”: <a href = "http://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo" target = _blank>Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo</a> (you can click the link to read the article about how it works out).</p>
<p>Translation, therefore, isn’t simply a substitution of the most commonly used definitions.  Words have their meaning by use, and people use words very loosely.  In the end, while it may serve to set analytical minds at ease if words were islands in the sea, conventionally words will always remain clouds in the sky.</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/12/14/islands-and-clouds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why You Shouldn&#8217;t Complain About the Weather</title>
		<link>http://calvindude.com/dude/2011/10/19/why-you-shouldnt-complain-about-the-weather/</link>
		<comments>http://calvindude.com/dude/2011/10/19/why-you-shouldnt-complain-about-the-weather/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 14:50:10 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Satire]]></category>
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=2075</guid>
		<description><![CDATA[Yesterday, I complained that it was 36 degrees when I rode my bike in to work. Today it was 29. That&#8217;s enough for me to declare &#8220;correlation&#8221;! Speaking of correlation, along a similar thread, it&#8217;s been a couple of months since school started, and I have to ride by one on the way in to [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I complained that it was 36 degrees when I rode my bike in to work.</p>
<p>Today it was 29.</p>
<p>That&#8217;s enough for me to declare &#8220;correlation&#8221;!</p>
<p>Speaking of correlation, along a similar thread, it&#8217;s been a couple of months since school started, and I have to ride by one on the way in to work.  And my conclusion, having been past it nearly every school morning for two months, is that people who drop their kids off at school couldn&#8217;t drive to save their life.  Like, there&#8217;s a 2-way stop sign there that magically becomes a 4-way stop because people just decide to not drive through it and block traffic, and then everyone else stops&#8211;even though there is clearly no stop sign at the intersection.</p>
<p>But this brings a dilemma too.  What do I correlate that to?  Is it that parents dropping off kids are poor drivers, or is it more general, since roughly 80% of the drivers there are female.  So maybe it&#8217;s women make poor drivers.  But then, I have to acknowledge that every single person I&#8217;ve seen there has been white, so maybe white people just make poor drivers.  Finally, there was an over-representation of SUVs and minivans, so the correlation clearly is that drivers of said vehicles are poor drivers.</p>
<p>Clearly, all of these things are correlated.  And therefore, Global Warming is true.  Proof of Global Warming is found in the fact that it was 29 degrees this morning when yesterday it was 36.  Clearly such a wild swing in temperatures can only be caused by massive global climate shifts&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/10/19/why-you-shouldnt-complain-about-the-weather/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line Finder</title>
		<link>http://calvindude.com/dude/2011/08/08/line-finder/</link>
		<comments>http://calvindude.com/dude/2011/08/08/line-finder/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 16:20:10 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=2021</guid>
		<description><![CDATA[One problem that you&#8217;ll run into if you program a lot of VBScripts is when you&#8217;re trying to track down a syntax error. When your script is short, this is easy. But when it says you made an error on line 107, it can be a pain trying to count through to find what line [...]]]></description>
			<content:encoded><![CDATA[<p>One problem that you&#8217;ll run into if you program a lot of VBScripts is when you&#8217;re trying to track down a syntax error.  When your script is short, this is easy.  But when it says you made an error on line 107, it can be a pain trying to count through to find what line that is.</p>
<p>To help combat this, I wrote a short script that will search for the appropriate line and display a message box quoting it.  Obviously, it could potentially be improved a bit, but for a Q&#038;D (i.e., &#8220;Quick and Dirty&#8221;) approach, this serves me well:</p>
<blockquote><pre>' line finder

Const ForReading = 1

strFileName = InputBox("File name: ")
LineNum = Inputbox("Line number: ")
LineNum = cInt(LineNum)

set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

i = 0

Do until objFile.AtEndOfStream
	i = i + 1
	LineText = objFile.ReadLine
	if i = LineNum then
		KeepText = LineText
	end if
Loop

Wscript.Echo KeepText</pre>
</blockquote>
<p>So have fun coding. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/08/08/line-finder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spamers Are At It Again</title>
		<link>http://calvindude.com/dude/2011/08/07/spamers-are-at-it-again/</link>
		<comments>http://calvindude.com/dude/2011/08/07/spamers-are-at-it-again/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 04:24:55 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[Evolution]]></category>
		<category><![CDATA[Penseés]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=2019</guid>
		<description><![CDATA[While I have a good program that helps to cut down the amount of spam I receive, occasionally the spam-bots wise up and alter their programming and, for a few weeks, I get flooded with spam again. It&#8217;s like an arms race in biology. Except it comes to mind that really Darwinism only works in [...]]]></description>
			<content:encoded><![CDATA[<p>While I have a good program that helps to cut down the amount of spam I receive, occasionally the spam-bots wise up and alter their programming and, for a few weeks, I get flooded with spam again.  It&#8217;s like an arms race in biology.</p>
<p>Except it comes to mind that really Darwinism only works in computer theory, when you can boil everything down to one or two essential factors and create an arms race out of it.  In biological systems, there are more factors involved (something that Darwinists continually forget) meaning that an increase in one aspect does not necessarily translate into an increase in fitness across the board.</p>
<p>But with computer programs and spam bots, the theory works just fine. </p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/08/07/spamers-are-at-it-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>21 (Part 3): Random Number Generator</title>
		<link>http://calvindude.com/dude/2011/07/23/21-part-3-random-number-generator/</link>
		<comments>http://calvindude.com/dude/2011/07/23/21-part-3-random-number-generator/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 21:12:05 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1980</guid>
		<description><![CDATA[As we continue looking at the structure of 21, the next concept we’ll look at is the Rnd function. Rnd is used to generate random numbers between 0 and 1—in other words, a decimal number. For example, you can run this easy VBScript: n = rnd wscript.echo(n) When I ran this script, it popped up [...]]]></description>
			<content:encoded><![CDATA[<p>As we continue looking at the structure of 21, the next concept we’ll look at is the <b>Rnd</b> function.  <b>Rnd</b> is used to generate random numbers between 0 and 1—in other words, a decimal number.  For example, you can run this easy VBScript:</p>
<blockquote><pre> n = rnd

wscript.echo(n)</pre>
</blockquote>
<p>When I ran this script, it popped up 0.7055475 for the value.  That’s good, because there’s “no way” you could have predicted that in advance!  So obviously, this is true randomness, right?</p>
<p>Well, what happens if I run it a second time?  I get the value 0.7055475.</p>
<p>I run it a third time and, you guessed it, the value is 0.7055475.</p>
<p>This explains why I put “no way” in quotes above, because in reality you <i>can</i> predict what it’ll be.  That sort of defeats the whole purpose of adding randomness into your computer program!  It would be nice if we could somehow make it where we’ll get a different number each time we run the script.</p>
<p>And VBScript has a way of doing that.  It’s the <b>Randomize</b> keyword.  Simply add that to the top of your script like this:</p>
<blockquote><pre> Randomize

n = rnd

wscript.echo(n)</pre>
</blockquote>
<p>What happens when I run it this time?  I get 0.4127008.  I run it a second time and I get 0.2001459.</p>
<p>The reason this occurs is because random numbers on computer programs are never truly random at all.  Instead, the computer has an algorithm it goes through to make pseudo-random results, but the algorithm is determined by a starting “seed” number.  This seed number is the same each time you run it, normally.</p>
<p>But what happens when we add the <b>Randomize</b> keyword?  It changes it so that the seed number that’s used is based on the system time instead.  Since time is represented by a number, and the system time goes to tiny fractions of seconds, then putting that in as the seed virtually guarantees that running the script multiple times will have a different seed in the algorithm each time through.  And the algorithm is specifically designed so that seeds of close numbers can still yield wildly different results. </p>
<p>It must be made clear that these results given are not truly random.  They are pseudo-random, however, in that despite the fact that they are deterministically generated by seed values, it is virtually impossible for any human to be able to determine beforehand what the results will be, and therefore this process mimics randomness for all intents and purposes.  For that reason, I will use the word “random” or “randomly” throughout this post, despite the fact that I should really use the word “pseudo-random” or “pseudo-randomly” instead.</p>
<p>So now we have a way to pick a random number between 0 and 1.  But how does that help us when we’re trying to choose random numbers between 1 and 11?  Or between 3 and 7?  (Both are requirements for the game 21.)</p>
<p>To solve this, we’re going to have to do a little math, but we’re also going to have to understand how VBScript converts numbers with decimals to integers.  This is because we need the final answer to be in integer format, but the <b>rnd</b> function returns a decimal number.  To convert to an integer in VBScript, you use the <b>int()</b> function, where you put the number you’re going to convert to an integer in the parentheses.</p>
<p>The first thing to know is that VBScript converts decimals to integers by just chopping off everything at the decimal point.  The key point to understand is that VBScript <i>does not round</i>!  That is, converting 1.1, 1.5, and 1.9 to integers in VBScript will yield answers of 1, 1, and 1:</p>
<blockquote><pre>n1 = 1.1
n2 = 1.5
n3 = 1.9

n1 = int(n1)
n2 = int(n2)
n3 = int(n3)

wscript.echo(n1 &#038; ", " &#038; n2 &#038; ", " &#038; n3)</pre>
</blockquote>
<p>Before we look at the more complex problems in 21, let’s look at a simpler version.  If we want to pick a number between 1 and 10, then we know that we have to get the number on the left-hand side of the decimal to become a number between 1 and 10, because the <b>int()</b> function will chop off the rest.  So how do we do that?</p>
<p>Well, let’s look at what happens if we multiply a decimal number.  Suppose we start with 0.91.  Multiply it by 10, and we get 9.1.  Find <b>int(9.1)</b> and we get 9.</p>
<p>So this is very good.  If we want to find a number between 0 and 9, we can multiply the fraction by 10.  But, if you notice, we want to find a value between 1 and 10, not 0 and 9.  How do we do that?  Simple!  We can just add 1 to the end result.  0.91 becomes 9.1; int(9.1) = 9.  And finally 9 + 1 = 10.  Consider the other end.  0.00 becomes 0.0; int (0.0) = 0.  And finally 0  + 1 = 1.  So this will find numbers between 1 and 10, just like we wanted!</p>
<p>But what happens when we’re looking for numbers between 1 and 11, like in the first problem in 21?  Well, we can just multiply by 11 instead.  0.91 x 11 = 10.01, for instance.  Adding 1 to the end result will bring us back to 11.  Similarly, 0.00 x 11 = 0, and adding 1 will bring us to 1.  So it works out.</p>
<p>This shows us the basic gist of what goes on, and we may think we know the key already.  Just multiply the random number by the maximum value possible, then add the minimum value possible.  But this is actually only accurate when we’re finding a value between 1 and some maximum value.  Suppose we were looking for a value between 0 and 10.   If we multiply by the maximum value possible—10—then add the minimum value possible—0—we will never be able to have a result that is 10.  If, on the other hand, we add 1 to the end result, we’ll never be able to have 0 as a result.  Instead, what we need to do is multiply by <i>one more</i> than the maximum number in order to make this work for the range between 0 and 10.</p>
<p>Now we’ve got a bit of a problem, because one function works when 1 is the lowest number (i.e., MaximumNumber x RandomNumber, then add MinimumNumber) but when 0 is the lowest number we have to use a completely different one ((MaximumNumber + 1) x RandomNumber, then add MinimumNumber).  And we haven’t even gotten to consider what happens when we’re trying to find a number between 3 and 7.</p>
<p>Thankfully, if we find a way to merge the two functions above into one, we’ll actually have found the rule for all of them.  When we merge them, we get this:</p>
<p>(MaximumNumber – MinimumNumber + 1) x RandomNumber + MinimumNumber</p>
<p>To see how this works, when the MinimumNumber = 0, then the first part is MaximumNumber + 1.  When MinimumNumber = 1, then the first part is just MaximumNumber (because 1 – 1 = 0).  So we see these two functions do combine into the one.</p>
<p>And now consider when we try to find a number between 3 and 7.  Plug that in and we get:</p>
<p>(7 – 3 + 1) x RandomNumber + 3.</p>
<p>Or, 5 x RandomNumber + 3.</p>
<p>Obviously, if the RandomNumber is 0.0, then 5 x 0 = 0, and we add 3 to that.  This means the lowest possible number is, indeed, 3.  And if the Random number is 0.9, then 5 x 0.9 = 4.5.  Add 3 to that, and it’s 7.5; int(7.5) = 7.  So the highest number we can get is, indeed, 7.  This likewise works out, and that&#8217;s the format we use in 21 to yield our random numbers.</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/23/21-part-3-random-number-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>21 (Part 2): InputBox</title>
		<link>http://calvindude.com/dude/2011/07/21/21-part-2-inputbox/</link>
		<comments>http://calvindude.com/dude/2011/07/21/21-part-2-inputbox/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 18:25:10 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1968</guid>
		<description><![CDATA[[NOTE: Due to the way my WordPress theme works, you probably won't be able to read all the code below. However, if you copy and paste it into a different window, the lines will still show up for you.] 21 is a game which relies on user input as well as automated, behind-the-scenes processes. When [...]]]></description>
			<content:encoded><![CDATA[<p>[<i><b>NOTE:</b> Due to the way my WordPress theme works, you probably won't be able to read all the code below.  However, if you copy and paste it into a different window, the lines will still show up for you.</i>]</p>
<p>21 is a game which relies on user input as well as automated, behind-the-scenes processes.  When we look at the structure of 21, as seen in <a href = "http://calvindude.com/dude/2011/07/20/21-part-1/">part 1</a>, we see that this input is required in two areas: 1) in deciding whether to pick a card (and if so, which one) or to hold; 2) in deciding whether to exit the game or play another round.  Both instances can be controlled by use of a menu-driven input box.  In other words, a menu is presented with numbered options that the user can select for by inputting the desired number.</p>
<p>It is relatively easy to make an input box in VBScript that allows information to be gleaned from the user.  The command uses the keyword <b>InputBox</b>.  I won’t go over all the attributes of <b>InputBox</b> here, but the bare bones version is <i>some variable</i> = <b>InputBox</b>(<i>the message you want to display on the input box</i>).  This assigns the value that the user types into the box to whatever variable you choose.</p>
<p>Let’s give a quick demonstration.  Open Notepad and type in the following:</p>
<blockquote><pre>Name = InputBox("What is your name?")

wscript.echo(Name)</pre>
</blockquote>
<p>Save the file as something that ends with the .vbs extension (say, “Inputbox.vbs”), then run your script.  When you run it, a box will pop up asking you for your name.  Type in anything, and whatever you type in will be displayed back to you in another message box (the second box is created by the <b>wscript.echo</b> command).</p>
<p>This shows both the strength and weakness of <b>InputBox</b>.  It’s strength is that the data can be of any type.  This is made possible because VBScript is not strongly typed, but instead makes its best “guess” as to what type of data is entered while it’s processing the script.  Most of the time, this is fine.  But when it comes to a menu-driven interface, that can be problematic because the menu interface requires the data input by the user to be <i>integers</i>.</p>
<p>Let’s see how this is a problem.  Open your Notepad again and change the code to the following:</p>
<blockquote><pre>Number = InputBox("Type a number:")

IF (Number < 10) THEN
     wscript.echo ("The number you typed in is less than 10")
ELSE
     wscript.echo ("The number you typed in is greater than or equal to 10")
END IF</pre>
</pre>
</blockquote>
<p>Run this script now and type in a number.  For example, if you type in 110 it will output “The number you typed in is greater than or equal to 10.”  Type in 1 and it will output “The number you typed in is less than 10.”  So it’s working like it’s supposed to, right?</p>
<p>Well, try this.  Instead of typing a number, type in the letter “a” and hit enter.  What happens?   You get an error (“Type mismatch: ‘Number’”) and the program crashes.  The last thing that we want is to crash a program.  This is especially true with scripting programs, because when it crashes there’s no way to recover from where you were.  You have to start the program all over again.</p>
<p>All good programmers need to be able to anticipate user errors and write code that will make it as close to error-proof as possible.  As a result, we need to check if the data that is typed into the program is an integer or not, and if it is not we should display an error message and allow the user to try again.  Thankfully, VBScript has a command that allows us to check if the data is a number, and it’s helpfully called <b>IsNumeric</b>.  Here’s how to use it.</p>
<blockquote><pre>Number = InputBox("Type a number:")

IF IsNumeric(Number) THEN

     IF (Number < 10) THEN
          wscript.echo ("The number you typed in is less than 10")
     ELSE
          wscript.echo ("The number you typed in is greater than or equal to 10")
     END IF
ELSE
     wscript.echo ("You did not type in a number")
END IF</pre>
</pre>
</blockquote>
<p>Now if you type in a letter, you get a helpful “You did not type in a number” instead of a program crash.  However, it would still be nice if we could prompt the user to try again, rather than just exiting the program.  To that end, we can put the entire thing in a <b>DO…LOOP WHILE</b> loop.</p>
<p>In order to do it well, however, we need to alter the <b>InputBox</b> command a little by replacing the literal statement (i.e., that which is in quotes) with a variable.  That way, we don’t have to try to fit a lot of text into the command, and furthermore we can add an error message and things of that nature to it too.  So, here we go:</p>
<blockquote><pre>strMessage = "Type a number:"
strError = "" 

Valid = FALSE

DO
     Number = InputBox(strError &#038; vbCrLf &#038; strMessage)

     Valid = IsNumeric(Number)

     IF Valid THEN

          IF (Number < 10) THEN
               wscript.echo ("The number you typed in is less than 10")
          ELSE
               wscript.echo ("The number you typed in is greater than or equal to 10")
          END IF
     ELSE
          strError = "WARNING: You must type in a number!"
     END IF

LOOP WHILE Valid = FALSE</pre>
</pre>
</blockquote>
<p>So here we set up a Boolean variable called <i>Valid</i>.  Valid can be either TRUE or FALSE, and we default it to FALSE.  However, Valid then takes on the value from the test of <b>IsNumeric(Number)</b>, which means if it’s a number Valid becomes TRUE, but if it’s not a number Valid becomes FALSE.  As long as Valid is FALSE, the loop repeats.</p>
<p>Now there’s one last bit to this, which I did not address in my quick version of 21 which I linked to earlier, and that’s the case of what happens when you hit the <i>Cancel</i> button on the InputBox.  If you run the above script and, instead of entering a value, you click <i>Cancel</i> you get a box that pops up saying: “The number you typed in is less than 10”.  But, of course, you didn’t type in any number at all!</p>
<p>What happens is that VBScript will interpret a variable that has no value as a 0 if it’s used as a number, or as “” (which is a null string) if it’s used as a string.  To verify that the Number has no value, use this code:</p>
<blockquote><pre>strMessage = "Type a number:"
strError = "" 

Valid = FALSE

DO
     Number = InputBox(strError &#038; vbCrLf &#038; strMessage)

     Valid = IsNumeric(Number)

     IF Valid THEN
          strMessage = "The value of the number you typed is " &#038; Number &#038; vbCrLf

          IF (Number < 10) THEN

               strMessage = strMessage &#038; "The number you typed in is less than 10"

          ELSE
               strMessage = strMessage &#038; "The number you typed in is greater than or equal to 10"
          END IF
          wscript.echo(strMessage)
     ELSE
          strError = "WARNING: You must type in a number!"
     END IF

LOOP WHILE Valid = FALSE</pre>
</pre>
</blockquote>
<p>If you run this and hit <i>Cancel</i> you can see that no value is displayed for the number.  Now, in the script version of 21, I actually exploited this feature because a 0 value meant to cancel out of the menu, so it worked to my benefit to have VBScript treat the null value as if it were a 0.  But here it doesn’t work to our advantage.  In this case, we can do a test using the <b>VarType</b> command to see if the Cancel button was pressed, and if it was we can terminate the script:</p>
<blockquote><pre>strMessage = "Type a number:"
strError = "" 

Valid = FALSE

DO
     Number = InputBox(strError &#038; vbCrLf &#038; strMessage)

     IF VarType(Number) = 0 THEN wscript.quit

     Valid = IsNumeric(Number)

     IF Valid THEN
          strMessage = "The value of the number you typed is " &#038; Number &#038; vbCrLf

          IF (Number < 10) THEN

               strMessage = strMessage &#038; "The number you typed in is less than 10"

          ELSE
               strMessage = strMessage &#038; "The number you typed in is greater than or  equal to 10"
          END IF
          wscript.echo(strMessage)
     ELSE
          strError = "WARNING: You must type in a number!"
     END IF

LOOP WHILE Valid = FALSE</pre>
</pre>
</blockquote>
<p>This is the basic way I used <b>InputBox</b> to get data from the user in the 21 script. </p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/21/21-part-2-inputbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>21 (Rough Cut&#8211;Part 2 Will Follow Later)</title>
		<link>http://calvindude.com/dude/2011/07/21/21-rough-cut-part-2-will-follow-later/</link>
		<comments>http://calvindude.com/dude/2011/07/21/21-rough-cut-part-2-will-follow-later/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 14:05:43 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1966</guid>
		<description><![CDATA[I now have a &#8220;rough cut&#8221; of the program 21, which is my Psuedo-Blackjack simulator in VBScript. The code is not yet optimized, and the AI code is very basic (as in, just enough to get it functional). Nevertheless, you can save the script by downloading it from http://www.calvindude.com/VBScripts/21_rough_cut.vbs. Once saved, double-click the file and [...]]]></description>
			<content:encoded><![CDATA[<p>I now have a &#8220;rough cut&#8221; of the program 21, which is my Psuedo-Blackjack simulator in VBScript.  The code is not yet optimized, and the AI code is very basic (as in, just enough to get it functional).  Nevertheless, you can save the script by downloading it from <a href = "http://www.calvindude.com/VBScripts/21_rough_cut.vbs">http://www.calvindude.com/VBScripts/21_rough_cut.vbs</a>.  Once saved, double-click the file and it&#8217;ll run automatically (assuming you have Windows).</p>
<p>I&#8217;ll go over the details of it in a future post.</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/21/21-rough-cut-part-2-will-follow-later/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>21 (Part 1)</title>
		<link>http://calvindude.com/dude/2011/07/20/21-part-1/</link>
		<comments>http://calvindude.com/dude/2011/07/20/21-part-1/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 15:13:50 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1960</guid>
		<description><![CDATA[Last night, I began work on a new program in VBScript which I’m calling 21. It’s roughly based on the rules for Blackjack, where you get random “cards” dealt to you and the object is to get as close to 21 as you can without going over. Now, I didn’t manage to finish this program [...]]]></description>
			<content:encoded><![CDATA[<p>Last night, I began work on a new program in VBScript which I’m calling 21.  It’s roughly based on the rules for Blackjack, where you get random “cards” dealt to you and the object is to get as close to 21 as you can without going over.  Now, I didn’t manage to finish this program last night since a certain fiancée I have wanted to chat with me (go figure!) but as I was preparing for bed I figured that a little script-based program like 21 would actually work quite well as a teaching tool since 1) the rules are pretty simple and straightforward, so you don’t get bogged down in a bunch of heavy code; and, 2) it actually still has areas where you can go profoundly deep.</p>
<p>So it’s a good thing I didn’t finish it, because now I can go over it a bit more organically here on the blog.  In other words, you can see closer to “real time” how I flesh out concepts when I’m working on a program.</p>
<p><b>Overview</b></p>
<p>First of all, we need to know what the basic gist of the program is going to be.  Obviously, 21 is a Blackjack lookalike—but that doesn’t tell us enough about it to start programming.  We need to look at the rules.</p>
<p>The first rule is that there are two players: the user and the dealer.  The dealer will be controlled by the computer code.  The user is going to be the person who runs the program.</p>
<p>The object of the game is to get “cards” in your hand that get as close to 21, but not over.  The user bets a small sum (say, $1 for the game) and begins.  The user can always select to receive another card, as long as the current total in his hand is less than 21.  (We can also let the user be an idiot and select a card if his hand value is <i>equal</i> to 21 too.)  The user can also decide to “hold” at any point, and the value of the cards he holds will be his “score” for the round.  If the user goes over 21, he “busts” and loses automatically, thus giving the dealer the $1 (this, incidentally, is part of what gives the dealer the edge in the game—he doesn’t have to play if the user busts first).</p>
<p>Assuming the user does not bust, the dealer then plays.  The dealer must either meet or beat the score of the user’s hand, without going bust himself.  If the dealer gets the same score as the user (that is, he “meets” the user’s score) then it is considered a tie, and the $1 is given back to the user.  If the dealer beats the user’s hand, the dealer wins the $1.  If the dealer busts, the user wins back both the $1 he bet <i>and</i> another $1 as reward for winning.</p>
<p>In 21, we will not use an actual deck of cards (i.e., having an Ace, 2 – 10, Jack, Queen, and King), but instead we will use a random number generator.  To give the user a little more control of what goes on, we will give him the option of selecting from two different types of card.  Card type 1 will be a card that will have a value between 3 and 7.  Card type 2 will be a card that will have a value between 1 and 11 (this value is selected so that it is possible for a user to get 21 after only two draws, by drawing a 10 and an 11, or to even go bust after only two draws by drawing two 11s).</p>
<p>The game begins by drawing a “Pot” card from Card Type 2.  The Pot card will be used by both the dealer and the user to begin their hand.  Thereafter, each player will draw their own unique cards for their hand.  In other words, suppose the Pot card at the beginning is 8.  <i>Both</i> the user’s current score <i>and</i> the dealer’s current score is 8.  But, the user will draw his own card (say, a 7) and his new total will be the sum of the Pot card and the user’s new card, in this case 15.  Meanwhile the dealer’s is still 8.  Supposing the player holds at 15, the dealer can then select to draw a card (say, a 10)—and his total will then be the Pot card plus the dealer’s new card, or in this case 18.</p>
<p><b>Program Structure</b></p>
<p>At this point, we can begin to think a bit about the structure of the program.  I am going to select a menu-type interface (since we’re using VBScript), where the user will be able to select numbers to determine actions.  We will therefore have the main program controlled by a DO … LOOP WHILE loop, which I will explain in detail as we get to it.  Essentially, the program will loop until the while condition is satisfied, which we will define as being two conditions: 1) the user terminates the program; 2) the user has no more money.</p>
<p>Note: in order for us to implement (2) above, this will require us to keep track of the user’s bankroll.  For instance, we can begin the game as a whole by having the user start with $10.  At any point the user gets to $0, the game is over.  Likewise, at any point the user wishes to exit the game, the game will end and his winnings will be displayed.</p>
<p>So the basic gist of the program will begin thus:</p>
<pre>HEADER INFORMATION (i.e., where all the constants and variables
                          are created)

BEGIN MAIN PROGRAM LOOP:

     PLAY A ROUND OF THE GAME

     DETERMINE IF GAME OVER

END MAIN PROGRAM LOOP

DISPLAY END RESULTS</pre>
<p>Now we need to better define what constitutes PLAY(ing) A ROUND OF THE GAME.  So let’s look at the next level of structure:</p>
<pre>SELECT A POT CARD

     ROUND IS PLAYED

RESULTS OF ROUND</pre>
<p>Now let’s drill down into what happens when a ROUND IS PLAYED:</p>
<pre>USER PLAYS

IF USER DOESN’T LOSE, DEALER PLAYS</pre>
<p>Finally, we need to define both what USER PLAYS means and what DEALER PLAYS means.  So first, USER PLAYS:</p>
<pre>BEGIN USER TURN LOOP:

     PRESENT OPTIONS (user can draw type 1, type 2, or hold)

          IF USER SELECTS TO HOLD
               END USER TURN AS HOLD

          IF USER SELECTS TYPE 1
               DRAW TYPE 1 CARD
          IF USER SELECTS TYPE 2
               DRAW TYPE2 CARD

          ADD NEW CARD TO USER TOTAL

          IF USER BUSTS
               END USER TURN AS LOSS     

END USER TURN LOOP</pre>
<p>This loop will terminate either if the user holds (i.e., END USER TURN AS HOLD) or busts (i.e., END USER TURN AS LOSS).</p>
<p>Now let’s examine the DEALER TURN.  This only occurs IF USER DOESN’T LOSE:</p>
<pre>BEGIN DEALER TURN LOOP:

     USE STATISTICS TO DECIDE WHICH TYPE OF CARD TO DRAW

     ADD NEW CARD TO DEALER TOTAL

     IF DEALER TOTAL > 21
          END DEALER TURN AS USER WIN

     IF DEALER TOTAL > USER TOTAL
          END DEALER TURN AS DEALER WIN

    IF DEALER TOTAL = USER TOTAL
          END DEALER TURN AS TIE

END DEALER TURN LOOP</pre>
<p>Note that in the above, the loop will go until the dealer either busts, ties the user, or beats the user.  Furthermore, if the dealer ties, right now we’re going to just make it a tie.  In the future, we can add AI that will determine whether or not the dealer would like to draw again.  (For instance, suppose that the user’s score is 14 and he holds.  If the dealer reaches 14, he can still draw a card of type 1 (which is 3 – 7) and be guaranteed of a win—but for now, to keep it simple, we’ll just force the tie.)</p>
<p>So now let’s put the entire structure together:</p>
<pre>21 PROGRAM STRUCTURE

HEADER INFORMATION

BEGIN MAIN PROGRAM LOOP:

     SELECT A POT CARD

          BEGIN USER TURN LOOP:

               PRESENT OPTIONS

               IF USER SELECTS TO HOLD
                    END USER TURN AS HOLD

               IF USER SELECTS TYPE 1
                    DRAW TYPE 1 CARD
               IF USER SELECTS TYPE 2
                    DRAW TYPE2 CARD

               ADD NEW CARD TO USER TOTAL

               IF USER BUSTS
                    END USER TURN AS LOSS     

          END USER TURN LOOP

          IF USER HASN’T LOST

               BEGIN DEALER TURN LOOP:

                    USE STATISTICS TO DECIDE WHICH TYPE OF CARD
                    TO DRAW

                    ADD NEW CARD TO DEALER TOTAL

                   IF DEALER TOTAL > 21
                        END DEALER TURN AS USER WIN

                   IF DEALER TOTAL > USER TOTAL
                        END DEALER TURN AS DEALER WIN

                   IF DEALER TOTAL = USER TOTAL
                        END DEALER TURN AS TIE

              END DEALER TURN LOOP

     RESULTS OF ROUND

     DETERMINE IF GAME OVER

END MAIN PROGRAM LOOP

DISPLAY END RESULTS</pre>
<p>So that’s the basic structure.  Next up, we’ll begin to actually code some of this :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/20/21-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deceptive Appearance</title>
		<link>http://calvindude.com/dude/2011/07/13/deceptive-appearance/</link>
		<comments>http://calvindude.com/dude/2011/07/13/deceptive-appearance/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 17:35:27 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[Atheism]]></category>
		<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1940</guid>
		<description><![CDATA[On Facebook, Bnonn Tennant from the Thinking Matters website asked “Is it unreasonable to believe that God created a 14 billion year old universe a few thousand years ago?” Obviously, one can quibble about the terminology used in the question, but I take it to mean something similar to “Is it unreasonable to believe that [...]]]></description>
			<content:encoded><![CDATA[<p>On Facebook, Bnonn Tennant from the Thinking Matters website asked “Is it unreasonable to believe that God created a 14 billion year old universe a few thousand years ago?”  Obviously, one can quibble about the terminology used in the question, but I take it to mean something similar to “Is it unreasonable to believe that God created a man who appeared to be, say, twenty years old (Adam) who was really only created that instant?” Substitute the entire universe for the man and fourteen billion years for the age and you’ve got the same problem.</p>
<p>Now, since this was on Facebook, I won’t put the name of one of the people who responded, but the question was asked in response: “Would this make God a deciever [sic] though?”  I always find this question interesting, because it presumes that when God was creating the world, He must have considered all our future inferences about how to measure the age of the universe and then specifically set out to make up a false history in order to trick us in some manner.  It never occurs to people who ask this question that maybe God didn’t concern Himself at all with our inferences but instead had completely different reasons for having the Earth “look” old.</p>
<p>I put “look” in quotes above precisely because the apparent age of an object has no bearing on its actual age.   Consider the Tower of Terror ride at Disney California Adventure.  It’s modeled after a 1930s look and is covered with fake cobwebs and dust to give the appearance that the hotel is old and decrepit, but it actually opened at DCA in 2004.  Does anyone think that such a design qualifies as a deception on the part of Disney?  No, for we recognize this as an aesthetic choice Disney made that’s intended to make a ride more enjoyable so that people will be more willing to part with their money to ride it.</p>
<p>Now, if human beings can make something with the appearance of age without it being deceptive, why then would we rule out the ability for God to do so?</p>
<p>In closing, I merely point out that I take no stance on the age of the universe at all.  I believe time is meaningless without a temporal observer to experience it, so it’s really pointless to speak of any time before Adam was created in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/13/deceptive-appearance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing Some Conditionals</title>
		<link>http://calvindude.com/dude/2011/07/11/introducing-some-conditionals/</link>
		<comments>http://calvindude.com/dude/2011/07/11/introducing-some-conditionals/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 05:34:51 +0000</pubDate>
		<dc:creator>CalvinDude</dc:creator>
				<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://calvindude.com/dude/?p=1934</guid>
		<description><![CDATA[At the end of my previous post on nested loops, I showed how VBScript had a built in function that converted data to a timestamp. I figured now I’ll go ahead and show you how to do that manually, since it’s actually really easy. There are three things you have to keep in mind. First [...]]]></description>
			<content:encoded><![CDATA[<p>At the end of my previous post on nested loops, I showed how VBScript had a built in function that converted data to a timestamp.  I figured now I’ll go ahead and show you how to do that manually, since it’s actually really easy.</p>
<p>There are three things you have to keep in mind.  First of all, the hour format needs to be in the 12-hour clock mode.  This means that when it’s 0 hours, we change the 0 into a 12, and then for every hour greater than 12, we subtract 12 from that (so 13 becomes 1).</p>
<p>The second thing is that if the hour is less than 12, it needs to be listed as AM, but if it is greater than or equal to 12, it needs to be listed as PM.</p>
<p>The third is that any minute or second that is less than 10 needs to be printed with a preceding 0.  That is, you want the time to read 12:00:00, not 12:0:0.</p>
<p>To do all of these, we just need conditional statements, which we’ll do here using <i>if</i> … <i>else</i> commands.  For the structure, I’ll capitalize the IF, THEN, ELSE, and END IF commands.</p>
<p>First, we can take care of the AM or PM switch.  I created a new variable called am_pm for this.  Then we use the following conditional:</p>
<blockquote><pre> 	' Test if time is AM or PM
	' ------------------------
	IF hour < 12 THEN
		am_pm = "AM"
	ELSE
		am_pm = "PM"
	END IF</pre>
</pre>
</blockquote>
<p>If the hour is less than 12, this marks it as AM.  Otherwise, it’s marked as PM.</p>
<p>Next up is the conditional to make 0 display as 12.  For this, we needed a new variable to display the hour.  Typically, you could use the hour variable itself, but since it controls our loop, I didn’t want to change its value, so I created a new variable called hour_displayed.</p>
<blockquote><pre>
	' Convert 0 to 12, if needed
	' --------------------------
	IF hour = 0 THEN
		hour_displayed = 12
	ELSE
		hour_displayed = hour
	END IF</pre>
</blockquote>
<p>The final thing to do with the hour is to subtract 12 from any hour_displayed variable that is greater than 12.</p>
<blockquote><pre> 	' Convert anything over 12 to proper format
	' -----------------------------------------
	IF hour_displayed > 12 THEN
		hour_displayed = hour_displayed - 12
	END IF</pre>
</blockquote>
<p>For this, we didn’t need an ELSE statement, since the variable is fine as it is if it is less than or equal to 12 already.</p>
<p>Finally, we need to convert the minutes and seconds less than 10 so they display with a leading zero.  I did this in the middle of the “second” loop (that is, the loop counting seconds) so as to get both minutes and seconds at the same time:</p>
<blockquote><pre>
			' Add leading 0 to any single digit for both minutes &#038; seconds

			IF minute < 10 THEN
				minute_displayed = "0" &#038; minute
			ELSE
				minute_displayed = minute
			END IF

			IF second < 10 THEN
				second_displayed = "0" &#038; second
			ELSE
				second_displayed = second
			END IF</pre>
</pre>
</blockquote>
<p>Finally, we plug all that in to our original program and we get this, which perfectly mimics the FormatDateTime function (as used previously).</p>
<blockquote><pre> 'VBScript program to make a fake clock

' ===== Variables ====================

option explicit
dim hour, minute, second, clock
dim objFSO, objFile, objNotepad
dim am_pm, hour_displayed, minute_displayed, second_displayed

' ===== Initialization ===============

set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.CreateTextFile("output.txt", TRUE)

' ===== Loops ========================

for hour = 0 to 23

	' Test if time is AM or PM
	' ------------------------
	IF hour < 12 THEN
		am_pm = "AM"
	ELSE
		am_pm = "PM"
	END IF

	' Convert 0 to 12, if needed
	' --------------------------
	IF hour = 0 THEN
		hour_displayed = 12
	ELSE
		hour_displayed = hour
	END IF

	' Convert anything over 12 to proper format
	' -----------------------------------------
	IF hour_displayed > 12 THEN
		hour_displayed = hour_displayed - 12
	END IF

	for minute = 0 to 59
		for second = 0 to 59

			' Add leading 0 to any single digit for both minutes &#038; seconds

			IF minute < 10 THEN
				minute_displayed = "0" &#038; minute
			ELSE
				minute_displayed = minute
			END IF

			IF second < 10 THEN
				second_displayed = "0" &#038; second
			ELSE
				second_displayed = second
			END IF

			clock = hour_displayed &#038; ":" &#038; minute_displayed &#038; _
				":" &#038; second_displayed &#038; " " &#038; am_pm

			objFile.WriteLine(clock)
		next ' second loop
	next ' minute loop
next ' hour loop

' ===== Clean up loose ends =========

objFile.Close

wscript.echo("Done.  Click OK to view results.")

set objNotepad = CreateObject("Wscript.Shell")
objNotepad.Run("notepad.exe output.txt")</pre>
</pre>
</blockquote>
<p>There ya go. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://calvindude.com/dude/2011/07/11/introducing-some-conditionals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

