What does DIM stand for in Visual Basic and BASIC?
Asked Answered
U

10

309

What does Dim stand for in Visual Basic?

Unkenned answered 23/6, 2009 at 15:57 Comment(0)
F
351

Dim originally (in BASIC) stood for Dimension, as it was used to define the dimensions of an array.

(The original implementation of BASIC was Dartmouth BASIC, which descended from FORTRAN, where DIMENSION is spelled out.)

Nowadays, Dim is used to define any variable, not just arrays, so its meaning is not intuitive anymore.

Forb answered 23/6, 2009 at 16:1 Comment(5)
a little background might help. In early releases of basic the only variables that needed to be declared were arrays. The "Dim" keyword was used to set the dimensions of this array.Complement
I remember reading a gw-basic programming guide in the early 80's and I explicitly remember it explaining DIM meaning Declare In Memory. Reading the Darthmouth Basic guide from '64 has LET and READ statements assign variables and their values and later in '68 DIM is included and in fact is used for arrays. bitsavers.org/pdf/dartmouth/BASIC_4th_Edition_Jan68.pdfPrevention
One thing to keep in mind is that, in early language development, it was common to overload a keyword to have multiple meanings. Since, in the original Basic, "Dim" was already a keyword used to declare array variables, the keyword was extended to include declaring all variables. Introducing a new keyword was avoided for multiple reasons, one of which is they didn't want to break existing programs who already used the new keyword as a variable name. Today we have more sophisticated parsing technologies and faster computers, we don't see those types of limitations.Pepsinate
For instance, in later Basic, such as Visual Basic, a type and a variable could be the same name. A great example of a keyword that was overloaded too much is "static" in C++. It means different things in different contexts.Pepsinate
For those looking at the great BASIC manual @Prevention linked to, the first reference to DIM is on page numbered 21 or it is page 26 in the PDF itself. The more formal definition is on page numbered 37 or 41 in the PDF itself.Inflect
A
133

Dim have had different meanings attributed to it.

I've found references about Dim meaning "Declare In Memory", the more relevant reference is a document on Dim Statement published Oracle as part of the Siebel VB Language Reference. Of course, you may argue that if you do not declare the variables in memory where do you do it? Maybe "Declare in Module" is a good alternative considering how Dim is used.

In my opinion, "Declare In Memory" is actually a mnemonic, created to make easier to learn how to use Dim. I see "Declare in Memory" as a better meaning as it describes what it does in current versions of the language, but it is not the proper meaning.

In fact, at the origins of Basic Dim was only used to declare arrays. For regular variables no keyword was used, instead their type was inferred from their name. For instance, if the name of the variable ends with $ then it is a string (this is something that you could see even in method names up to VB6, for example Mid$). And so, you used Dim only to give dimension to the arrays (notice that ReDim resizes arrays).


Really, Does It Matter? I mean, it is a keyword it has its meaning inside an artificial language. It doesn't have to be a word in English or any other natural language. So it could just mean whatever you want, all that matters is that it works.

Anyhow, that is not completely true. As BASIC is part of our culture, and understanding why it came to be as it is - I hope - will help improve our vision of the world.


I sit in from of my computer with a desire to help preserve this little piece of our culture that seems lost, replaced by our guessing of what it was. And so, I have dug MSDN both current and the old CDs from the 1998 version. I have also searched the documention for the old QBasic [Had to use DOSBox] and managed to get some Darthmouth manual, all to find how they talk about Dim. For my disappointment, they don't say what does Dim stand for, and only say how it is used.

