Dim

In Microsoft Visual Basic, the Dim keyword is used to declare a local variable. It allocates enough space in the computer's memory for data of a specific type. In Visual Basic, these types are Integer, Long, Double, Boolean, Currency, Date, String, Byte, Object, or Variant. A variable declared using the Dim keyword lasts only as long as a particular sub or function lasts.

The syntax is: Dim varName As varType

The statement might be used in a program such as this:

Private Sub cmdVariables_Click()
     Dim intResult As Integer
     
     intResult = 5
     lblResult.Caption = intResult
End Sub

An alternative to using As is to use a Type Suffix to declare the type of your variable. These type suffixes are:

_____________________________
|Variable Type |  Suffix     |
|Integer       |  %          |
|Double        |  #          |
|String        |  $          |
|Long          |  &          |
|Single        |  !          |
|Currency      |  @          |
______________________________
The other variable types don't have one, and you must use As.


If you want another type of variable (such as a global variable), you can use Private, Public, or Const (for a constant).

In BASIC (the real thing, back in the days when programmers were pimply-faced youths with no life, LOWERCASE WAS A LUXURY, and CPUs were 8 bit), the keyword DIM actually made sense.

You used it to DIMension an array.

Saying

1000 DIM A(100)
would declare an array A of 101 elements. (Well, SOMEBODY wanted to accommodate both OPTION BASE 0-ers and $[=1-ers, so the array's elements were A(0),...,A(100)).

On some BASICs, saying just DIM B would DIMension B with 11 elements. Multiple dimensions were (usually) supported, by saying DIM C(3,4,5). Not that anyone had the memory for large multidimensional arrays, but then, back then they hadn't even invented the third dimension... Types were supported using the same postfixed sigils as for plain variables; an array of 111 (well, 112) strings was DIM S$(111), and (on BBC BASIC) an array of 16 integers was DIM I%(15).

Arrays weren't originally local variables, of course. We kiddies who used BASIC didn't go in for software engineering. "Besides, local variables are meaningless in the presence of GOTOs!" Later BASICs (e.g. BBC BASIC) had locals, but I don't think arrays could be stuffed on the stack.

Special 10000 point bonus to anyone who can predict what

10 FOR I=10 TO 100
20 DIM A(I)
30 NEXT I

does!

How DIM reached its present sorry state I do not know. I assume you can still DIM X(100). I hope MS broke compatibility with MS BASIC, and that DIM Z no longer gives you an array of 11 elements.

DIM indeed. Like the future of software engineering in an industry dominated by the people who brought you BASICA.

Dim (?), a. [Compar. Dimmer (?); superl. Dimmest (?).] [AS. dim; akin to OFries. dim, Icel. dimmr: cf. MHG. timmer, timber; of uncertain origin.]

1.

Not bright or distinct; wanting luminousness or clearness; obscure in luster or sound; dusky; darkish; obscure; indistinct; overcast; tarnished.

The dim magnificence of poetry. Whewell.

How is the gold become dim! Lam. iv. 1.

I never saw The heavens so dim by day. Shak.

Three sleepless nights I passed in sounding on, Through words and things, a dim and perilous way. Wordsworth.

2.

Of obscure vision; not seeing clearly; hence, dull of apprehension; of weak perception; obtuse.

Mine eye also is dim by reason of sorrow. Job xvii. 7.

The understanding is dim. Rogers.

⇒ Obvious compounds: dim-eyed; dim-sighted, etc.

Syn. -- Obscure; dusky; dark; mysterious; imperfect; dull; sullied; tarnished.

 

© Webster 1913.


Dim, v. t. [imp. & p. p. Dimmed (?); p. pr. & vb. n. Dimming.]

1.

To render dim, obscure, or dark; to make less bright or distinct; to take away the luster of; to darken; to dull; to obscure; to eclipse.

A king among his courtiers, who dims all his attendants. Dryden.

Now set the sun, and twilight dimmed the ways. Cowper.

2.

To deprive of distinct vision; to hinder from seeing clearly, either by dazzling or clouding the eyes; to darken the senses or understanding of.

Her starry eyes were dimmed with streaming tears. C. Pitt.

 

© Webster 1913.


Dim, v. i.

To grow dim.

J. C. Shairp.

 

© Webster 1913.

Log in or registerto write something here or to contact authors.