<?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>if Archive - Robert Skibbe</title>
	<atom:link href="https://robbelroot.de/blog/tag/if/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>alias RobbelRoot – Freelance Full Stack Developer .NET</description>
	<lastBuildDate>Sun, 08 Aug 2021 23:01:05 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://robbelroot.de/wp-content/uploads/2020/12/cropped-favicon-32x32.png</url>
	<title>if Archive - Robert Skibbe</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>IFS VBA</title>
		<link>https://robbelroot.de/blog/ifs-vba/</link>
					<comments>https://robbelroot.de/blog/ifs-vba/#comments</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Sun, 08 Aug 2021 22:55:15 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic for Applications]]></category>
		<category><![CDATA[Visual Basic for Applications lernen]]></category>
		<category><![CDATA[abfrage]]></category>
		<category><![CDATA[abfragen]]></category>
		<category><![CDATA[anweisung]]></category>
		<category><![CDATA[ausdruck]]></category>
		<category><![CDATA[bedingung]]></category>
		<category><![CDATA[bedingungen]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[branching]]></category>
		<category><![CDATA[condition]]></category>
		<category><![CDATA[conditions]]></category>
		<category><![CDATA[different]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[expression]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[ifs]]></category>
		<category><![CDATA[kalkulation]]></category>
		<category><![CDATA[konditionen]]></category>
		<category><![CDATA[makro]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[microsoft 365]]></category>
		<category><![CDATA[msft]]></category>
		<category><![CDATA[office 365]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[result]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[tabellen]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[verzweigung]]></category>
		<category><![CDATA[verzweigungen]]></category>
		<category><![CDATA[visual basic]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=5138</guid>

					<description><![CDATA[<p>IFS VBA Möchtest Du mit der IFS VBA Funktion/Formel umzugehen wissen, bzw. verstehen was Diese überhaupt ist? Dann heiße ich Dich in meinem heutigen Beitrag zur Visual Basic for Applications Kategorie herzlich willkommen. Vielleicht steht Dir anschließend auch noch der Sinn nach anderweitigen VBA relevanten Beiträgen: VBA For Schleife, InStr, &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/ifs-vba/">IFS VBA</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung.png"><img fetchpriority="high" decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-1024x536.png" alt="" class="wp-image-5140" srcset="https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/08/IFS-VBA-Funktion-Verzweigung.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>IFS VBA</figcaption></figure>






<h2 class="wp-block-heading">IFS VBA</h2>



<p><strong>Möchtest </strong>Du mit der <strong>IFS VBA</strong> Funktion/Formel umzugehen wissen, bzw. <strong>verstehen was </strong>Diese überhaupt <strong>ist</strong>?</p>



<p>Dann <strong>heiße ich Dich </strong>in meinem heutigen Beitrag zur Visual Basic for Applications Kategorie <strong>herzlich willkommen</strong>.</p>



<p><strong>Vielleicht </strong>steht Dir <strong>anschließend </strong>auch <strong>noch </strong>der Sinn nach anderweitigen <strong>VBA relevanten Beiträgen</strong>: <strong><a href="https://robbelroot.de/blog/vba-for-schleife/" target="_blank" rel="noreferrer noopener">VBA For Schleife</a></strong>, <strong><a href="https://robbelroot.de/blog/vba-instr/" target="_blank" rel="noreferrer noopener">InStr</a></strong>, <strong><a href="https://robbelroot.de/blog/vba-range/" target="_blank" rel="noreferrer noopener">Range</a></strong>.</p>



<pre class="wp-block-verse"><strong>Achtung</strong>! Die IFS Funktion ist <strong>nur im Excel-Kontext</strong> <strong>als Formel </strong>vorhanden! Die dazu <strong>benötigte Excel </strong>Version findet man auf <strong>Windows &amp; Mac</strong>, wenn man <strong>mind. Office 2019</strong>, oder ein <strong>Microsoft 365 Abonnement </strong>hat.</pre>



<h2 class="wp-block-heading">Awendungsfälle</h2>



<p><strong>Wer </strong>kennt es <strong>nicht</strong>? <strong>Man möchte </strong>durch kurze <strong>geschickte Abfragen </strong>den <strong>Ablauf </strong>des Programmes <strong>bestimmen </strong>und <strong>leiten</strong>.</p>



<p><strong>Vielleicht </strong>sind Dir auch schon derartige <strong>Konstroll</strong>&#8211; , bzw. <strong>Verzweigungs-Strukturen</strong> wie das &#8222;If-Then-Else&#8220;- &amp; das &#8222;Select-Case&#8220; <strong>bekannt</strong>.</p>



<p>Das <strong>gut bekannte </strong>&#8222;<strong>If-Then-Else</strong>&#8222;-Konstrukt wird <strong>eher für </strong>die <strong>Abarbeitung</strong>, bzw. Steuerung von <strong>verschiedenen Ausgangspunkten </strong>verwendet.</p>



<p>Ich kann <strong>prüfen</strong>, <strong>ob </strong>die <strong>Performance </strong>einer Aktie <strong>gut </strong>war, <strong>jedoch</strong> dennoch die <strong>Dividende gekürzt </strong>wurde.</p>



<p><strong>Bei </strong>dem &#8222;<strong>Select-Case</strong>&#8222;-Konstrukt hingegen, <strong>prüft </strong>man für <strong>gewöhnlich einen Ausgangspunkt</strong> – z. B. auch <strong>Bereiche </strong>dessen – und handelt je nach Ergebnis.</p>



<p>Bleiben wir bei unserem <strong>kleinen Aktien-Beispiel</strong> und verfahren je nach <strong>Dividendenrendite </strong>anders:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Dim dividendYieldPercentage As Integer = 9
Dim message As String = ""
Select Case
    Case 1 To 2
        message = "Dividend yield is okay!"
    Case 3 To 4
        message = "Woah! Nice yield!"
    Case 5 To 6
        message = "Hmm, nice but maybe too much!?"
    Case Else
        message = "Woah, this is too much to be good!"
End Case</pre>



<h2 class="wp-block-heading">In der Kürze..</h2>



<p><strong>Häufig </strong>sagt man, dass <strong>in </strong>der <strong>Kürze </strong>die bekannte <strong>Würze </strong>liegt, man möchte es also ab und zu gerne <strong>kurz und schmerzlos </strong>haben.</p>



<p><strong>Wenn man </strong>jedoch die <strong>Länge </strong>des jeweiligen <strong>Konstruktes </strong>in <strong>Augenschein </strong>nimmt, hat man ein anderes Gefühl, eher <strong>lang und wiederholend</strong>.</p>



<p><strong>Im Falle </strong>einer <strong>relativ simplen </strong>&#8222;If-<strong>Anweisung</strong>&#8220; <strong>kann </strong>man den <strong>Ausdruck </strong>natürlich auch optional <strong>auf </strong>eine <strong>Zeile reduzieren</strong>.</p>



<p><strong>Je komplexer </strong>die eben erwähnte &#8222;If-Anweisung&#8220; allerdings wird, <strong>desto unlesbarer und unmöglich </strong>wird die Anweisung.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Dim performance As Integer = 100
If performance &lt;= 20 Then MsgBox("Yay")</pre>



<p><strong>Nehmen </strong>wir <strong>allerdings </strong>das Beispiel von oben, wäre es <strong>unlesbar </strong>und teilweise auch <strong>nicht möglich</strong>, daher würde ich nur in <strong>seltenen Fällen </strong>zur <strong>Verkürzung </strong>raten.</p>



<h2 class="wp-block-heading">IFS VBA Erklärung</h2>



<p>Mit der <strong>IFS-Funktion</strong> haben wir eine <strong>weitere Kontrollstruktur</strong>, um den <strong>Ablauf </strong>des &#8222;Programmes&#8220; zu <strong>gestalten</strong>.</p>



<p>Die <strong>IFS VBA (Excel) Formel</strong> wird dabei zunächst <strong>analog </strong>zum <strong>&#8222;Einzeiligen</strong> If&#8220; formuliert, <strong>mit </strong>einem <strong>kleinen Unterschied</strong>.</p>



<p><strong>Statt </strong>weniger <strong>Ausdrücke </strong>wie im If-Beispiel, können wir nun <strong>mehrere Ausdrücke</strong> wie durch Zauberhand <strong>kombinieren</strong>.</p>



<h2 class="wp-block-heading">IFS VBA Syntax – Schreibweise</h2>



<p><strong>Schauen wir</strong> uns zum obigen Vergleich einmal die <strong>Struktur, bzw. die Syntax der IFS-Funktion</strong> an:</p>



<pre class="wp-block-code"><code>=IFS(&lt;condition 1>, &lt;value 1>, &lt;condition 2>, ....)</code></pre>



<p>Dabei stellen wir fest, dass wir <strong>innerhalb </strong>der <strong>Klammern </strong>– also durch Angabe von <strong>Parametern </strong>– verschiedene <strong>Paare an Konditionen </strong>&amp; <strong>Werten </strong>angeben können.</p>



<p>Laut offizieller Dokumentation der <strong><a href="https://support.microsoft.com/en-us/office/ifs-function-36329a26-37b2-467c-972b-4a39bd951d45" target="_blank" rel="noreferrer noopener">IFS VBA Funktion</a></strong> von Microsoft, können wir <strong>bis zu 127 verschiedene Bedingungen</strong> prüfen und auswerten.</p>



<p><strong>Natürlich </strong>sollte man das <strong>nach Möglichkeit vermeiden</strong>, <strong>wer möchte </strong>schon eine gefühlt 40000 Zeichen <strong>lange Zeile</strong> lesen..</p>



<p><strong>Neben </strong>der <strong>schier endlos </strong>langen <strong>Zeile</strong>, hat man natürlich <strong>noch</strong> ein <strong>Problem mit </strong>den einzelnen <strong>Reihenfolgen</strong>, wo man sich dann <strong>leicht irren </strong>kann.</p>



<h2 class="wp-block-heading">Beispiel – Excel Zelle anhand IFS Formel</h2>



<p>Um nun <strong>beispielsweise </strong>den <strong>Wert </strong>einer <strong>Zelle </strong>im <strong>Excel-Sheet</strong> zu setzen, könnte man <strong>analog zu oben</strong> folgendes <strong>Beispiel </strong>verwenden.</p>



<p>Wir <strong>ziehen uns </strong>die <strong>Dividendenrendite </strong>dafür nun <strong>aus </strong>einer <strong>Zelle </strong>namens &#8222;A2&#8220; und setzen den <strong>Wert der Zelle </strong>&#8222;A3&#8220; dann auf <strong>das Ergebnis</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">=IFS(A2&lt;3, "Yield OK!", A2&lt;5, "Nice yield!", A2&lt;7, "Too much!")</pre>



<p><strong>Wenn </strong>im Beispiel der <strong>Wert </strong>in der Zelle &#8222;A2&#8220; z. B. <strong>unter 3</strong> liegt, dann <strong>gibt </strong>die Formel den Wert <strong>&#8222;Yield OK!&#8220; zurück</strong>.</p>



<p><strong>Bei </strong>einem Wert <strong>unter 5</strong> dann &#8222;<strong>Nice yield!</strong>&#8220; und und und..</p>



<figure class="wp-block-image size-full"><a href="https://robbelroot.de/wp-content/uploads/2021/08/VBA-IFS-Excel.png"><img decoding="async" width="356" height="155" src="https://robbelroot.de/wp-content/uploads/2021/08/VBA-IFS-Excel.png" alt="VBA IFS Excel" class="wp-image-5159" title="VBA IFS Excel" srcset="https://robbelroot.de/wp-content/uploads/2021/08/VBA-IFS-Excel.png 356w, https://robbelroot.de/wp-content/uploads/2021/08/VBA-IFS-Excel-300x131.png 300w, https://robbelroot.de/wp-content/uploads/2021/08/VBA-IFS-Excel-332x145.png 332w" sizes="(max-width: 356px) 100vw, 356px" /></a><figcaption>VBA IFS Excel</figcaption></figure>



<h2 class="wp-block-heading">Funktioniert übrigens auch bei Google Sheets</h2>



<p>Die <strong>IFS</strong>-Formel gibt es übrigens <strong>auch für</strong> die bekannte <strong>Cloud-Tabellen-Plattform Google Sheets</strong>.</p>



<p>Der <strong>einzige simple Unterschied </strong>ist, dass man dort <strong>statt Kommas</strong> (,) dann <strong>Semikolons</strong> (;) verwenden muss.</p>



<h2 class="wp-block-heading">Aber ich wollte IFS für VBA :(!?</h2>



<p><strong>Kein Problem</strong>! Leider wird man wie oben gesehen bei den Begriffen &#8222;<strong>IFS VBA</strong>&#8220; größtenteils nur im <strong>Bereich </strong>der <strong>Tabellen </strong>– also <strong><a href="https://de.wikipedia.org/wiki/Microsoft_Excel" target="_blank" rel="noreferrer noopener">Microsoft Excel</a></strong> &amp; <strong><a href="https://de.wikipedia.org/wiki/Google_Docs,_Sheets,_Slides_und_Forms#Tabellenkalkulation_(Sheets)" target="_blank" rel="noreferrer noopener">Google Sheets</a></strong> – fündig.</p>



<p><strong>Es gibt </strong>allerdings <strong>auch Codes </strong>wie Dieser hier (vom Stackoverflow-Nutzer &#8222;jsheeran&#8220;), <strong>Welcher </strong>eine <strong>ähnliche Implementierung </strong>im Bereich VBA darstellt:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Public Function UdfIfs(ParamArray args() As Variant) As Variant
  Dim i As Integer
  i = 0 ' or 1 if you're not using zero-based indexing
  Do Until CBool(args(i)) Or (i >= UBound(args))
    i = i + 2
  Loop
  If i &lt; UBound(args) Then
    UdfIfs = args(i + 1)
  End If
End Function</pre>
<p>Der Beitrag <a href="https://robbelroot.de/blog/ifs-vba/">IFS VBA</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/ifs-vba/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>VBScript If Else</title>
		<link>https://robbelroot.de/blog/vbscript-if-else/</link>
					<comments>https://robbelroot.de/blog/vbscript-if-else/#respond</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Thu, 15 Jul 2021 17:26:53 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic Script]]></category>
		<category><![CDATA[Visual Basic Script lernen]]></category>
		<category><![CDATA[andernfalls]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[branching]]></category>
		<category><![CDATA[dann]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[elseif]]></category>
		<category><![CDATA[falls]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[selektion]]></category>
		<category><![CDATA[then]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[verzweigung]]></category>
		<category><![CDATA[verzweigungen]]></category>
		<category><![CDATA[visual]]></category>
		<category><![CDATA[visual basic script]]></category>
		<category><![CDATA[wenn]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=4216</guid>

					<description><![CDATA[<p>VBScript If Else Du möchtest mit VBScript If Else &#8211;Anweisungen Entscheidungen, bzw. Verzweigungen in deinem Code realisieren? Kein Problem, lerne in diesem Beitrag wie Du das &#8222;If Then Else&#8222;-Konstrukt richtig anwendest. Vielleicht interessieren Dich auch andere Beiträge zu einem späteren Zeitpunkt: VBScript Array, MsgBox, InStr. Hintergrund – VBScript If Else &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbscript-if-else/">VBScript If Else</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else.png"><img decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-1024x536.png" alt="" class="wp-image-4219" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>VBScript If Else</figcaption></figure>






<h2 class="wp-block-heading">VBScript If Else</h2>



<p>Du <strong>möchtest </strong>mit <strong>VBScript If Else</strong> &#8211;<strong>Anweisungen Entscheidungen</strong>, bzw. <strong>Verzweigungen </strong>in deinem Code <strong>realisieren</strong>?</p>



<p>Kein Problem, <strong>lerne </strong>in diesem Beitrag <strong>wie </strong>Du das &#8222;<strong>If Then Else</strong>&#8222;-Konstrukt richtig <strong>anwendest</strong>.</p>



<p><strong>Vielleicht </strong>interessieren Dich auch <strong>andere Beiträge </strong>zu einem späteren Zeitpunkt: <strong><a href="/blog/vbscript-array" target="_blank" rel="noreferrer noopener">VBScript Array</a></strong>, <strong><a href="/blog/vbscript-msgbox" target="_blank" rel="noreferrer noopener">MsgBox</a></strong>, <strong><a href="/blog/vbscript-instr" target="_blank" rel="noreferrer noopener">InStr</a></strong>.</p>



<h2 class="wp-block-heading">Hintergrund – VBScript If Else</h2>



<p><strong>Entscheidungen </strong>– ein grundlegender Baustein allen <strong>Lebens</strong>, mal <strong>Gute</strong>, mal <strong>Schlechte</strong>, manchmal <strong>instinktiv </strong>und manchmal <strong>rational</strong>.</p>



<p>Sie <strong>bestimmen </strong>unseren <strong>Alltag </strong>als Menschen, als Individuen und <strong>ziehen Folgeentscheidungen nach </strong>sich.</p>



<p>So ist es <strong>auch in </strong>der Welt der <strong>Programmierung</strong>, denn auch dort <strong>müssen </strong>ständig <strong>Entscheidungen getroffen </strong>werden.</p>



<h2 class="wp-block-heading">Verzweigungen </h2>



<p><strong>Entscheidungen </strong>werden in der Programmierung häufig <strong>als Verzweigungen</strong>, oder auch als <strong>Selektion </strong>bezeichnet.</p>



<p>Denn <strong>anhand gewisser </strong>von uns festgelegter <strong>Kriterien</strong>, kann der Programm-Code sich in <strong>verschiedene Wege unterteilen </strong>und Folge-Code ausgeführt werden.</p>



<p>Die <strong>If-Else Verzweigung</strong> <strong>unterscheidet </strong>sich z. B. <strong>von </strong>der bekannten <strong>Mehrfachselektion </strong>&#8222;Select Case&#8220; (in anderen Sprachen auch Switch genannt).</p>



<h3 class="wp-block-heading">Simple Verzweigung – VBScript If Else</h3>



<p><strong>Bei </strong>einer eher <strong>simpleren Verzweigung </strong>haben wir <strong>einen</strong>, <strong>oder mehrere </strong>Ausgangspunkte <strong>verschiedener Abfragemöglichkeiten</strong>.</p>



<p>Ich <strong>kann </strong>zum Beispiel <strong>abfragen</strong>, <strong>ob </strong>gerade die <strong>Sonne scheint</strong>, <strong>ob </strong>dabei <strong>Wolken vorbeiziehen </strong>und <strong>ob </strong>es <strong>regnet</strong>.</p>



<p><strong>Eventuell </strong>kann ich <strong>auf </strong>eine <strong>Kombination </strong>dieser Fälle auch noch <strong>anders reagieren</strong>, <strong>wenn </strong>ein <strong>weiterer Punkt </strong>wie eine <strong>Bewässerungsautomatik </strong>hinzukommt.</p>



<p>Wie <strong>wir sehen</strong>, sind das alles <strong>eventuell </strong>völlig voneinander <strong>unabhängige </strong>Beispiele, Welche wir <strong>kombinieren </strong>und <strong>abfragen </strong>können.</p>



<h3 class="wp-block-heading">Mehrfachselektion</h3>



<p><strong>Bei </strong>der <strong>Mehrfachselektion </strong>sieht es anders aus, dort ist <strong>eigentlich immer </strong>die <strong>Rede von </strong>einem <strong>einzelnen Ausgangspunkt</strong>.</p>



<p>Das <strong>heißt</strong>, wir <strong>überprüfen </strong>einen <strong>Wert </strong>und <strong>schauen welcher </strong>einzelne <strong>Fall </strong>dazu <strong>passt</strong>, mit dem wir dann <strong>passend reagieren</strong>.</p>



<p><strong>Einige Sprachen bieten </strong>hierbei auch die <strong>Möglichkeit </strong>gewisse &#8222;<strong>Ranges</strong>&#8220; <strong>abzuarbeiten</strong>, <strong>statt </strong>nur <strong>einzelne Werte </strong>zu erlauben.</p>



<p>So <strong>könnte man </strong>ein <strong>Symbol </strong>anhand der <strong>Lautstärke </strong>des PCs so gestalten, dass es <strong>sich der Lautstärke</strong> in <strong>gewissen Bereichen anpasst</strong>, oder wenn es die <strong>Bereiche überschreitet</strong>.</p>



<p>Die <strong>Mehrfachselektion </strong>werden wir zu einem <strong>späteren Zeitpunkt</strong>, also vermutlich in einem <strong>separaten Beitrag bearbeiten</strong>.</p>



<h2 class="wp-block-heading">Eine Abfrage – VBScript If Else</h2>



<p><strong>An dieser Stelle </strong>nutze ich die Gelegenheit, dir ein <strong>kurzes </strong>und simples <strong>Beispiel </strong>einer <strong>VBScript If Else</strong> Abfrage zu <strong>zeigen</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Dim firstName
firstName = "Robert"

If firstName = "John" Then
    MsgBox("Oh, your name is John?")
End If

If firstName = "Robert" Then
    MsgBox("Oh, maybe you are RobbelRoot?")
End If</pre>



<p><strong>Hier legen </strong>wir eine <strong>Variable </strong>namens &#8222;firstName&#8220; <strong>fest</strong>, Welche wir <strong>anschließend mit </strong>dem <strong>Wert </strong>&#8222;Robert&#8220; <strong>versehen</strong>.</p>



<p><strong>Dann starten </strong>wir eine erste <strong>Abfrage</strong>, in der wir <strong>prüfen</strong>, <strong>ob </strong>der <strong>Name </strong>&#8222;<strong>John</strong>&#8220; in der Variable steht.</p>



<p><strong>Da John nicht </strong>in der Variable <strong>steht</strong>, <strong>wird </strong>die erste MsgBox <strong>nicht ausgegeben</strong>.</p>



<p>Die <strong>zweite Abfrage wird </strong>eine MsgBox <strong>ausgeben</strong>, <strong>da </strong>der gesuchte <strong>Name </strong>&#8222;Robert&#8220; in der Variable <strong>steht</strong>.</p>



<p>Du <strong>kannst </strong>den <strong>Namen </strong>testweise gerne einmal <strong>auf </strong>z. B. &#8222;<strong>Bob</strong>&#8220; ändern, <strong>dann </strong>würde <strong>nichts ausgegeben </strong>werden.</p>



<p><strong>Oder verwende </strong>stattdessen doch einmal &#8222;<strong>John</strong>&#8222;, um die <strong>erste Meldung </strong>zu <strong>sehen</strong>.</p>



<h2 class="wp-block-heading">Der Else-Part – VBScript If Else</h2>



<p><strong>Kommen </strong>wir nun zum <strong>Teil</strong>, <strong>wo </strong>wir das erste Mal das &#8222;<strong>Else</strong>&#8222;-Schlüsselwort <strong>verwenden</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Dim age
age = 16
If age >= 18 Then
    MsgBox("Ok, old enough!")
Else
    MsgBox("Sorry, you're too young :(!")
End If</pre>



<p>Du siehst hier eine <strong>kleine Altersprüfung</strong>, wo wir eine <strong>Variable namens </strong>&#8222;<strong>age</strong>&#8220; deklarieren.</p>



<p><strong>Danach weisen </strong>wir dem &#8222;age&#8220; die <strong>Zahl 16 zu</strong> und <strong>führen </strong>anschließend eine kleine <strong>Überprüfung </strong>durch.</p>



<p><strong>Wenn </strong>das <strong>Alter größer gleich 18</strong>, die Person also volljährig ist, <strong>geben </strong>wir eine kleine <strong>Erfolgsmeldung aus</strong>.</p>



<p>In <strong>jedem anderen Fall </strong>allerdings, bekommt die Person eine <strong>Meldung</strong>, <strong>dass </strong>Sie noch <strong>zu jung </strong>ist.</p>



<h3 class="wp-block-heading">Visuelle Darstellung</h3>



<p>Hier siehst Du die <strong>visuelle Darstellung </strong>analog zu einem <strong>Programmablaufplan</strong>:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung.png"><img loading="lazy" decoding="async" width="569" height="400" src="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung.png" alt="VBScript If Else Beispiel Altersprüfung" class="wp-image-4233" title="VBScript If Else Beispiel Altersprüfung" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung.png 569w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-300x211.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-332x233.png 332w" sizes="auto, (max-width: 569px) 100vw, 569px" /></a><figcaption>VBScript If Else Beispiel Altersprüfung</figcaption></figure>



<p>Dort <strong>sehen wir </strong>den einen <strong>Ausgangspunkt</strong>, wo sich entschieden wird, <strong>ob </strong>die <strong>Person </strong>nun <strong>volljährig </strong>ist (Weg nach <strong>unten</strong>), oder nicht (Weg nach <strong>rechts</strong>).</p>



<h2 class="wp-block-heading">Andernfalls wenn? ElseIf</h2>



<p>Nun kommen wir zu dem <strong>letzten kleinen Part</strong>, wo ich mir ein <strong>Szenario </strong>überlegt habe, dass die Person <strong>einen </strong>&#8222;<strong>Muttizettel</strong>&#8220; hat.</p>



<p><strong>Dadurch </strong>würde Sie also eine <strong>explizite Erlaubnis </strong>ihrer Eltern bekommen <strong>und </strong>mit dem <strong>Alter 16 und 17 </strong>trotzdem <strong>hineinkommen</strong>.</p>



<p><strong>Mit ElseIf </strong>kann man <strong>beliebig </strong>viele weitere <strong>Abfragen </strong>in die Verzweigung <strong>einbauen</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Dim age
age = 16
Dim hasMumPaper
hasMumPaper = True
If age >= 18 Then
    MsgBox("Ok, old enough!")
ElseIf age >= 16 And age &lt;= 17 And hasMumPaper Then
    MsgBox("Ok, you're too young, but your mum allowed, nice :)!")
Else
    MsgBox("Sorry, you're too young :(!")
End If</pre>



<h3 class="wp-block-heading">Visuelle Darstellung</h3>



<p>Das <strong>Beispiel mit </strong>dem <strong>Muttizettel </strong>siehst Du <strong>hier </strong>als <strong>visuelle </strong>Darstellung:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel.png"><img loading="lazy" decoding="async" width="904" height="629" src="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel.png" alt="VBScript If Else Beispiel Altersprüfung mit Muttizettel" class="wp-image-4238" title="VBScript If Else Beispiel Altersprüfung mit Muttizettel" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel.png 904w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel-300x209.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel-768x534.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel-700x487.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/VBScript-If-Else-Beispiel-Alterspruefung-mit-Muttizettel-332x231.png 332w" sizes="auto, (max-width: 904px) 100vw, 904px" /></a><figcaption>VBScript If Else Beispiel Altersprüfung mit Muttizettel</figcaption></figure>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbscript-if-else/">VBScript If Else</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/vbscript-if-else/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>VB.NET AndAlso</title>
		<link>https://robbelroot.de/blog/vbnet-andalso/</link>
					<comments>https://robbelroot.de/blog/vbnet-andalso/#respond</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Mon, 12 Jul 2021 00:17:55 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic .NET]]></category>
		<category><![CDATA[Visual Basic .NET Problemlösungen]]></category>
		<category><![CDATA[abfrage]]></category>
		<category><![CDATA[abfragen]]></category>
		<category><![CDATA[also]]></category>
		<category><![CDATA[and]]></category>
		<category><![CDATA[andalso]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[combine]]></category>
		<category><![CDATA[false]]></category>
		<category><![CDATA[geschwindigkeit]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[logical]]></category>
		<category><![CDATA[logisch]]></category>
		<category><![CDATA[logisches]]></category>
		<category><![CDATA[optimierung]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ressourcen]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[true]]></category>
		<category><![CDATA[und]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[vbnet]]></category>
		<category><![CDATA[verknüpfen]]></category>
		<category><![CDATA[verunden]]></category>
		<category><![CDATA[zeit]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=3587</guid>

					<description><![CDATA[<p>VB.NET AndAlso Du möchtest mehr über den VB.NET AndAlso Operator lernen und verstehen wie Er funktioniert? In diesem Beitrag zeige ich Dir einige Bespiele des VB.NET AndAlso Operators und erkläre Dir die Vorteile wie z. B. die Performance bezogenen Aspekte. Vielleicht interessieren Dich z. B. auch noch folgende Beiträge: Application &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbnet-andalso/">VB.NET AndAlso</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso.png"><img loading="lazy" decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-1024x536.png" alt="VB.NET AndAlso" class="wp-image-3590" title="VB.NET AndAlso" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso.png 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption>VB.NET AndAlso</figcaption></figure>






<h2 class="wp-block-heading">VB.NET AndAlso</h2>



<p>Du möchtest <strong>mehr über </strong>den <strong>VB.NET AndAlso</strong> Operator <strong>lernen und verstehen </strong>wie Er funktioniert?</p>



<p>In <strong>diesem Beitrag </strong>zeige ich Dir <strong>einige Bespiele </strong>des <strong>VB.NET AndAlso</strong> Operators und <strong>erkläre Dir </strong>die <strong>Vorteile </strong>wie z. B. die <strong>Performance </strong>bezogenen Aspekte.</p>



<p><strong>Vielleicht </strong>interessieren Dich z. B. auch noch <strong>folgende Beiträge</strong>: <strong><a href="/blog/vbnet-application-path" target="_blank" rel="noreferrer noopener">Application Path</a></strong>, <strong><a href="/blog/vbnet-pdf-oeffnen" target="_blank" rel="noreferrer noopener">PDF Öffnen</a></strong>, oder <strong><a href="/blog/vbnet-button-click-ausloesen" target="_blank" rel="noreferrer noopener">Button Click auslösen</a></strong>.</p>



<h2 class="wp-block-heading">Vorarbeit – Wetter-Sensor</h2>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen.png"><img loading="lazy" decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-1024x536.png" alt="Wetter-Sensor Sonne Regen" class="wp-image-3600" title="Wetter-Sensor Sonne Regen" srcset="https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/07/Wetter-Sensor-Sonne-Regen.png 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption>Wetter-Sensor Sonne Regen</figcaption></figure>



<p><strong>Um </strong>das VB.NET AndAlso <strong>Beispiel klarer </strong>zu gestalten, leisten wir ein <strong>wenig Vorarbeit</strong>, indem wir eine kleine <strong>WetterSensor-Klasse</strong> bauen.</p>



<p><strong>Keine Sorge</strong>, dabei wir es sich um relativ <strong>stupide Daten ohne </strong>jegliche Anbindung einer <strong>API </strong>handeln.</p>



<p>Die Sensor-Klasse dient<strong> </strong>letztendlich nur der <strong>einfacheren Visualisierung und </strong>dem <strong>Verständnis </strong>hinter den Kulissen.</p>



<h3 class="wp-block-heading" id="wetter-sensor-klasse-achtung">Achtung – Textbox-Referenz</h3>



<p>Ich <strong>verwende </strong>hier <strong>beabsichtigt </strong>eine <strong>Referenz </strong>zur <strong>Log-Textbox</strong>, <strong>normalerweise </strong>sollte man dies <strong>nicht </strong>tun.</p>



<p><strong>Mein Ziel </strong>ist es aber, das Beispiel so <strong>einfach wie möglich </strong>zu halten <strong>und </strong>Dir irgendwelche <strong>Handler </strong>zu <strong>ersparen</strong>.</p>



<p>Die Sensor-<strong>Klasse soll </strong>also beabsichtigt <strong>direkt in </strong>die <strong>Textbox loggen </strong>und somit eine <strong>direkte Abhängigkeit </strong>zu Ihr besitzen.</p>



<h3 class="wp-block-heading">WeatherSensor-Klasse</h3>



<p>An diesem Punkt <strong>stelle </strong>ich <strong>kurz </strong>die <strong>WeatherSensor</strong>&#8211;<strong>Klasse </strong>vor:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Public Class WeatherSensor

    Public Property TbLog As TextBox

    Sub New(tbLog As TextBox)
        Me.TbLog = tbLog
    End Sub

    Public Async Function IsSunny() As Task(Of Boolean)
        Log($"{NameOf(IsSunny)}()")
        Await ConnectToSensor()
        Await DisconnectFromSensor()
        Return False
    End Function

    Public Async Function IsRaining() As Task(Of Boolean)
        Log($"{NameOf(IsRaining)}()")
        Await ConnectToSensor()
        Await DisconnectFromSensor()
        Return True
    End Function

    Private Async Function ConnectToSensor() As Task
        Log($"{NameOf(ConnectToSensor)}()")
        Await Task.Delay(1000)
        Log("Connected to sensor")
        Log("------")
    End Function

    Private Async Function DisconnectFromSensor() As Task
        Log($"{NameOf(DisconnectFromSensor)}()")
        Await Task.Delay(1000)
        Log("Disconnected from sensor")
        Log("------")
    End Function

    Private Sub Log(txt As String)
        TbLog.AppendText($"[{Now:HH:mm:ss}] {txt}{Environment.NewLine}")
    End Sub

End Class</pre>



<h4 class="wp-block-heading">Eigenschaften</h4>



<h5 class="wp-block-heading">TbLog</h5>



<p><strong>Hier speichern </strong>wir die <strong>Referenz</strong>, <strong>um </strong>direkt aus der Klasse <strong>loggen </strong>zu können (bitte <strong><a href="#wetter-sensor-klasse-achtung">Hinweise</a></strong> beachten).</p>



<h4 class="wp-block-heading">Konstruktoren</h4>



<h5 class="wp-block-heading">new(TextBox)</h5>



<p>Der <strong>erste </strong>und <strong>einzige Konstruktor </strong>der Klasse <strong>benötigt </strong>die <strong>Referenz </strong>zur <strong>Log</strong>-Textbox.</p>



<h4 class="wp-block-heading">Methoden</h4>



<h5 class="wp-block-heading">IsSunny</h5>



<p>Eine <strong>Funktion </strong>um festzustellen, <strong>ob </strong>es aktuell <strong>sonnig </strong>ist.</p>



<p>Im <strong>Hintergrund </strong>müssen wir uns natürlich – simuliert – zum Sensor <strong>verbinden</strong>, etc.</p>



<h5 class="wp-block-heading">IsRaining</h5>



<p>Mit dieser Funktion stellen wir fest, <strong>ob es </strong>aktuell <strong>regnet </strong>(die <strong>Intensität spielt </strong>hier <strong>keine Rolle</strong>).</p>



<p><strong>Auch hier </strong>muss im <strong>Hintergrund </strong>natürlich eine &#8222;<strong>Verbindung </strong>hergestellt&#8220; werden.</p>



<h5 class="wp-block-heading">ConnectToSensor</h5>



<p><strong>Simuliert </strong>eine <strong>Verbindung </strong>zum Sensor aufzubauen.</p>



<h5 class="wp-block-heading">DisconnectFromSensor</h5>



<p><strong>Tut so</strong>, als ob die Instanz sich <strong>vom Sensor trennen </strong>würde.</p>



<h5 class="wp-block-heading">Log(String)</h5>



<p>Eine <strong>Hilfsfunktion um </strong>Daten direkt in die Textbox <strong>zu loggen </strong>(bitte auch hier <strong><a href="#wetter-sensor-klasse-achtung">Hinweise</a></strong> beachten!).</p>



<h2 class="wp-block-heading">Grafische Oberfläche</h2>



<p>Für unser &#8222;<strong>VB.NET AndAlso</strong>&#8222;-Beispiel kannst Du Dir am besten die <strong>folgende</strong>, <strong>oder </strong>eine <strong>ähnliche Oberfläche </strong>zusammenklicken:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-GUI.png"><img loading="lazy" decoding="async" width="521" height="545" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-GUI.png" alt="VB.NET AndAlso GUI" class="wp-image-3613" title="VB.NET AndAlso GUI" srcset="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-GUI.png 521w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-GUI-287x300.png 287w, https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-GUI-332x347.png 332w" sizes="auto, (max-width: 521px) 100vw, 521px" /></a><figcaption>VB.NET AndAlso GUI</figcaption></figure>



<h3 class="wp-block-heading">VB.NET And – der linke Button</h3>



<p><strong>Zuerst </strong>einmal schauen wir uns an, wie man <strong>das normale &#8222;<a href="https://docs.microsoft.com/de-de/dotnet/visual-basic/language-reference/operators/and-operator" target="_blank" rel="noreferrer noopener">And</a></strong>&#8222;, also den normalen And-Operator verwendet.</p>



<p><strong>Wie </strong>schon <strong>angepriesen verwenden </strong>wir dafür die erstellte WetterSensor-<strong>Klasse</strong>, um eine <strong>sinnvoll</strong> gestützte Basis zu haben.</p>



<p><strong>Doppelklicke </strong>den <strong>linken Button und </strong>füge den folgenden <strong>Code </strong>ein (<strong>vergiss nicht </strong>die Sub als <strong>Async </strong>zu deklarieren):</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    Private Async Sub btnCheckWeatherByAnd_Click(sender As Object, e As EventArgs) Handles btnCheckWeatherByAnd.Click
        tbLog.Clear()
        Dim isNiceWeather = Await WeatherSensor.IsSunny() And Await WeatherSensor.IsRaining()
        ' do something
    End Sub</pre>



<p>Im <strong>ersten Schritt löschen </strong>wir den aktuellen <strong>Inhalt </strong>des <strong>Logs</strong>, <strong>damit </strong>wir <strong>bei jedem Durchgang </strong>einen <strong>sauberen Start </strong>haben.</p>



<p><strong>Dann legen </strong>wir eine <strong>Variable </strong>fest, <strong>worin </strong>wir das <strong>boolesche Ergebnis </strong>des einfachen &#8222;And&#8220;-Operators speichern.</p>



<p><strong>Letztendlich </strong>ist für uns hier nur das <strong>Ergebnis im Log relevant</strong>, um zu überprüfen, <strong>was</strong>, <strong>wie </strong>und <strong>wann passiert </strong>ist.</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-And-Wetter-Sensor-Log-Ausgabe.png"><img loading="lazy" decoding="async" width="246" height="220" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-And-Wetter-Sensor-Log-Ausgabe.png" alt="VB.NET And Wetter-Sensor Log Ausgabe" class="wp-image-3622" title="VB.NET And Wetter-Sensor Log Ausgabe"/></a><figcaption>VB.NET And Wetter-Sensor Log Ausgabe</figcaption></figure>



<p>Wir <strong>können </strong>im Log <strong>beobachten</strong>, <strong>dass beide Funktionen </strong>(IsSunny und IsRaining) <strong>unabhängig </strong>vom ersten Ergebnis <strong>aufgerufen </strong>werden.</p>



<p><strong>Bei </strong>einer &#8222;<strong>Verundung</strong>&#8220; müssen <strong>alle Bestandteile True </strong>ergeben, <strong>damit </strong>letztendlich das <strong>Ergebnis </strong>den Wert <strong>True </strong>erhält.</p>



<p><strong>Trotz </strong>des &#8222;<strong>False</strong>&#8222;-Wertes, also <strong>trotz </strong>des <strong>Ausschlusses</strong>, <strong>dass </strong>der <strong>erste Wert </strong>überhaupt True sein kann, <strong>wird </strong>die <strong>zweite Funktion </strong>&#8222;IsRaining&#8220; <strong>aufgerufen</strong>!</p>



<p><strong>Das dies </strong>natürlich <strong>absolut sinnlos </strong>ist, liegt auf der Hand, doch <strong>wie verhindern </strong>wir das?</p>



<p><strong>Nicht nur </strong>die <strong>sinnlosen Verbindungsversuche </strong>der Klasse zum Sensor <strong>stoßen </strong>hier <strong>übel auf</strong>.</p>



<p><strong>Ebenso </strong>stören auch die dabei <strong>verschwendeten Ressourcen</strong> und die <strong>sinnlose</strong> <strong>Warterei</strong>.</p>



<h3 class="wp-block-heading">VB.NET AndAlso – der rechte Button</h3>



<p>Schauen wir uns <strong>als nächstes </strong>die <strong>Vorgehensweise </strong>im <strong>rechten Button </strong>an:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    Private Async Sub btnCheckWeatherByAndAlso_Click(sender As Object, e As EventArgs) Handles btnCheckWeatherByAndAlso.Click
        tbLog.Clear()
        Dim isNiceWeather = Await WeatherSensor.IsSunny() AndAlso Await WeatherSensor.IsRaining()
    End Sub</pre>



<p>Dir wird <strong>vermutlich </strong>schnell <strong>auffallen</strong>, <strong>dass </strong>der Code im <strong>Handler </strong>des zweiten Buttons nur <strong>ein anderes Wort </strong>enthält.</p>



<p><strong>Statt </strong>des &#8222;<strong>And</strong>&#8222;-Operators <strong>verwenden </strong>wir hier den &#8222;<strong>AndAlso</strong>&#8222;-Operator und <strong>verändern </strong>somit die <strong>Verhaltensweise</strong>.</p>



<p>Werfen wir <strong>nun </strong>das <strong>zweite Mal </strong>einen <strong>Blick auf </strong>das <strong>Log</strong>:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-Wetter-Sensor-Log-Ausgabe.png"><img loading="lazy" decoding="async" width="246" height="130" src="https://robbelroot.de/wp-content/uploads/2021/07/VB.NET-AndAlso-Wetter-Sensor-Log-Ausgabe.png" alt="VB.NET AndAlso Wetter-Sensor Log Ausgabe" class="wp-image-3631" title="VB.NET AndAlso Wetter-Sensor Log Ausgabe"/></a><figcaption>VB.NET AndAlso Wetter-Sensor Log Ausgabe</figcaption></figure>



<p>Nun <strong>können </strong>wir mit glücklicher Miene <strong>feststellen</strong>, <strong>dass nur </strong>die &#8222;<strong>IsSunny</strong>&#8222;-<strong>Funktion aufgerufen </strong>wird und die &#8222;IsRaining&#8220;-Funktion außen vor bleibt.</p>



<p>Somit <strong>finden keine unnötigen Verbindungsversuche </strong>und auch <strong>keine Verschwendung </strong>von Ressourcen <strong>statt</strong>, SUPER!</p>



<h2 class="wp-block-heading">Kompletter Code – VB.NET AndAlso</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="visualbasic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Public Class Form1

    Private ReadOnly WeatherSensor As WeatherSensor

    Sub New()
        InitializeComponent()
        WeatherSensor = New WeatherSensor(tbLog)
    End Sub

    Private Sub btnClearLog_Click(sender As Object, e As EventArgs) Handles btnClearLog.Click
        tbLog.Clear()
    End Sub

    Private Async Sub btnCheckWeatherByAnd_Click(sender As Object, e As EventArgs) Handles btnCheckWeatherByAnd.Click
        tbLog.Clear()
        Dim isNiceWeather = Await WeatherSensor.IsSunny() And Await WeatherSensor.IsRaining()
    End Sub

    Private Async Sub btnCheckWeatherByAndAlso_Click(sender As Object, e As EventArgs) Handles btnCheckWeatherByAndAlso.Click
        tbLog.Clear()
        Dim isNiceWeather = Await WeatherSensor.IsSunny() AndAlso Await WeatherSensor.IsRaining()
    End Sub

End Class

Public Class WeatherSensor

    Public Property TbLog As TextBox

    Sub New(tbLog As TextBox)
        Me.TbLog = tbLog
    End Sub

    Public Async Function IsSunny() As Task(Of Boolean)
        Log($"{NameOf(IsSunny)}()")
        Await ConnectToSensor()
        Await DisconnectFromSensor()
        Return False
    End Function

    Public Async Function IsRaining() As Task(Of Boolean)
        Log($"{NameOf(IsRaining)}()")
        Await ConnectToSensor()
        Await DisconnectFromSensor()
        Return True
    End Function

    Private Async Function ConnectToSensor() As Task
        Log($"{NameOf(ConnectToSensor)}()")
        Await Task.Delay(1000)
        Log("Connected to sensor")
        Log("------")
    End Function

    Private Async Function DisconnectFromSensor() As Task
        Log($"{NameOf(DisconnectFromSensor)}()")
        Await Task.Delay(1000)
        Log("Disconnected from sensor")
        Log("------")
    End Function

    Private Sub Log(txt As String)
        TbLog.AppendText($"[{Now:HH:mm:ss}] {txt}{Environment.NewLine}")
    End Sub

End Class</pre>



<h2 class="wp-block-heading">Downloads</h2>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link" href="/downloads/vbnet/AndAlsoExample.zip" target="_blank" rel="noreferrer noopener">AndAlsoExample.zip</a></div>
</div>
<p>Der Beitrag <a href="https://robbelroot.de/blog/vbnet-andalso/">VB.NET AndAlso</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/vbnet-andalso/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Bilder vergleich mit If</title>
		<link>https://robbelroot.de/blog/bilder-vergleich-mit-if/</link>
					<comments>https://robbelroot.de/blog/bilder-vergleich-mit-if/#respond</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Sun, 07 Feb 2016 19:55:20 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic .NET]]></category>
		<category><![CDATA[Visual Basic .NET Problemlösungen]]></category>
		<category><![CDATA[bilder]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbnet]]></category>
		<category><![CDATA[vergleich]]></category>
		<category><![CDATA[visual basic]]></category>
		<guid isPermaLink="false">http://robbelroot.de/?p=864</guid>

					<description><![CDATA[<p>Auf YouTube ansehen Code Download</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/bilder-vergleich-mit-if/">Bilder vergleich mit If</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" async=""></script><!-- robbelroot.de pre content --><ins class="adsbygoogle" style="display: inline-block; width: 468px; height: 60px;" data-ad-client="ca-pub-3635281460831831" data-ad-slot="4378945418"></ins><script>// <![CDATA[
(adsbygoogle = window.adsbygoogle || []).push({});
// ]]&gt;</script></p>
<p style="margin-bottom:0;">
<a class="fasc-button fasc-size-medium fasc-type-glossy fasc-rounded-medium fasc-ico-before dashicons-format-video" style="background-color: #ff0000; color: #ffffff;" href="https://www.youtube.com/watch?v=OMqMl2Qlbd8" target="_blank" data-fasc-style="background-color:#ff0000;color:#ffffff;">Auf YouTube ansehen</a> <a class="fasc-button fasc-size-medium fasc-type-glossy fasc-rounded-medium fasc-ico-before dashicons-download" style="background-color: #339e48; color: #ffffff;" href="https://adf.ly/rwahx" target="_blank" data-fasc-style="background-color:#339e48;color:#ffffff;">Code Download</a>
</p>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/OMqMl2Qlbd8" frameborder="0" allowfullscreen></iframe></p>
<p><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" async=""></script><!-- robbelroot.de pre content --><ins class="adsbygoogle" style="display: inline-block; width: 468px; height: 60px;" data-ad-client="ca-pub-3635281460831831" data-ad-slot="4378945418"></ins><script>// <![CDATA[
(adsbygoogle = window.adsbygoogle || []).push({});
// ]]&gt;</script></p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/bilder-vergleich-mit-if/">Bilder vergleich mit If</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/bilder-vergleich-mit-if/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
