关于vb的一个问题
PrivateSubCommand1_Click()Dima(2,3),c(2,3),trans(3,3)a(1,1)=2000a(1,2)=2000a(1,3)=1a(...
Private Sub Command1_Click()
Dim a(2, 3), c(2, 3), trans(3, 3)
a(1, 1) = 2000
a(1, 2) = 2000
a(1, 3) = 1
a(2, 1) = 4000
a(2, 2) = 4000
a(2, 3) = 1
Line (a(1, 1), Form1.Height - a(1, 2))-(a(2, 1), Form1.Height - a(2, 2)), RGB(255, 0, 0), B
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
For i = 1 To 3
For j = 1 To 3
trans(i, j) = 0
If i = j Then
trans(i, j) = 1
End If
Next j
Next i
trans(3, 1) = 5000
trans(3, 2) = 5000
End
For i = 1 To 2
For j = 1 To 3
c(i, j) = 0
For k = 1 To 3
c(i, j) = c(i, j) + a(i, k) * trans(k, j)
Next k
Next j
Next i
End
Line (c(1, 1), Form1.Height - c(1, 2))-(c(2, 1), Form1.Height - c(2, 2)), RGB(255, 0, 0), B
Command2.Enabled = False
Command1.Enabled = True
End Sub
这是我编的一个平移矩形的一个程序,按钮有两个,一个是画图(原先的矩形),一个是平移,我点画图能行,为什么点平移按钮,它就闪一下,不出现结果呢???(c是平移后的点的坐标,trans是变换矩阵,a是原来的两点的坐标) 展开
Dim a(2, 3), c(2, 3), trans(3, 3)
a(1, 1) = 2000
a(1, 2) = 2000
a(1, 3) = 1
a(2, 1) = 4000
a(2, 2) = 4000
a(2, 3) = 1
Line (a(1, 1), Form1.Height - a(1, 2))-(a(2, 1), Form1.Height - a(2, 2)), RGB(255, 0, 0), B
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
For i = 1 To 3
For j = 1 To 3
trans(i, j) = 0
If i = j Then
trans(i, j) = 1
End If
Next j
Next i
trans(3, 1) = 5000
trans(3, 2) = 5000
End
For i = 1 To 2
For j = 1 To 3
c(i, j) = 0
For k = 1 To 3
c(i, j) = c(i, j) + a(i, k) * trans(k, j)
Next k
Next j
Next i
End
Line (c(1, 1), Form1.Height - c(1, 2))-(c(2, 1), Form1.Height - c(2, 2)), RGB(255, 0, 0), B
Command2.Enabled = False
Command1.Enabled = True
End Sub
这是我编的一个平移矩形的一个程序,按钮有两个,一个是画图(原先的矩形),一个是平移,我点画图能行,为什么点平移按钮,它就闪一下,不出现结果呢???(c是平移后的点的坐标,trans是变换矩阵,a是原来的两点的坐标) 展开
展开全部
程序逻辑上是对的,没什么大问题,
但是中间为什么加了这么多End呢?End不就是让程序结束吗?你按第二个按钮的时候程序不会退出吗?
而且你的窗体一定要够长够宽哦,form1的height至少要大于9020左右,你这个矩形是往右上角移动的,如果窗体太小,Form1.Height - c(1, 2)就成负数了,根本画不出来。
但是中间为什么加了这么多End呢?End不就是让程序结束吗?你按第二个按钮的时候程序不会退出吗?
而且你的窗体一定要够长够宽哦,form1的height至少要大于9020左右,你这个矩形是往右上角移动的,如果窗体太小,Form1.Height - c(1, 2)就成负数了,根本画不出来。
追问
谢谢您的回答,我把end去掉以后,程序果然不跳出来了,但是我把高度和宽度调到最大,按第二个按钮还是没有平移后的图啊。。
追答
哦,忘记说了,你定义的变量得放到外面呀,不然你第二个按钮里面a和c都成0了呗
Option Explicit
Dim a(2, 3), c(2, 3), trans(3, 3)
Private Sub Command1_Click()
a(1, 1) = 2000
a(1, 2) = 2000
a(1, 3) = 1
a(2, 1) = 4000
a(2, 2) = 4000
a(2, 3) = 1
Line (a(1, 1), Form1.Height - a(1, 2))-(a(2, 1), Form1.Height - a(2, 2)), RGB(255, 0, 0), B
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Dim i As Long, j As Long, k As Long
For i = 1 To 3
For j = 1 To 3
trans(i, j) = 0
If i = j Then
trans(i, j) = 1
End If
Next j
Next i
trans(3, 1) = 5000
trans(3, 2) = 5000
For i = 1 To 2
For j = 1 To 3
c(i, j) = 0
For k = 1 To 3
c(i, j) = c(i, j) + a(i, k) * trans(k, j)
Next k
Next j
Next i
Line (c(1, 1), Form1.Height - c(1, 2))-(c(2, 1), Form1.Height - c(2, 2)), RGB(255, 0, 0), B
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询