注册 登录
编程论坛 VB6论坛

新人剛接觸,請大佬幫忙解惑,我底下If (floor = 2)的語句不執行,怎麼寫才能整個判斷執行,謝謝!

tianxia978 发布于 2020-11-20 18:22, 2165 次点击
Private Sub show_gd_son8(PCBNO As String)
Dim Rs                        As New ADODB.Recordset
Dim strSql                    As String

    strSql = " select SUBSTRING(PcbNo,6,1) as floor ,PlatLength/25.4 as PlatLength,PlatWidth/25.4 as PlatWidth " & _
    " from  cyerp.dbo.tblEng_WorkDirection_Plating " & _
    " where SH_Status=1 and PcbNo='" & Trim(PCBNO) & "'  "
   
    If Rs.State = adStateOpen Then Rs.Close
    With Rs
       .Source = strSql
       .Open , gConnection, adOpenStatic, adLockReadOnly, 1
    End With
    If Rs.EOF Then
    Exit Sub
    End If
      
    floor = Rs.Fields("floor").Value
    PlatLength = Rs.Fields("PlatLength").Value
    PlatWidth = Rs.Fields("PlatWidth").Value
      
    If floor > 2 Then
    strSql = " select YaheWLen as WLen,YaheJLen as JLen from  cyerp.dbo.tblEng_WorkDirection_PressMerge " & _
    " where SH_Status=1 and PcbNo='" & Trim(PCBNO) & "'  "

    End If

    If Rs.State = adStateOpen Then Rs.Close
    With Rs
        .Source = strSql
        .Open , gConnection, adOpenStatic, adLockReadOnly, 1
    End With
    If Rs.EOF Then
    Exit Sub
    End If

    WLen = Rs.Fields("WLen").Value
    JLen = Rs.Fields("JLen").Value

    If (PlatLength <> WLen) Or (PlatWidth <> JLen) Then
    MsgBox "多層板壓合撈邊尺寸有誤", vbOKOnly, "警告"
    End If
   
 
    If (floor = 2) Then
    strSql = " select cutlengthIn,cutwidthIn from  cyerp.dbo.tblEng_WorkDirection_Cutter " & _
    " where SH_Status=1 and PcbNo='" & Trim(PCBNO) & "' "
    End If
   
    If Rs.State = adStateOpen Then Rs.Close
    With Rs
        .Source = strSql
        .Open , gConnection, adOpenStatic, adLockReadOnly, 1
    End With
    If Rs.EOF Then
    Exit Sub
    End If

   cutlengthIn = Rs.Fields("cutlengthIn").Value
   cutwidthIn = Rs.Fields("cutwidthIn").Value

   If (PlatLength<> cutlengthIn) Or (PlatWidth<> cutwidthIn) Then

   MsgBox "雙層板開料尺寸有誤", vbOKOnly, "警告"

   End If


[此贴子已经被作者于2020-11-20 18:25编辑过]

9 回复
#2
cwa99582020-11-21 08:33
你在这个语句上设置个断点,看看有没有运行到这条语句,看看floor的值是多少。
#3
tianxia9782020-11-21 08:50
回复 2楼 cwa9958
上面floor>2的可以拿到,並且能夠執行,從floor=2 開始就出問題了,難道我得從寫一個floor=2的方法?我想寫在一個方法里分別判斷執行的,
#4
cwa99582020-11-21 10:28
我就是确定你的有没有运行到这一句。
还有,刚才没有仔细看,你的程序的逻辑有问题。
改为这样试试看。
程序代码:
If floor > 2 Then
    strSql = " select YaheWLen as WLen,YaheJLen as JLen from  cyerp.dbo.tblEng_WorkDirection_PressMerge " & _
    " where SH_Status=1 and PcbNo='" & Trim(PCBNO) & "'  "

    If Rs.State = adStateOpen Then Rs.Close
    With Rs
        .Source = strSql
        .Open , gConnection, adOpenStatic, adLockReadOnly, 1
    End With
    If Rs.EOF Then
    Exit Sub
    End If

    WLen = Rs.Fields("WLen").Value
    JLen = Rs.Fields("JLen").Value

    If (PlatLength <> WLen) Or (PlatWidth <> JLen) Then
    MsgBox "多層板壓合撈邊尺寸有誤", vbOKOnly, "警告"
    End If
   
  End If

 
  If (floor = 2) Then
    strSql = " select cutlengthIn,cutwidthIn from  cyerp.dbo.tblEng_WorkDirection_Cutter " & _
    " where SH_Status=1 and PcbNo='" & Trim(PCBNO) & "' "
   
    If Rs.State = adStateOpen Then Rs.Close
    With Rs
        .Source = strSql
        .Open , gConnection, adOpenStatic, adLockReadOnly, 1
    End With
    If Rs.EOF Then
    Exit Sub
    End If

   cutlengthIn = Rs.Fields("cutlengthIn").Value
   cutwidthIn = Rs.Fields("cutwidthIn").Value

   If (PlatLength<> cutlengthIn) Or (PlatWidth<> cutwidthIn) Then

   MsgBox "雙層板開料尺寸有誤", vbOKOnly, "警告"

   End If

 End If
#5
ZHRXJR2020-11-21 11:42
既然 If floor > 2 Then 以后的语句能够执行,说明 floor 的值是大于 2 的,那么 If (floor = 2) Then 以后的语句肯定不会执行了。
如果 floor 的值 = 2,那么仅仅执行的是  If (floor = 2) Then 以后的语句,而 If floor > 2 Then 以后的语句就不会执行了。
如果  floor 的值 < 2,那么  If floor > 2 Then 与  If (floor = 2) Then 以后的语句均不会执行了。
因此关键是 floor 的值决定程序应该执行那些语句,不执行那些语句的。其他的没有详细看,如果还要什么问题,再探讨。
#6
tianxia9782020-11-21 13:49
回复 4楼 cwa9958
多謝大哥,你的代碼幫我去掉了end if 之後現在都能根據條件執行了,滿足了我的需求。
在幫我看看這個圖片   
只有本站会员才能查看附件,请 登录
  的問題能弄好嗎,執行時提示automation 錯誤,找不到知道你個模組。
#7
tianxia9782020-11-21 13:51
回复 5楼 ZHRXJR
謝謝幫我分析阿。
#8
cwa99582020-11-21 15:12
回复 6楼 tianxia978
不是去掉了endif,是挪了地方了。
你原来的代码逻辑有问题。

现在的错误,只有图片,谁也不知道是什么问题。错误出在哪个代码上,是什么情况下出的错误

[此贴子已经被作者于2020-11-21 15:15编辑过]

#9
tianxia9782020-11-21 15:39
回复 8楼 cwa9958
原本這個程式在別的電腦上點擊預覽會調出EXCEL都正常,不會報錯,我電腦沒安裝VB,安裝之後把那個程式拷到我電腦上運行點擊預覽就報automation錯誤,找不到指定模組,也不知道是沒配置好還是沒有引用什麽插件,還是電腦缺失文件,反正已經重裝了軟件4次了。網上搜了一下regsvr32 MSINET.OCX註冊,也不起作用。
#10
l满满2020-11-26 14:34
刚好我也新手,白瞟
1