Dim i,j as integer 表明i和j都是整型变量.为什么是错的?
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/09 05:06:09
Dim i,j as integer 表明i和j都是整型变量.为什么是错的?
Dim i, j as integer
相当于
Dim i
Dim j as integer
也就是
Dim i as Variant
Dim j as integer
这也就是说,i是Variant(变体型),只有j才是整型
补充说明:
我发现有好多大学生编的VB程序都有这样的问题:
Dim a, b, c, d As String
其实这是完全错的.在这里,逗号的优先级要高于As,也就是说,上面语句相当于:
Dim a
Dim b
Dim c
Dim d As String
也就是
Dim a As Variant
Dim b As Variant
Dim c As Variant
Dim d As String
虽然在多数情况下,这么做并不会造成程序出错(因为Variant可以代替其他任何类型),但这跟你设计的初衷就有很大出入了(且不说用Variant会造成资源浪费、效率降低).程序应该是严谨的,差之毫厘谬以千里,所以我们应该养成良好的正确的编程习惯,正确的写法应该是:
Dim a As String, b As String, c As String, d As String
补充说一句,我怀疑是不是现在大学的电脑老师就是这样教的(即Dim a, b, c, d As String)?我不知道,因为我是自学的.如果真是这样,那我对中国的教育真是失望透顶了!没救了!
再补充一句:要验证我说的对不对,可以用下面的代码:
Dim a, b As String
Print "a的类型是" & TypeName(a)
Print "b的类型是" & TypeName(b)
相当于
Dim i
Dim j as integer
也就是
Dim i as Variant
Dim j as integer
这也就是说,i是Variant(变体型),只有j才是整型
补充说明:
我发现有好多大学生编的VB程序都有这样的问题:
Dim a, b, c, d As String
其实这是完全错的.在这里,逗号的优先级要高于As,也就是说,上面语句相当于:
Dim a
Dim b
Dim c
Dim d As String
也就是
Dim a As Variant
Dim b As Variant
Dim c As Variant
Dim d As String
虽然在多数情况下,这么做并不会造成程序出错(因为Variant可以代替其他任何类型),但这跟你设计的初衷就有很大出入了(且不说用Variant会造成资源浪费、效率降低).程序应该是严谨的,差之毫厘谬以千里,所以我们应该养成良好的正确的编程习惯,正确的写法应该是:
Dim a As String, b As String, c As String, d As String
补充说一句,我怀疑是不是现在大学的电脑老师就是这样教的(即Dim a, b, c, d As String)?我不知道,因为我是自学的.如果真是这样,那我对中国的教育真是失望透顶了!没救了!
再补充一句:要验证我说的对不对,可以用下面的代码:
Dim a, b As String
Print "a的类型是" & TypeName(a)
Print "b的类型是" & TypeName(b)
vb程序Dim a(1 To 20) As Integer,i As Integer,j As Integer
Private Sub Command1_Click() Dim i,j As Integer For i = 3 To
dim a(10,10) as integer for i=1 to 10 for j=1to 10 a(i,j)=i*
Dim x(3,5) As Integer For i = 1 To 3 For j = 1 To 5 x(i,j) =
DIM AS INTEGER A(6),I,T,J,P T=0 FOR I=1 TO 6:A(I)=7-I:NEXT F
定义整型变量i和j的初值分别为2和3,则下列语句运行后,i和j的值分别为( ).
Dim a(9) As Integer,x As Integer,k As Integer,I As Integer R
若有整型变量i,j,则以下程序段中内循环体的循环次数为
x,i,j和k都是int型变量,则计算表达式x=(i=4,j=16,k=32)后,x的值是
Dim ia(1 To 10) As Integer,imin As Integer,n As Integer,i As
某过程中有以下语句dim V as integer v = "200.0"V是整型,却赋给v一个字符串型,为什么不会报错
设 x,i,k,j都是int 型变量. 计算下面表达式 结果为什么是32 x =(i=4, j=16, k=32)