难道你不知道代码缩进么?
If xxx Then
If xxx Then
For xxx
xxx
Next
Else
xxxx
End If
For xxx
If xxx Then
xxx
End If
xxx
Next
End If
xxx
If xxx Then
If xxx Then
For xxx
xxx
Next
Else
xxxx
End If
For xxx
If xxx Then
xxx
End If
xxx
Next
End If
xxx
解决方案 »
- 请问 这段代码速度差别的原因是什么?
- 现在有N个Command按钮,想显示在窗体的某一部分,但太多需要垂直滚动条,请问用什么做容器,怎么加?
- 如何用程序取消打印队列中的文档呢
- 哪位兄弟有发送邮件的代码呀?要求支持smtp验证,可以发送附件(主要)~
- 谁有使用vb自带的报表设计器,进行打印的例子,给代码,马上给分,在线等
- 我的机器死机后,发现图标颜色丢失,游戏运行的也很慢:(怎么办啊?
- 5/1祝大家心情好!放分100
- 兄弟们有没有什么经典的加解密文件算法,我给分150
- 求救,急
- 怎样在flexgrid中取得当前光标的位置?
- INI文件中的配置信息是明文,客户觉得不安全,请问大家一般是怎么处理的?
- 关于如何提高运行效率!
'按名称模糊查找
If Left(Text1.Text, 1) = ":" Then '[105]
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
LV1.ListItems.Clear
s = "select * from tmb where mc like '%" & Replace(Text1.Text, " ", "") & "%'"
RST.Open s, CNN
Do Until RST.EOF
LV1.ListItems.Add , , RST.Fields("mc").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = RST.Fields("dj").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(2) = 0
LV1.ListItems(LV1.ListItems.Count).SubItems(4) = RST.Fields("tm").Value
RST.MoveNext
Loop
Text1.Text = ""
Else '[105]
'--------------------------------------------------------------------------------------------------------------------------------------------------
If Right(Text1.Text, 1) = "." Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) '最后是点的,删了
If Text1.Text = Empty Then '[104]
If LV1.ListItems.Count > 0 And Shift = 1 Then '结帐
s = "select max(dh) as zddh from xcb" '营业表
RST.Open s, CNN
d = IIf(RST.Fields("zddh").Value > 0, RST.Fields("zddh").Value + 1, 1)
RST.Close
For i = 1 To LV1.ListItems.Count
s = "insert into xcb(dh,[date],mc,dj,sl,zj,tm) values(" & d & ",#" & Now & "#,'" & LV1.ListItems(i) & "'," & _
LV1.ListItems(i).SubItems(1) & "," & LV1.ListItems(i).SubItems(2) & "," & LV1.ListItems(i).SubItems(3) & "," & LV1.ListItems(i).SubItems(4) & ")"
RST.Open s, CNN
s = "select * from dmb where tm=" & CheckString(LV1.ListItems(i).SubItems(4)) '店面表
RST.Open s, CNN, 1, 3
If RST.RecordCount > 0 Then
'If RST.Fields("sl").Value > 0 Then
RST.Fields("sl").Value = IIf(RST.Fields("sl").Value > LV1.ListItems(i).SubItems(2), RST.Fields("sl").Value - LV1.ListItems(i).SubItems(2), 0) '减去相应的数量,以后还要完善
RST.Update
'End If
'Else
End If
RST.Close
Next i
LV1.ListItems.Clear
WritTextFile "结帐:" & d & "," & Now
StatusBar1.Panels(1).Text = "结帐完成"
End If
Else '[104]
'将输入信息赋值到数组------------------------------------------------------------------------------------------------------------------------------
arr() = Split(Text1.Text, ",")
If UBound(arr) < 1 Then Text1.Text = Text1.Text & ",0" '没有逗号,人工加上(这里不能&1,因为要做一个有无数量输入的判断)
arr() = Split(Text1.Text, ",")
Text1.Text = ""
'不在数据库查找的,直接加入------------------------------------------------------------------------------------------------------------------------
If IsNumeric(arr(0)) And IsNumeric(arr(1)) Then '当单价数量是数字时,分二行,减少错误
If arr(0) < 9999 And arr(0) > 0 And arr(1) < 9999 And arr(1) >= 0 Then '直接加入散装物品
LV1.ListItems.Add , , "散装物品"
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = arr(0) '单价
'LV1.ListItems(LV1.ListItems.Count).SubItems(2) = IIf(arr(1) = 0, 1, arr(1)) '数量
If arr(1) > 0 Then LV1.ListItems(LV1.ListItems.Count).SubItems(2) = arr(1) '数量
Text1.Text = "1"
End If
End If
'用SQL语句打开记录集-------------------------------------------------------------------------------------------------------------------------------
If Text1.Text <> "1" And IsNumeric(arr(1)) Then '[103]
s = "select * from tmb where tm=" & CheckString(Left(arr(0), 22)) '" & Left(arr(0), 22) & "'" '条码表
RST.Open s, CNN
'--------------------------------------------------------------------------------------------------------------------------------------------------
'If IsNull(RST.Fields("tm").Value) Then '条形码空
If RST.RecordCount = 0 Then 'Or (RST.RecordCount > 0 And RST.Fields("dj").Value = 0) Then '无记录 [101]
frmDB.Text1(0).Text = arr(0)
frmDB.Show
frmDB.Move Me.Left + Me.Width, 0
Else '以下有记录 [101]
If RST.Fields("dj").Value = 0 Then '有记录但单价为0,这里不能合到上面语句,否则要产生错误 [107]
frmDB.Text1(0).Text = arr(0)
frmDB.Show
frmDB.Move Me.Left + Me.Width, 0
Else '[107]
If RST.Fields("cm").Value = True Then '重码[102]
s = InputBox("货品重码,请输入单价:")
If s = "" Or Not IsNumeric(s) Then s = 0
If s < 9999 And s > 0 Then
LV1.ListItems.Add , , "重码物品"
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = s
StatusBar1.Panels(1).Text = "重码物品"
'Else
'StatusBar1.Panels(1).Text = "输入有误"
End If
Else '[102]
'--------------------------------------------------------------------------------------------------------------------------------------------------
Set Lvist1 = LV1.FindItem(RST.Fields("tm").Value, lvwSubItem)
If Lvist1 Is Nothing Then
B = 0
Else
Lvist1.Selected = True
B = LV1.SelectedItem.Index
End If
Set Lvist1 = Nothing
'For i = 1 To LV1.ListItems.Count
' If LV1.ListItems(i).SubItems(4) = RST.Fields("tm").Value Then '列表已有
' B = i
' Exit For
' End If
'Next i
'最常用的新扫描入来的物品--------------------------------------------------------------------------------------------------------------------------
If RST.Fields("szwp").Value = 0 Or arr(1) > 0 Then '[106]
If B = 0 Then '列表没有
LV1.ListItems.Add , , RST.Fields("mc").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = RST.Fields("dj").Value '单价
If arr(1) > 0 Then LV1.ListItems(LV1.ListItems.Count).SubItems(2) = arr(1) '数量
LV1.ListItems(LV1.ListItems.Count).SubItems(4) = RST.Fields("tm").Value '要此条码辨别列表是否存在
Else '列表已有
s = IIf(arr(1) = 0, 1, arr(1))
LV1.ListItems(B).SubItems(2) = Val(LV1.ListItems(B).SubItems(2)) + s
LV1.ListItems(B).SubItems(3) = LV1.ListItems(B).SubItems(1) * s + LV1.ListItems(B).SubItems(3)
End If 'If B = 0 Then '列表没有
Else '是散装计量物品[106]
s = InputBox("计量物品,请输入数量:", , 1)
If Not IsNumeric(s) Or s = "" Then s = 0 '这里要分二行,减少一个Err
If s > 9999 Then s = 0
'LV1.ListItems(LV1.ListItems.Count).SubItems(2) = IIf(IsNumeric(s) = True And s > 0 And s < 9999, s, 1) '数量
If s > 0 Then
If B = 0 Then '列表没有
LV1.ListItems.Add , , RST.Fields("mc").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = RST.Fields("dj").Value '单价
LV1.ListItems(LV1.ListItems.Count).SubItems(2) = s '数量
'If s = 0 Then LV1.ListItems.Remove LV1.ListItems.Count '删了
LV1.ListItems(LV1.ListItems.Count).SubItems(4) = RST.Fields("tm").Value '要此条码辨别列表是否存在
Else '列表已有
LV1.ListItems(B).SubItems(2) = Val(LV1.ListItems(B).SubItems(2)) + s
LV1.ListItems(B).SubItems(3) = LV1.ListItems(B).SubItems(1) * s + LV1.ListItems(B).SubItems(3)
End If
End If
End If '[106]
'--------------------------------------------------------------------------------------------------------------------------------------------------
If LV1.ListItems.Count > 0 Then StatusBar1.Panels(1).Text = "等待结帐"
End If '[102]
End If '[107]
End If '[101]
RST.Close
End If '[103]
Text1.Text = ""
End If '[104]
End If '[105]
以上代码有缩进吧,[107]是发现错误才添加的,有了编号方便准确
case ...
....
case ....
....
case ....
....
case else
....
end select
Text1.Text = Mid(Text1.Text, 1)
s = "select * from tmb where mc like '%" & Replace(Text1.Text, " ", "") & "%'"
RST.Open s, CNN
LV1.ListItems.Clear
Do Until RST.EOF
LV1.ListItems.Add , , RST.Fields("mc").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(1) = RST.Fields("dj").Value
LV1.ListItems(LV1.ListItems.Count).SubItems(2) = 0
LV1.ListItems(LV1.ListItems.Count).SubItems(4) = RST.Fields("tm").Value
RST.MoveNext
Loop
Text1.Text = ""
Exit Sub '退出过程,省去 Else 判断
End If
'--------------------------------------------------------------------------------------------------------------------------------------------------
If Text1.Text = Empty And LV1.ListItems.Count > 0 And Shift = 1 Then '结帐
s = "select max(dh) as zddh from xcb" '营业表
RST.Open s, CNN
d = IIf(RST.Fields("zddh").Value > 0, RST.Fields("zddh").Value + 1, 1)
RST.Close
For i = 1 To LV1.ListItems.Count
s = "insert into xcb(dh,[date],mc,dj,sl,zj,tm) values(" & d & ",#" & Now & "#,'" & LV1.ListItems(i) & "'," & _
LV1.ListItems(i).SubItems(1) & "," & LV1.ListItems(i).SubItems(2) & "," & LV1.ListItems(i).SubItems(3) & "," & LV1.ListItems(i).SubItems(4) & ")"
CNN.Execute s '不返回记录集的语句不要用打开记录集命令
s = "select * from dmb where tm=" & CheckString(LV1.ListItems(i).SubItems(4)) '店面表
RST.Open s, CNN, 1, 3
If Not RST.EOF Then
RST.Fields("sl").Value = IIf(RST.Fields("sl").Value > LV1.ListItems(i).SubItems(2), RST.Fields("sl").Value - LV1.ListItems(i).SubItems(2), 0) '减去相应的数量,以后还要完善
RST.Update
End If
RST.Close
Next i
LV1.ListItems.Clear
WritTextFile "结帐:" & d & "," & Now
StatusBar1.Panels(1).Text = "结帐完成"
Exit Sub
End If If InStr(Text1, ".") < 1 Then Text1.Text = Text1.Text & ",0" '没有逗号,人工加上(这里不能&1,因为要做一个有无数量输入的判断)
arr() = Split(Text1.Text, ",")
'......总之,写代码之前,要先做逻辑设计,不要写到哪里算哪里。
即便是有了缩进,当一大堆if endif混在一起的时候确实不好肉眼匹配
if …… Then
call ……
else
call ……
endif