Array length: Difference between revisions

Content added Content deleted
imported>J7M
(add example for SmallBASIC)
(Added XBasic)
Line 605: Line 605:


==={{header|True BASIC}}===
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">
<syntaxhighlight lang="qbasic">DIM fruta$(2)
DIM fruta$(2)
READ fruta$(1), fruta$(2)
READ fruta$(1), fruta$(2)
DATA "apple", "orange"
DATA "apple", "orange"
Line 613: Line 612:


PRINT "La longitud del array fruta$ es" ; tamano
PRINT "La longitud del array fruta$ es" ; tamano
END</syntaxhighlight>
END
</syntaxhighlight>

{{out}}
{{out}}
<pre> La longitud del array fruta$ es 2 </pre>
<pre> La longitud del array fruta$ es 2 </pre>
Line 622: Line 619:
True BASIC's arrays are not fixed in length and, although True BASIC is a compiled-language, the number of elements can be changed during runtime using such functions as the MAT REDIM (matrix re-dimension) function. Although the starting index of 1 is in implicit, it can be changed by setting the lower and upper bounds (eg. fruit(0 to 3)) when declaring the array. Also, the example below uses the MAT READ function to read in the data elements into the array without having to explicitly list each variable-array index. The example also uses the SIZE function vs the bounds method to determine the length of the array. Finally, in this example the SIZE function was not assigned to a separate variable and instead is used within the PRINT function itself.
True BASIC's arrays are not fixed in length and, although True BASIC is a compiled-language, the number of elements can be changed during runtime using such functions as the MAT REDIM (matrix re-dimension) function. Although the starting index of 1 is in implicit, it can be changed by setting the lower and upper bounds (eg. fruit(0 to 3)) when declaring the array. Also, the example below uses the MAT READ function to read in the data elements into the array without having to explicitly list each variable-array index. The example also uses the SIZE function vs the bounds method to determine the length of the array. Finally, in this example the SIZE function was not assigned to a separate variable and instead is used within the PRINT function itself.


<syntaxhighlight lang="qbasic">
<syntaxhighlight lang="qbasic">DIM fruit$(2)
DIM fruit$(2)
MAT READ fruit$
MAT READ fruit$
DATA "apple", "orange"
DATA "apple", "orange"


PRINT "The length of the array 'fruit$' is "; SIZE(fruit$)
PRINT "The length of the array 'fruit$' is "; SIZE(fruit$)
END</syntaxhighlight>
END
{{out}}
</syntaxhighlight>
<pre> The length of the array 'fruit$' is 2 </pre>


==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Array length"
VERSION "0.0000"


DECLARE FUNCTION Entry ()

FUNCTION Entry ()
DIM F$[2]
F$[0] = "apple"
F$[1] = "orange"
F$[2] = "pear"

PRINT "The length of the fruit array is "; UBOUND(F$[])
PRINT F$[1]
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
{{out}}
<pre> The length of the array 'fruit$' is 2 </pre>
<pre>The length of the fruit array is 2
orange</pre>


=={{header|Batch File}}==
=={{header|Batch File}}==