DIM 在 Visual Basic 和 BASIC 中代表什么?
Dim
在 Visual Basic 中代表什么?
What does Dim
stand for in Visual Basic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Dim
在 Visual Basic 中代表什么?
What does Dim
stand for in Visual Basic?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
Dim
有不同的含义。我找到了关于
Dim
的参考资料,意思是“在内存中声明”,更相关的参考资料是 Dim 声明 将 Oracle 作为 Siebel VB 语言参考的一部分发布。 当然,你可能会说,如果你不在内存中声明变量,你在哪里声明呢? 考虑到Dim
的使用方式,也许“在模块中声明”是一个不错的选择。在我看来,“Declare In Memory”实际上是一个助记符,创建的目的是为了让您更容易学习如何使用
Dim
。 我认为“在内存中声明”是一个更好的含义,因为它描述了它在当前版本的语言中的作用,但这不是正确的含义。事实上,Basic
Dim
最初仅用于声明数组。 对于常规变量,不使用关键字,而是从名称推断其类型。 例如,如果变量的名称以$
结尾,则它是一个字符串(即使在 VB6 之前的方法名称中也可以看到这一点,例如Mid$
)。 因此,您仅使用Dim
为数组指定维度(请注意,ReDim
调整数组大小)。真的,这重要吗? 我的意思是,它是一个关键字,它在人工语言中具有其含义。 它不一定是英语或任何其他自然语言中的单词。 所以它可能意味着任何你想要的,重要的是它有效。
无论如何,这并不完全正确。 由于 BASIC 是我们文化的一部分,我希望理解它为何会变成现在这样,将有助于改善我们对世界的看法。
我坐在电脑前,希望能够帮助保存我们文化中的这一小部分,它似乎已经消失,取而代之的是我们对它是什么的猜测。 因此,我从 1998 年版本开始挖掘了 MSDN 的最新 CD 和旧 CD。 我还搜索了旧 QBasic 的文档 [必须使用 DOSBox] 并设法获得了一些达斯茅斯手册,所有这些都是为了找到他们如何谈论
Dim
。 令我失望的是,他们没有说Dim
代表什么,只说了它是如何使用的。但在我的希望渺茫之前,我设法找到了这份BBC微机系统使用指南 (声称是 1984 年的,我不想怀疑它)。 BBC 微型计算机使用了 BASIC 的一种变体,称为 BBC BASIC,文档中对此进行了描述。 尽管如此,它并没有说明
Dim
代表什么,它说(第 104 页):正如我所说,它并不是说
Dim
代表维度,而是证明将Dim
与Dimension
关联起来是一种常见的情况。撰写该文件时的事情。现在,稍后(第 208 页)我得到了一个惊喜,描述 DIM 关键字的部分的标题(注意:未在内容中列出)说:
所以,我没有得到“Dim 代表...”的引用,但我想很明显,任何能够阅读这些文档的正派人都会认为
Dim
表示尺寸。带着新的希望,我决定研究一下
Dim
是如何被选择的。 同样,我没有找到有关该主题的帐户,但我仍然能够找到明确的引用:您可以在 True BASIC inc 的网页上找到True BASIC 在线用户指南的一部分,一家由 BASIC 合著者 Thomas Eugene Kurtz 创立的公司。
所以,实际上,
Dim
是DIMENSION
的简写,是的。 FORTRAN 中以前就存在这种情况,因此很可能是受 FORTRAN 的影响而选择的,正如 Patrick McDonald 在他的回答中所说的。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 howDim
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 exampleMid$
). And so, you usedDim
only to give dimension to the arrays (notice thatReDim
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 doesDim
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):As I said, it doesn't say that
Dim
stands for dimension, but serves as proof to show that associatingDim
withDimension
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:
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: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 forDIMENSION
, 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.它是 Dimension 的缩写,因为它最初在 BASIC 中用于指定数组的大小。
参考:http://en.wikipedia.org/wiki /Dartmouth_BASIC
原始BASIC编译器源代码的一部分,当找到
DIM
命令时会跳转到这里,从中可以清楚地看到关键字的初衷:Ref: http://dtss.dartmouth.edu/scans/BASIC/BASIC%20Compiler.pdf
后来,当在最近的实现中添加了指定变量类型的可能性时,它被用来声明各种变量。
It's short for Dimension, as it was originally used in BASIC to specify 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: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.
确定变量的维度,基本上就是告诉编译器您在某个时候将需要这种类型的变量。
Dimension a variable, basically you are telling the compiler that you are going to need a variable of this type at some point.
它代表“维度”,但通常解读为“创建变量”或“为此分配空间”。
It stands for Dimension, but is generally read as "Create Variable," or "Allocate Space for This."
变量声明。 最初,它是“dimension”的缩写,该术语在编程中(除此特定关键字之外)没有任何重要程度的使用。
http://in.answers.yahoo.com/question/index?qid=20090310095555AANmiAZ
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
过去,DIM 为阵列保留了内存,当内存有限时,您必须小心使用它。 我曾经(1981 年)在具有 48Kb RAM 的 TRS-80 Model III 上编写了一个 BASIC 程序。 它无法在具有 16Kb RAM 的类似机器上运行,直到我通过更改 DIM 语句减小数组大小
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
DIM 代表 内存中声明
DIM x 作为新整数
在内存中创建一个存储变量 x 的空间
DIM stands for Declaration In Memory
DIM x As New Integer
creates a space in memory where the variable x is stored
维度的缩写。 它是一种变量类型。 您声明(或“告诉”Visual Basic)您正在使用该词设置一个变量。
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.
当我们将它与修饰符一起使用时,Dim 关键字是可选的 - Public、Protected、Friend、Protected Friend、Private、Shared、Shadows、Static、ReadOnly 等。
例如 -
Static nTotal As Integer
对于引用类型,我们必须使用 new 关键字来创建类或结构的新实例。 例如
Dim lblTop As New System.Windows.Forms.Label
。设置时可以在没有数据类型的情况下使用 Dim 语句
选项推断为开。
在这种情况下,编译器会根据变量的初始化表达式的类型推断变量的数据类型。
示例:
上述语句相当于 -
Dim nExpVar As Integer
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 :
The above statement is equivalent to-
Dim nExpVar As Integer
Dim 最初(在 BASIC 中)代表 Dimension,因为它用于定义数组的维度。
(BASIC 的原始实现是 Dartmouth BASIC,它源自 FORTRAN,其中 DIMENSION 拼写为)
如今,Dim 用于定义任何变量,而不仅仅是数组,因此它的含义不再直观。
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.