 




<?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>The VBScript Network and Systems Administrator&#039;s Cafe &#187; variant</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/variant/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>A new found bug in VBScript that causes if then statements to return wrong comparisons (or is it?)</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 00:00:58 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Integer]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[Variable Types]]></category>
		<category><![CDATA[variant]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[working with variables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/</guid>
		<description><![CDATA[In the past I&#8217;ve cautioned you on always initializing your variables and encouraged you to always declare your variable types, rather than using the default variant type in VBScript. I&#8217;ll be the first to admit I don&#8217;t follow my own advice in my examples! However, variants can be dangerous! Recently I had a situation where if [...]]]></description>
				<content:encoded><![CDATA[<p>In the past I&#8217;ve cautioned you on always initializing your variables and encouraged you to always declare your variable types, rather than using the default variant type in VBScript. I&#8217;ll be the first to admit I don&#8217;t follow my own advice in my examples! However, variants can be dangerous!</p>
<p>Recently I had a situation where if statements were returning completely not correct results and for the life of me I couldn&#8217;t figure it out! Here is an example that illustrates what was happening to me.</p>
<p><font color="#0000ff">one = 1<br />
two = 2<br />
three = 3<br />
OneBillion = 1000000000</font></p>
<p><font color="#0000ff">MyVar = inputbox(&#8220;Enter a number&#8221;)</font><font color="#0000ff">If one &lt; MyVar Then<br />
     WScript.Echo (one &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If<br />
If two &lt; MyVar Then<br />
     WScript.Echo (two &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font><font color="#0000ff"><font color="#0000ff">If three &lt; MyVar Then<br />
     WScript.Echo (three &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font></font><font color="#0000ff"><font color="#0000ff">If OneBillion &lt; MyVar Then<br />
     WScript.Echo (OneBillion &amp; &#8221; is lessthan &#8221; &amp; MyVar)<br />
End If</font></p>
<p></font><font color="#000000">The basis of the problem is that I was taking input from a file that was a number&#8211; however I was reading the file and it was coming into the script and being used as a string by the variant variable. I then was comparing it to a number and the comparisons were not working 100% correctly. Check it out by entering several numbers into the script. Try entering 0, 1, 2, 3, and 1000000001.</font></p>
<p>The moral of the story here is to always cast your varables as a specific type or use the cint() function to convert your variant varables to numbers before doing number comparisons with a literal number and a variant variable that is supposed to contain a number.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-new-found-bug-in-vbscript-that-causes-if-then-statements-to-return-wrong-comparisons-or-is-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
