Dim i,j as integer 表明i和j都是整型变量.为什么是错的?

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/09 02:06:55

Dim i,j as integer 表明i和j都是整型变量.为什么是错的?
Dim i,j as integer 表明i和j都是整型变量.为什么是错的?

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,j as integer 表明i和j都是整型变量.为什么是错的? dim a(3,2) as integer a(3,2)啥意思a(j,i)呢 vb程序Dim a(1 To 20) As Integer,i As Integer,j As IntegerDim a(1 To 20) As Integer,i As Integer,j As IntegerPrivate Sub Command1_Click()Dim a(1 To 20) As IntegerFor j = 1 To 2For i = 1 To 10a(i) = Int(Rnd * 21) + 20Text1 = Text1 & Str(a(i))Next iTe Dim a(9) As Integer,x As Integer,k As Integer,I As Integer RandomizeDo While I Dim ia(1 To 10) As Integer,imin As Integer,n As Integer,i As Integer,j As Integer,t As Integern = 6For i = 1 To n - 1 imin = i For j = i + 1 To nIf ia(j) < ia(imin) Then imin = jNext jt = ia(i)ia(i) = ia(imin)ia(imin) = tNext i VB 使显示每行的最大值的位置(下面的程序可以把最大值找出)Private Sub cmdbegin_Click() Dim a(4,3) As Integer,i As Integer,j As Integer Dim max As Integer For i = 1 To 4 For j = 1 To 3 a(i,j) = InputBox(请输入矩阵的第 您给我的计算公式没有去处重复的组合呀!就是33个数字的那个.如题 原程序:Sub tt() Application.ScreenUpdating = False Dim i,j,k,l,m,n As Integer Dim Ar(33) As Integer,Arsum As Long,tempSum As Long Dim x As Long Dim FS As Ob Dim x(3,5) As Integer For i = 1 To 3 For j = 1 To 5 x(i,j) = x(i - 1,j - 1) + i + j Next j Next iprint (3,4) vb编程 Call q(1,i):Call q(2,j):Call q(3,k):Dim i As Integer,j As Integer,k As Integer,h As IntegerPrivate Sub Form_click()i = 0:j = 1:k = 2Call q(1,i):Print i; j; kCall q(2,j):Print i; j; kCall q(3,k):Print i; j; kEnd SubPrivate Sub p(i)i = i + 1:P VB 麻烦把A矩阵改成下三角型显示,B上三角型显示Private Sub Command1_Click()Dim a(4, 4) As IntegerDim i As Integer, j As Integer For i = 1 To 4 For j = 1 To 4 a(i, j) = Int(Rnd * 41 + 30) Print a(i, j); Next j Print Next i DIM AS INTEGER A(6),I,T,J,P T=0 FOR I=1 TO 6:A(I)=7-I:NEXT FOR I=1 TO 5 FOR J=1 TO 5 IF A(J)>A( dim i as integer dim sum as integer sum=0 for i=0 to 5 sum=sum+i next sum=? Dim a(1 To 10) As Integer Dim i As Integer a(1) = 1 For i = 2 To 10 a(i) = a Private Sub Command1_Click() Dim i,j As Integer For i = 3 To 1 Step -1 Print Spc(5); For j = 1 To 2Private Sub Command1_Click()Dim i,j As IntegerFor i = 3 To 1 Step -1Print Spc(5);For j = 1 To 2 * i - 1Print *;nextjPrintNext iEnd Sub请问它为什 请用通俗易懂的语言解释该代码的意思Function SJS() As String Application.Volatile Randomize Dim i,j As Integer Dim iFlag As Boolean SJS = Int(Rnd() * 10) For i = 1 To 5 iFlag = True Do While iFlag j = Int(Rnd() * 10) If InStr(SJS,j) = vb中判断语句 If A(i,j) =0 Then A(i,j)=k,其中动态数组A()被赋值为0,option base1dim A() as integerprivate sub command1_click()dim i as integer ,j as integer ,k as integerdim n as integern=3redim A(n,n)i=1:j=(n+1)/2k=1A(i,j)=k ________ vb计算1!+3!+*****+(2n+1)!的代码Private Sub Command1_Click()Dim n As Integer, i As Integer, j As Integern = Val(InputBox(请输入N值))m = 1: Sum = 0For i = 1 To 2 * n + 1 Step (2)For j = 1 To im = m * jNext jSum = Sum + mNext iPrint SumEn 删除一个数列中的重复数Option ExplicitOption Base 1Dim A() As Integer '定义了一个模块级的动态数组Private Sub Command1_Click() Dim N As Integer, I As Integer Text1 = Text2 = N = Inpu