新开网站,目前还在陆续搬家中,现开源一个以前随手做的VB小游戏供VB新手学习用。
不过目前VB还有人用吗。。。
源代码如下:
Dim i As Integer
Dim j As Integer
Dim ball(38) As Double
Dim status(38) As String
Dim k As Integer
Dim t As Integer
Private Sub Command1_Click()
Randomize
k = Int(Rnd * 38)
ball(k) = Rnd * 10
Command1.Visible = False
Label2.Caption = 4
Label3.Visible = False
Label2.Visible = True
Label1.Visible = True
Label4.Visible = True
Line1.Visible = True
Shape1.Visible = True
Shape2.Visible = True
Command5.Visible = True
Command4.Visible = True
Command6.Visible = True
Label5.Visible = False
For i = 0 To 37
Command2(i).Visible = True
status(i) = "在桌上"
Command2(i).ToolTipText = status(i)
Command2(i).BackColor = &H8000000F
Next
Command3.Visible = True
End Sub
Private Sub Command2_Click(Index As Integer)
If status(Index) = "在桌上" Then
status(Index) = "天平右边"
Command2(Index).BackColor = vbYellow
ElseIf status(Index) = "天平右边" Then
status(Index) = "天平左边"
Command2(Index).BackColor = vbGreen
Else
status(Index) = "在桌上"
Command2(Index).BackColor = &H8000000F
End If
Command2(Index).ToolTipText = status(Index)
End Sub
Private Sub Command3_Click()
If Label2.Caption = 0 Then
Label2.Visible = False
Label4.Visible = False
Label1.ForeColor = vbRed
Command4.Visible = True
Command4.Visible = True
Label1.Caption = "你已经称过4次了..."
Else
Label2.Caption = Label2.Caption - 1
For i = 0 To 37
If status(i) = "天平左边" Then
lefttotal = lefttotal + ball(i)
ElseIf status(i) = "天平右边" Then
righttotal = righttotal + ball(i)
End If
Next
If lefttotal > righttotal Then
Line1.Y1 = 2980
Shape1.Top = 2740
Line1.Y2 = 2780
Shape2.Top = 2540
ElseIf lefttotal < righttotal Then
Line1.Y1 = 2780
Shape1.Top = 2540
Line1.Y2 = 2980
Shape2.Top = 2740
Else
Line1.Y1 = 2880
Shape1.Top = 2640
Line1.Y2 = 2880
Shape2.Top = 2640
End If
End If
End Sub
Private Sub Command4_Click()
Form_Load
End Sub
Private Sub Command5_Click()
bbb:
a = InputBox("请输入你猜测的球编号(1-38):")
If a < 1 Or a > 38 Then
MsgBox "输入错误!只能输入(1-38)."
GoTo bbb
ElseIf a <> k + 1 Then
MsgBox "很遗憾,错误!正确的应该是" & k + 1 & "号球."
GoTo aaa
Else
MsgBox "你答对了!接下来请问此球比其它球轻还是重?"
End If
ccc:
b = InputBox("请输入轻或者重:")
If b = "轻或者重" Then
MsgBox "你脑子被驴踢了啊!"
b = InputBox("请输入轻或者重:")
ElseIf b = "轻" And ball(k) < 5 Then
MsgBox "答案正确!"
ElseIf b = "重" And ball(k) > 5 Then
MsgBox "答案正确!"
ElseIf b <> "重" And b <> "轻" Then
MsgBox "输入错误!只能输入重或者轻."
GoTo ccc
Else
MsgBox "真可惜," & k + 1 & "号球重量为" & ball(k)
End If
aaa:
Form_Load
End Sub
Private Sub Command6_Click()
For i = 0 To 37
status(i) = "在桌上"
Command2(i).BackColor = &H8000000F
Command2(i).ToolTipText = status(i)
Next
Line1.Y1 = 2880
Shape1.Top = 2640
Line1.Y2 = 2880
Shape2.Top = 2640
End Sub
Private Sub Form_Load()
Line1.Y1 = 2880
Line1.Y2 = 2880
Shape1.Top = 2640
Shape2.Top = 2640
t = 0
Command6.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = True
Label4.Visible = False
Label5.Visible = True
Command1.Visible = True
Shape1.Visible = False
Shape2.Visible = False
Line1.Visible = False
Command3.Visible = False
Command5.Visible = False
Command4.Visible = False
For i = 0 To 37
Command2(i).Visible = False
Command2(i).Caption = i + 1
ball(i) = 5
Next
j = -1
End Sub
文章评分1次,平均分5.0:★★★★★

VB当然有人用啦,而且用的人还蛮多的。最近有用VBA来写宏
VB当时用来做条形码打印机程序的时候用到。
头痛,之前学VB前看到就好了~
这都是陈年老账了。
现在 就想学习这个了= =