微信乔迁新居邀请函:关于vb编程!帮我看看错在哪里!!急!!!

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 16:50:44
Dim carteam(8) As String
Dim cost(8) As Long
Dim selected As Integer

Private Sub Command3_Click()
End
End Sub

Private Sub Command2_Click()
If TxtPrice.Text < cost(selected) Then
MsgBox "难道这个车队一年就花" & TxtPrice.Text & "万元这么少的钱吗?笨蛋!", vbOKOnly + vbInformation, "猜错了!"
ElseIf TxtPrice.Text > cost(selected) Then
MsgBox "这个车队要花" & TxtPrice.Text & "万元这么多的钱吗?以为烧钱啊!", vbOKOnly + vbInformation, "猜错了!"
Else
MsgBox "恭喜你,你获得了车队的参观券!", vbOKOnly + vbInformation, "猜对了!"
End If

End Sub

Private Sub Command1_Click()

Command1.Enabled = True
Txtcost.Enabled = True
Txtcost.Text = ""
Txtcost.SetFocus

Dim i As Integer
Randomize
selected = Int(Rnd() * 10)
For i = 0 To 7
Image1(i).Visible = False
Next i
Image1(selected).Visible = True

lblName.Caption = sName(selected)

End Sub

Private Sub Form_Load()
sName(0) = "英美车队"
sName(1) = "威廉姆斯车队"
sName(2) = "乔丹车队"
sName(3) = "美洲虎车队"
sName(4) = "迈凯轮车队"
sName(5) = "雷诺车队"
sName(6) = "丰田车队"
sName(7) = "法拉利车队"

cost(0) = 200
cost(1) = 150
cost(2) = 150
cost(3) = 140
cost(4) = 270
cost(5) = 140
cost(6) = 200
cost(7) = 410

End Sub

Private Sub TxtPrice_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Sub
我刚开始学vb!!!请各位大虾帮忙!!小弟在这谢了!

Option Explicit

Dim carteam(8) As String
Dim cost(8) As Long
Dim selected As Integer

Dim sname(8) As String

Private Sub Command3_Click()
End
End Sub

Private Sub Command2_Click()
If Not IsNumeric(txtPrice.Text) Then txtPrice.Text = "0"

If CLng(txtPrice.Text) < cost(selected) Then
MsgBox "难道这个车队一年就花" & txtPrice.Text & "万元这么少的钱吗?笨蛋!", vbOKOnly + vbInformation, "猜错了!"
ElseIf txtPrice.Text > cost(selected) Then
MsgBox "这个车队要花" & txtPrice.Text & "万元这么多的钱吗?以为烧钱啊!", vbOKOnly + vbInformation, "猜错了!"
Else
MsgBox "恭喜你,你获得了车队的参观券!", vbOKOnly + vbInformation, "猜对了!"
End If

End Sub

Private Sub Command1_Click()

Command1.Enabled = True
txtCost.Enabled = True
txtCost.Text = ""
txtCost.SetFocus

Dim i As Integer
Randomize
selected = Int(Rnd() * UBound(carteam))
For i = 0 To 7
Image1(i).Visible = False
Next i
Image1(selected).Visible = True

lblName.Caption = sname(selected)

txtCost.Text = cost(selected)
End Sub

Private Sub Form_Load()
sname(0) = "英美车队"
sname(1) = "威廉姆斯车队"
sname(2) = "乔丹车队"
sname(3) = "美洲虎车队"
sname(4) = "迈凯轮车队"
sname(5) = "雷诺车队"
sname(6) = "丰田车队"
sname(7) = "法拉利车队"

cost(0) = 200
cost(1) = 150
cost(2) = 150
cost(3) = 140
cost(4) = 270
cost(5) = 140
cost(6) = 200
cost(7) = 410

End Sub

Private Sub TxtPrice_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Sub

刚学习VB 我教你种好的办法,可以让自己在今后的学习上,知道自己的程序错在哪里,这样你就可以对出先的BUG 进行修改
On Error GoTo CancelLoad
把你认为出错的语句放到这里或是正个语句
CancelLoad: 这段是对错误的判断
If Err.Number <> cdlCancel Then
MsgBox Err.Description, vbExclamation
Else
Exit Sub
End If
BadLoad:返回错误信息,
MsgBox Err.Description, vbExclamation
Exit Sub
End If
GOOD LUCK
用软件改变世界,用代码书写人生,用思想创造未来!