首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

vb中的代码解决方案

2012-04-22 
vb中的代码Private Sub Command1_Click()If DTPicker1.Value CDate(Text1.Text) ThenMsgBox 进货日期不

vb中的代码
Private Sub Command1_Click()
If DTPicker1.Value > CDate(Text1.Text) Then
MsgBox "进货日期不能大于登记日期,请重新选择", vbOKOnly + vbExclamation, "提示"
 Exit Sub
 Else
 If Combo1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then ' Or Text5.Text = ""
 MsgBox "请将信息填写完整!", vbOKOnly + vbExclamation, "提示"
 Exit Sub
 'End If
  Else

Do While rs1.EOF = False 'then
If rs1.Fields(2) = Text2.Text And rs1.Fields(3) = Combo1.Text Then
MsgBox "此光盘信息已录入,是否增加!", vbOKOnly + vbExclamation, "提示"
Exit Sub
rs1.Fields(4) = rs1.Fields(4) + Val(Text3.Text)
rs1.Fields(6) = rs1.Fields(6) + Val(Text5.Text)
End If
Loop

'Else
rs1.MoveNext

  rs1.AddNew
  rs1.Fields(0) = DTPicker1.Value
  rs1.Fields(1) = Text1.Text
  rs1.Fields(2) = Text2.Text
  rs1.Fields(3) = Combo1.Text
  rs1.Fields(4) = Text3.Text
  rs1.Fields(5) = Text4.Text
  rs1.Fields(6) = Text5.Text
  rs1.Update

  a = MsgBox("信息添加成功")
  Combo1.Text = ""
 Text2.Text = ""
 Text3.Text = ""
 Text4.Text = ""
 Text5.Text = ""

 End If
 End If
End Sub

谁能帮我看看这段代码哪里有问题,尤其是我设置成黑体的部分,谢谢

[解决办法]
rs1.Fields(4) = rs1.Fields(4) + Val(Text3.Text)
rs1.Fields(6) = rs1.Fields(6) + Val(Text5.Text)

这两句永远不会被执行,是死代码
[解决办法]
执行"Exit Sub"后, 就退出Command1_Click了。
[解决办法]

VB code
Private Sub Command1_Click()If DTPicker1.Value > CDate(Text1.Text) Then    MsgBox "进货日期不能大于登记日期,请重新选择", vbOKOnly + vbExclamation, "提示"    Exit SubEnd IfIf Combo1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then ' Or Text5.Text = ""    MsgBox "请将信息填写完整!", vbOKOnly + vbExclamation, "提示"    Exit SubEnd IfDo Until rs1.EOF = False 'then    If rs1.Fields(2) = Text2.Text And rs1.Fields(3) = Combo1.Text Then        If MsgBox("此光盘信息已录入,是否增加?", vbOKCancel + vbExclamation, "提示") = vbOK Then            rs1.Fields(4) = rs1.Fields(4) + Val(Text3.Text)            rs1.Fields(6) = rs1.Fields(6) + Val(Text5.Text)        End If        Exit Sub    End If    rs1.MoveNextLooprs1.AddNewrs1.Fields(0) = DTPicker1.Valuers1.Fields(1) = Text1.Textrs1.Fields(2) = Text2.Textrs1.Fields(3) = Combo1.Textrs1.Fields(4) = Text3.Textrs1.Fields(5) = Text4.Textrs1.Fields(6) = Text5.Textrs1.Updatea = MsgBox("信息添加成功")Combo1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""End Sub
[解决办法]
探讨
rs1.Fields(4) = rs1.Fields(4) + Val(Text3.Text)
rs1.Fields(6) = rs1.Fields(6) + Val(Text5.Text)

这两句永远不会被执行,是死代码

热点排行