CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account

DIM

DIM var(dim) , [var(dim)]…
DIM var$(dim) LENGTH n

Specifies a variable that is an array with one or more dimensions. The variables can be numbers or strings with multiple declarations separated by commas.

‘dim’ is a bracketed list of numbers separated by commas. Each number specifies the number of elements in each dimension. Normally the numbering of each dimension starts at 0 but the OPTION BASE command can be used to change this to 1.

For example: DIM nbr(10, 20) specifies a two dimensional array with 11 elements (0 to 10) in the first dimension and 21 (0 to 20) in the second dimension. The total number of elements is 231 and because each number requires 4 bytes a total of 924 bytes of memory will be allocated.

String arrays will by default be allocated memory for 255 characters for each element and this can quickly use up memory. In that case the LENGTH keyword can be used to specify the amount of memory to be allocated to each element. This allocation (‘n’) can be from 1 to 255 characters.

For example: DIM str$(5, 10) will declare a string array with 66 elements consuming 16,896 bytes of memory while: DIM str$(5, 10) LENGTH 20 Will only consume 1,386 bytes of memory. Note that the amount of memory allocated for each element is n + 1 as the extra byte is used to track the actual length of the string stored in each element.


Examples:
DIM nbr(50)
DIM str$(20)
DIM a(5,5,5), b(1000)
DIM str$(200) LENGTH 20


1
2
3
4
5
6
7
8
10 Data 1, 2, 3, 4, 5, 6, 7, 8, 9
20 Dim var(9)
30 For loop = 1 To 9
40 Read var(loop)
50 Next loop
60 For loop = 1 To 9
70 Print var(loop)
80 Next loop


> run
1
2
3
4
5
6
7
8
9


If a string longer than ‘n’ is assigned to an element of the array an error will be produced. Other than this string arrays created with the LENGTH keyword act exactly the same as other string arrays.

See also:
CLEAR
DATA
ERASE
LET
OPTION BASE
READ
RESTORE

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2021 · Generate Pro Theme on Genesis Framework · WordPress · Log in