Dim a(1 To 9) As Boolean
Dim win As Boolean, begin As Boolean, haveload As Boolean, start As BooleanPrivate Sub Command1_Click()
start = True: begin = False
For i = 1 To 9
a(i) = False
Next i
Form_Load
End SubPrivate Sub Form_Load()
a(9) = True
Label1(0).Visible = False
Me.Height = 4400
Me.Width = 4000
Scale (0, 0)-(3, 3.3)
If haveload = False Then
haveload = True: start = True
Command1.Top = 3: Command1.Left = 2
Command1.Width = 1: Command1.Height = 0.3
Command1.Caption = "开始"
For i = 1 To 9
Load Label1(i)
Next i
End If
For i = 1 To 9
Label1(i).Height = 1
Label1(i).Width = 1
Label1(i).Visible = True
Label1(i).Top = (i - 1) \ 3
Label1(i).Left = (i - 1) Mod 3
Label1(i).Caption = Str(i)
Label1(i).BackColor = QBColor(i)
Label1(i).FontBold = True
Label1(i).FontSize = 40
Next i
Label1(9).Caption = "": Label1(9).BackColor = vbWhite
Randomize
For i = 1 To 500
r% = Int(9 * Rnd) + 1
Call Label1_Click(r)
Next i
begin = True
End SubPrivate Sub Label1_Click(index As Integer)
Dim x1 As Integer, y1 As Integer
If start = True Then
If a(index) = False Then
x1 = (index - 1) Mod 3: y1 = (index - 1) \ 3
If x1 - 1 >-0.2 Then
If a(x1 + y1 * 3) = True Then Call yidong(x1 + y1 * 3, index)
End If
If x1 + 1 <2.2 Then
If a(x1 + y1 * 3 + 2) = True Then Call yidong(x1 + y1 * 3 + 2, index)
End If
If y1 - 1 >-0.2 Then
If a(x1 + 1 + (y1 - 1) * 3) = True Then Call yidong(x1 + (y1 - 1) * 3 + 1, index)
End If
If y1 + 1 <2.2 Then
If a(x1 + 1 + (y1 + 1) * 3) = True Then Call yidong(x1 + 1 + (y1 + 1) * 3, index)
End If
End If
win = True
For i = 1 To 8
If Val(Label1(i).Caption) <>i Then win = False
Next i
If win = True And begin = True Then MsgBox ("恭喜你成功了"): begin = False: start = False
End If
End Sub
Sub yidong(x, index)
Label1(0).Caption = Label1(index).Caption
Label1(index).Caption = Label1(x).Caption
Label1(x).Caption = Label1(0).Caption
a(index) = True: a(x) = False
Label1(0).BackColor = Label1(index).BackColor
Label1(index).BackColor = Label1(x).BackColor
Label1(x).BackColor = Label1(0).BackColor
End Sub
在桌面上,鼠标左键双击程序,在打开的VB6主界面上,左边是工具菜单栏,单击标签按钮,兆岁在Form1窗口上,绘制出悔猜腊一Label1,然后在其属性窗口上改个名字,如Caption为第一数,如下图所示。
接着,用同样的方法,在Form1窗口上绘制出第二数,并且在左边工具菜单栏,单击文本框按钮,并绘制出来。在文本框属性栏的Text属性上,将其Text1删除,也就是清空数据,如下图所示。
然后,反复用第一步骤和第二步骤做成如图所示的界面来,学习需要反复练习,在练习中不断进步。这里是做简单的加法程序,如下图所示。
接着,加法程序的界面做好后,还不能执行加法运算,必须还要在Form1窗口上绘制出一个命令按钮来,在左边工具菜单栏,单击命令按钮,并绘制出来。然后给其属性窗口下Caption改名为计算,如下图所示。
然后,程序看起来是做好了,单击如图所示的运行按钮,d出自己做出的Form1窗口,输入数字3和6,然后单击计算。可是结果并没有出现,如下图所示。
最后,前面5个步骤只是做碧滑了程序的界面,想要程序出结果,那必须加些代码了,既然是简单程序,只加一行代码就可以了。双击命令按钮,在代码窗口中输入如下:Text3.Text = Val(Text1.Text) + Val(Text2.Text)后,再单击运行,输入数字,单击计算,此时就出现结果了,如下图所示。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)