<?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>vb6 Archive - Robert Skibbe</title>
	<atom:link href="https://robbelroot.de/blog/tag/vb6/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>alias RobbelRoot – Freelance Full Stack Developer .NET</description>
	<lastBuildDate>Sat, 17 Jul 2021 07:37:20 +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>vb6 Archive - Robert Skibbe</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Array Length VB</title>
		<link>https://robbelroot.de/blog/array-length-vb/</link>
					<comments>https://robbelroot.de/blog/array-length-vb/#respond</comments>
		
		<dc:creator><![CDATA[Robert Skibbe]]></dc:creator>
		<pubDate>Sat, 17 Jul 2021 07:37:20 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Visual Basic Problemlösungen]]></category>
		<category><![CDATA[anzahl]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[datenfeld]]></category>
		<category><![CDATA[datenfelder]]></category>
		<category><![CDATA[durchlaufen]]></category>
		<category><![CDATA[elemente]]></category>
		<category><![CDATA[enumerieren]]></category>
		<category><![CDATA[feld]]></category>
		<category><![CDATA[felder]]></category>
		<category><![CDATA[größe]]></category>
		<category><![CDATA[kapazität]]></category>
		<category><![CDATA[länge]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[schleife]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vb5]]></category>
		<category><![CDATA[vb6]]></category>
		<category><![CDATA[visual]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[zählen]]></category>
		<guid isPermaLink="false">https://robbelroot.de/?p=4407</guid>

					<description><![CDATA[<p>Array length VB Du möchtest die Array Length in VB, also die Anzahl der Elemente, bzw. die Größe eines Arrays bestimmen? Die Größe des Arrays ist in vielen Situationen wie z. B. das Durchlaufen mit einer Schleife relevant, lerne in diesem Beitrag, wie Du die Größe herausfindest! Schaue Dir bei &#8230;</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/array-length-vb/">Array Length VB</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/Array-Length-VB.png"><img fetchpriority="high" decoding="async" width="1024" height="536" src="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-1024x536.png" alt="Array Length VB" class="wp-image-4409" title="Array Length VB" srcset="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-1024x536.png 1024w, https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-300x157.png 300w, https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-768x402.png 768w, https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-700x366.png 700w, https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-332x174.png 332w, https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Array Length VB</figcaption></figure>






<h2 class="wp-block-heading">Array length VB</h2>



<p>Du möchtest die <strong>Array Length in VB</strong>, also die <strong>Anzahl </strong>der <strong>Elemente</strong>, bzw. die <strong>Größe </strong>eines <strong>Arrays bestimmen</strong>?</p>



<p>Die <strong>Größe des Arrays</strong> ist in vielen Situationen wie z. B. das <strong>Durchlaufen </strong>mit einer <strong>Schleife relevant</strong>, lerne in diesem Beitrag, <strong>wie </strong>Du die <strong>Größe herausfindest</strong>!</p>



<p><strong>Schaue </strong>Dir <strong>bei Bedarf </strong>doch gerne auch einige <strong>andere </strong>meiner <strong>Visual Basic Beiträge</strong> an: (folgen noch).</p>



<h2 class="wp-block-heading">Was? Keine native Funktion?</h2>



<p>Du hast leider <strong>richtig gelesen</strong>, wir <strong>haben </strong>in VB <strong>keine </strong>&#8222;<strong>native</strong>&#8220; <strong>Möglichkeit</strong>, die Length des Arrays abzurufen.</p>



<p>Man <strong>kennt </strong>es eventuell <strong>aus </strong>dem .NET <strong>Umfeld</strong>, dass man <strong>einfach </strong>&#8222;.<strong>Length</strong>&#8222;, oder auch &#8222;.<strong>Count</strong>&#8220; aufrufen kann, <strong>hier </strong>haben wir <strong>allerdings </strong>mehr oder weniger <strong>Pech</strong>.</p>



<p>Daher müssen wir uns wohl oder übel eine <strong>eigene Variante </strong>bauen, um die <strong>Length </strong>des Arrays <strong>herauszufinden</strong>.</p>



<h2 class="wp-block-heading">Probleme – Array Length VB</h2>



<p><strong>Wer </strong>schon ein wenig <strong>mit Visual Basic</strong> <strong>gearbeitet </strong>hat, <strong>wird </strong>vermutlich die <a href="https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/lbound-function"><strong>LBound</strong></a> und <a href="https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/ubound-function"><strong>UBound</strong></a> Funktionen <strong>kennen</strong>.</p>



<p><strong>Leider gestaltet </strong>sich die zum vermeintlich zum Ziel führende <strong>Arbeit </strong>damit <strong>nicht ganz </strong>einfach.</p>



<p>Daher <strong>zeige </strong>ich Dir hier einmal, <strong>wie </strong>man eventuell in eine kleine <strong>Falle </strong>tappen <strong>könnte</strong>.</p>



<h2 class="wp-block-heading">Länge mit LBound und UBound erfassen</h2>



<p>In diesem <strong>Abschnitt </strong>erstellen wir ein kleines, mit den <strong>beiden Funktionen </strong>arbeitendes <strong>Beispiel</strong>, die <strong>Länge des Arrays </strong>zu <strong>erfassen</strong>.</p>



<p><strong>Schauen </strong>wir uns dafür einfach mal den <strong>folgenden Code </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="">Dim arr
arr = Array("First", "Second")
Dim arrLength
arrLength = UBound(arr) - LBound(arr) + 1
MsgBox(arrLength)</pre>



<h3 class="wp-block-heading">Code-Erklärung</h3>



<p>Im <strong>ersten Schritt </strong>kündige ich eine <strong>Variable </strong>namens &#8222;<strong>arr</strong>&#8220; an und setze im <strong>nächsten Schritt</strong> den <strong>Wert</strong>.</p>



<p>Danach <strong>deklariere </strong>ich eine <strong>Variable </strong>namens &#8222;<strong>arrLength</strong>&#8220; <strong>wo </strong>wir gleich – oh Wunder – die <strong>Length des Arrays </strong>speichern werden.</p>



<p>Die <strong>Length des Arrays berechnet </strong>sich in unserem Beispiel <strong>aus </strong>dem <strong>Rückgabewert </strong>der &#8222;<strong>UBound</strong>&#8222;-Funktion <strong>minus </strong>den <strong>Rückgabewert </strong>der &#8222;<strong>LBound</strong>&#8222;-Funktion <strong>plus 1</strong>.</p>



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



<p><strong>Wenn </strong>Du Dir dann die <strong>Ausgabe </strong>der <strong><a href="https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/msgbox-function" target="_blank" rel="noreferrer noopener">MsgBox</a></strong> ansiehst, wirst Du <strong>folgendes Fenster </strong>bekommen:</p>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-UBound-LBound-Beispiel.png"><img decoding="async" width="129" height="137" src="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-UBound-LBound-Beispiel.png" alt="Array Length VB UBound LBound Beispiel" class="wp-image-4418" title="Array Length VB UBound LBound Beispiel"/></a><figcaption>Array Length VB UBound LBound Beispiel</figcaption></figure>



<p>Nun <strong>scheint </strong>im ersten Moment <strong>alles richtig </strong>zu sein, <strong>jedoch nicht </strong>mehr, <strong>wenn </strong>Du Dir nun <strong>folgendes Beispiel </strong>ansiehst.</p>



<p><strong>Hier verläuft </strong>erstmal alles <strong>analog </strong>zum Beispiel <strong>hier drüber</strong>, <strong>allerdings erweitern </strong>wir die <strong>Kapazität </strong>des Arrays, <strong>ohne </strong>einen <strong>tatsächlichen Wert </strong>in den neuen Index zu stecken.</p>



<h3 class="wp-block-heading">Nicht ganz zufriedenstellend – Array Length VB</h3>



<p>Das <strong>Array </strong>hat <strong>nun </strong>also eine theoretische <strong>Kapazität von 3</strong> Elementen, <strong>jedoch </strong>sind <strong>nur 2 Elemente</strong> darin vorhanden.</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 arr
arr = Array("First", "Second")
ReDim Preserve arr(2)
Dim arrLength
arrLength = UBound(arr) - LBound(arr) + 1
MsgBox(arrLength)</pre>



<figure class="wp-block-image size-large"><a href="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-UBound-LBound-Beispiel-2.png"><img decoding="async" width="128" height="137" src="https://robbelroot.de/wp-content/uploads/2021/07/Array-Length-VB-UBound-LBound-Beispiel-2.png" alt="Array Length VB UBound LBound Beispiel 2" class="wp-image-4425" title="Array Length VB UBound LBound Beispiel 2"/></a><figcaption>Array Length VB UBound LBound Beispiel 2</figcaption></figure>



<h2 class="wp-block-heading">Die verbleibende Lösung</h2>



<p>Die <strong>einzig </strong>uns <strong>verbleibende Lösung</strong>, um die <strong>Array-Länge</strong> festzustellen ist es, das <strong>Array manuell </strong>zu <strong>durchlaufen und </strong>das jeweilige <strong>Element </strong>auf z. B. &#8222;IsEmpty&#8220; zu <strong>prüfen</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 arr
arr = Array("First", "Second")
ReDim Preserve arr(2)
Dim arrLength
For i = LBound(arr) To UBound(arr)
    If Not IsEmpty(arr(i)) Then
        arrLength = arrLength + 1
    End If
Next
MsgBox(arrLength)</pre>



<p>Somit <strong>bekommen</strong> wir auch in diesem letzten Beispiel, die <strong>korrekte Zahl</strong>, bzw. <strong>Länge 2 </strong>heraus.</p>



<p>Je <strong>nach Wunsch und Datentyp könnte </strong>man die <strong>Überprüfen </strong>natürlich noch <strong>anpassen</strong>, bzw. erweitern.</p>
<p>Der Beitrag <a href="https://robbelroot.de/blog/array-length-vb/">Array Length VB</a> erschien zuerst auf <a href="https://robbelroot.de">Robert Skibbe</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://robbelroot.de/blog/array-length-vb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
