<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>powershell &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Sat, 11 Apr 2020 16:17:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>powershell &#8211; MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>Single line &#8220;if&#8221; statement in VBScript (like in C# or PHP)</title>
		<link>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/</link>
					<comments>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Mon, 13 Apr 2020 16:09:00 +0000</pubDate>
				<category><![CDATA[Classic ASP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[asp-classic]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[conditional-if]]></category>
		<category><![CDATA[conditional-operator]]></category>
		<category><![CDATA[function-like-c]]></category>
		<category><![CDATA[function-like-php]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[single-if]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[ternary-operator]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[vbscript-syntax]]></category>
		<category><![CDATA[visual-basic-script]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=234</guid>

					<description><![CDATA[The &#8220;single line if statement&#8221; exists in C# and VB.NET as in many other programming and script languages in the following format The conditional ternary operator doesn&#8217;t exist out of the box, but it&#8217;s pretty easy to create your own &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/" aria-label="Single line &#8220;if&#8221; statement in VBScript (like in C# or PHP)">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>The &#8220;single line if statement&#8221; exists in C# and VB.NET as in many other programming and script languages in the following format</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">lunchLocation = (dayOfTheWeek == &quot;Tuesday&quot;) ? &quot;Fuddruckers&quot; : &quot;Food Court&quot;;</pre></div>



<p>The conditional ternary operator doesn&#8217;t exist out of the box, but it&#8217;s pretty easy to create your own function in VBScript:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vbscript&quot;,&quot;mime&quot;:&quot;text/vbscript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;VBScript&quot;,&quot;modeName&quot;:&quot;vb&quot;}">Function IIf(bClause, sTrue, sFalse)
    If CBool(bClause) Then
        IIf = sTrue
    Else 
        IIf = sFalse
    End If
End Function</pre></div>



<p>You can then use this, as for the example above:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vbscript&quot;,&quot;mime&quot;:&quot;text/vbscript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;VBScript&quot;,&quot;modeName&quot;:&quot;vb&quot;}">lunchLocation = IIf(dayOfTheWeek = &quot;Tuesday&quot;, &quot;Fuddruckers&quot;, &quot;Food Court&quot;)</pre></div>



<p>The advantage of this over using a single line <code>If</code>/<code>Then</code>/<code>Else</code> is that it can be directly concatenated with other strings. Using <code>If</code>/<code>Then</code>/<code>Else</code> on a single line must be the only statement on that line.</p>



<p>There is no error checking on this, and the function expects a well formed expression that can be evaluated to a boolean passed in as the clause.</p>



<p>It&#8217;s also worth noting that unlike a real ternary operator, <strong>both the <code>sTrue</code> and <code>sFalse</code> parameters will be evaluated regardless of the value of <code>bClause</code></strong>. This is fine if you use it with strings as in the question, but be very careful if you pass in functions as the second and third parameters!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">234</post-id>	</item>
	</channel>
</rss>