But before my hope was dim, I managed to find this BBC Microcomputer System Used Guide (that claims to be from 1984, and I don't want to doubt it). The BBC Microcomputer used a variant of BASIC called BBC BASIC and it is described in the document. Even though, it doesn't say what does Dim stand for, it says (on page 104):

... you can dimension N$ to have as many entries as you want. For example, DIM N$(1000) would create a string array with space for 1000 different names.

As I said, it doesn't say that Dim stands for dimension, but serves as proof to show that associating Dim with Dimension was a common thing at the time of writing that document.

Now, I got a rewarding surprise later on (at page 208), the title for the section that describes the DIM keyword (note: that is not listed in the contents) says:

DIM dimension of an array

So, I didn't get the quote "Dim stands for..." but I guess it is clear that any decent human being that is able to read those document will consider that Dim means dimension.


With renewed hope, I decided to search about how Dim was chosen. Again, I didn't find an account on the subject, still I was able to find a definitive quote:

Before you can use an array, you must define it in a DIM (dimension) statement.

You can find this as part of the True BASIC Online User's Guides at the web page of True BASIC inc, a company founded by Thomas Eugene Kurtz, co-author of BASIC.


So, In reallity, Dim is a shorthand for DIMENSION, and yes. That existed in FORTRAN before, so it is likely that it was picked by influence of FORTRAN as Patrick McDonald said in his answer.


Dim sum as string = "this is not a chinese meal" REM example usage in VB.NET ;)
Actinouranium answered 5/10, 2010 at 1:19 Comment(3)
I've heard "declare in memory" also.Tumescent
"Really, Does It Matter?" Underappreciated joke. Also I am now going to insist to people that this is what Dim actually stands forPrebo
The ZX Spectrum BASIC Programming manual from 1983 explicitly mentions that "Before you can use an array, you must reserve some space for it inside the computer, and you do this using a DIM (for dimension) statement."Ex
H
31

It's short for Dimension, as it was originally used in BASIC to specify the size of arrays.

DIM — (short for dimension) define the size of arrays

Ref: http://en.wikipedia.org/wiki/Dartmouth_BASIC

A part of the original BASIC compiler source code, where it would jump when finding a DIM command, in which you can clearly see the original intention for the keyword:

DIM    LDA XR01             BACK OFF OBJECT POINTER
       SUB N3
       STA RX01
       LDA L        2       GET VARIABLE TO BE DIMENSIONED
       STA 3
       LDA S        3
       CAB N36              CHECK FOR $ ARRAY
       BRU *+7              NOT $
       ...

Ref: http://dtss.dartmouth.edu/scans/BASIC/BASIC%20Compiler.pdf

Later on it came to be used to declare all kinds of variables, when the possibility to specify the type for variables was added in more recent implementations.

Hachure answered 23/6, 2009 at 16:2 Comment(0)
G
15

Dimension a variable, basically you are telling the compiler that you are going to need a variable of this type at some point.

Galore answered 23/6, 2009 at 16:0 Comment(0)
C
14

It stands for Dimension, but is generally read as "Create Variable," or "Allocate Space for This."

Cockle answered 23/6, 2009 at 16:2 Comment(0)
S
10

Variable declaration. Initially, it was short for "dimension", which is not a term that is used in programming (outside of this specific keyword) to any significant degree.

http://in.answers.yahoo.com/question/index?qid=20090310095555AANmiAZ

Stove answered 23/6, 2009 at 16:1 Comment(0)
P
7

Back in the day DIM reserved memory for the array and when memory was limited you had to be careful how you used it. I once wrote (in 1981) a BASIC program on TRS-80 Model III with 48Kb RAM. It wouldn't run on a similar machine with 16Kb RAM until I decreased the array size by changing the DIM statement

Phobia answered 9/10, 2009 at 21:5 Comment(0)
B
7

DIM stands for Declaration In Memory DIM x As New Integer creates a space in memory where the variable x is stored

Barquentine answered 14/1, 2012 at 20:12 Comment(0)
I
4

Short for Dimension. It's a type of variable. You declare (or "tell" Visual Basic) that you are setting up a variable with this word.

Instalment answered 7/4, 2012 at 8:30 Comment(0)
W
3

The Dim keyword is optional, when we are using it with modifiers- Public, Protected, Friend, Protected Friend,Private,Shared,Shadows,Static,ReadOnly etc. e.g. - Static nTotal As Integer

For reference type, we have to use new keyword to create the new instance of the class or structure. e.g. Dim lblTop As New System.Windows.Forms.Label.

Dim statement can be used with out a datatype when you set Option Infer to On. In that case the compiler infers the data type of a variable from the type of its initialization expression. Example :

Option Infer On

Module SampleMod

Sub Main()

 Dim nExpVar = 5

The above statement is equivalent to- Dim nExpVar As Integer

Wasson answered 3/7, 2015 at 20:30 Comment(1)
Welcome to StackOverflow and thank you for this answer, but it doesn't really expand on the numerous other answers that all give the same answer.Harrovian

© 2022 - 2024 — McMap. All rights reserved.