vb运行时提示错误7 程序代码如下 请大神赐教
PrivateSubCommand1_Click()Diml(8)AsBooleanDima(8)AsIntegerDimb(8)AsIntegerDimc(600,62...
Private Sub Command1_Click()
Dim l(8) As Boolean
Dim a(8) As Integer
Dim b(8) As Integer
Dim c(600, 620, 600, 620)
Dim e(8) As Integer
Dim m As Long
Dim n As Long
Dim x As Long
Dim y As Long
Dim q As Long
Dim w As Long
Dim r As Long
Dim t As Long
a(1) = 240
a(2) = 10
a(3) = 60
a(4) = 20
a(5) = 560
a(6) = 180
a(7) = 520
a(8) = 600
b(1) = 90
b(2) = 160
b(3) = 620
b(4) = 360
b(5) = 70
b(6) = 110
b(7) = 60
b(8) = 400
e(1) = 25
e(2) = 49
e(3) = 53
e(4) = 33
e(5) = 36
e(6) = 17
e(7) = 64
e(8) = 76
For m = 1 To 2
For n = 1 To 2
For x = 1 To 2
For y = 1 To 2
For i = 1 To 8
If e(i) * ((m - a(i)) ^ 2 + (n - b(i)) ^ 2) ^ (1 / 2) >= e(i) * ((x - a(i)) ^ 2 + (y - b(i)) ^ 2) ^ (1 / 2) Then
l(i) = True
Else
l(i) = False
End If
Next i
For i = 1 To 8
If l(i) = True Then
c(m, n, x, y) = c(m, n, x, y) + e(i) * ((m - a(i)) ^ 2 + (n - b(i)) ^ 2) ^ (1 / 2)
Else
c(m, n, x, y) = c(m, n, x, y) + e(i) * ((x - a(i)) ^ 2 + (y - b(i)) ^ 2) ^ (1 / 2)
End If
Next i
Next y
Next x
Next n
Next m
Min1 = c(1, 1, 1, 1)
For q = 1 To 2
For w = 1 To 2
For r = 1 To 2
For t = 1 To 2
If c(q, w, r, t) < Min1 Then
Min1 = c(q, w, r, t)
h1 = q
z1 = w
h2 = r
z2 = t
End If
Next t
Next r
Next w
Next q
Print h1, z1, h2, z2; Min1
End Sub 展开
Dim l(8) As Boolean
Dim a(8) As Integer
Dim b(8) As Integer
Dim c(600, 620, 600, 620)
Dim e(8) As Integer
Dim m As Long
Dim n As Long
Dim x As Long
Dim y As Long
Dim q As Long
Dim w As Long
Dim r As Long
Dim t As Long
a(1) = 240
a(2) = 10
a(3) = 60
a(4) = 20
a(5) = 560
a(6) = 180
a(7) = 520
a(8) = 600
b(1) = 90
b(2) = 160
b(3) = 620
b(4) = 360
b(5) = 70
b(6) = 110
b(7) = 60
b(8) = 400
e(1) = 25
e(2) = 49
e(3) = 53
e(4) = 33
e(5) = 36
e(6) = 17
e(7) = 64
e(8) = 76
For m = 1 To 2
For n = 1 To 2
For x = 1 To 2
For y = 1 To 2
For i = 1 To 8
If e(i) * ((m - a(i)) ^ 2 + (n - b(i)) ^ 2) ^ (1 / 2) >= e(i) * ((x - a(i)) ^ 2 + (y - b(i)) ^ 2) ^ (1 / 2) Then
l(i) = True
Else
l(i) = False
End If
Next i
For i = 1 To 8
If l(i) = True Then
c(m, n, x, y) = c(m, n, x, y) + e(i) * ((m - a(i)) ^ 2 + (n - b(i)) ^ 2) ^ (1 / 2)
Else
c(m, n, x, y) = c(m, n, x, y) + e(i) * ((x - a(i)) ^ 2 + (y - b(i)) ^ 2) ^ (1 / 2)
End If
Next i
Next y
Next x
Next n
Next m
Min1 = c(1, 1, 1, 1)
For q = 1 To 2
For w = 1 To 2
For r = 1 To 2
For t = 1 To 2
If c(q, w, r, t) < Min1 Then
Min1 = c(q, w, r, t)
h1 = q
z1 = w
h2 = r
z2 = t
End If
Next t
Next r
Next w
Next q
Print h1, z1, h2, z2; Min1
End Sub 展开
展开全部
Dim c(600, 620, 600, 620)
这是个多么庞大的数组啊!它所占用的字节总数为601*621*601*621*16,你自己算算是多少吧,反正我的计算器算不了这么大的数,大概是2千多GB吧,我不知道几年后的电脑内存有没有这么大的,反正现在肯定是没有,所以发生“内存溢出”的错误就一点也不奇怪了。
从你的程序来看,这个数组其实就这么大:
Dim c(2, 2, 2, 2)
更准确一点的话,还应该把0去掉:
Dim c(1 To 2, 1 To 2, 1 To 2, 1 To 2)
这样的话,实际占用字节数就是2*2*2*2*16=256
这是个多么庞大的数组啊!它所占用的字节总数为601*621*601*621*16,你自己算算是多少吧,反正我的计算器算不了这么大的数,大概是2千多GB吧,我不知道几年后的电脑内存有没有这么大的,反正现在肯定是没有,所以发生“内存溢出”的错误就一点也不奇怪了。
从你的程序来看,这个数组其实就这么大:
Dim c(2, 2, 2, 2)
更准确一点的话,还应该把0去掉:
Dim c(1 To 2, 1 To 2, 1 To 2, 1 To 2)
这样的话,实际占用字节数就是2*2*2*2*16=256
更多追问追答
追问
我刚才也发现了这个问题了。。。可是我要用一个600*620*600*620的循环。。。。那个2是我故意改过来测试的。。。
追答
你要做什么要这么大的循环啊?假定循环一次是0.001毫秒(这已经是很短的时间了)也要接近2天的时间才能运行完啊!这还是在没考虑内存等资源限制的情况下!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询