Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba ElseIf语句不应与“或”一起使用时跳过_Vba_Excel_Logic - Fatal编程技术网

Vba ElseIf语句不应与“或”一起使用时跳过

Vba ElseIf语句不应与“或”一起使用时跳过,vba,excel,logic,Vba,Excel,Logic,我正在建立一个小程序来帮助导入一些数据,并在网站上为我们的技术人员提供帮助 我正在努力解决的问题是bp检查,请参见下面的代码: Private Sub bphg_afterupdate() 'blood pressure values 'below 100/60 - low '120/70 - normal '140/90 - high, gp review '180/100 - high, cut off for fitness for driving '200/100 - high, cu

我正在建立一个小程序来帮助导入一些数据,并在网站上为我们的技术人员提供帮助

我正在努力解决的问题是bp检查,请参见下面的代码:

Private Sub bphg_afterupdate()

'blood pressure values
'below 100/60 - low
'120/70 - normal
'140/90 - high, gp review
'180/100 - high, cut off for fitness for driving
'200/100 - high, cut off for driving/spiro
'230/120 - urgent review required


    If bpmm <= 100 Or bphg <= 60 Then
        bpcomment.Value = "LOW! - Seek Advice"
    ElseIf bpmm < 140 Or bphg < 90 Then
        bpcomment.Value = "Normal BP"
    ElseIf bpmm < 180 Or bphg < 100 Then
        bpcomment.Value = "High! - GP Review"
    ElseIf bpmm < 200 Then
        bpcomment.Value = "High! - Temp restriction to driving MPE/FLT"
    ElseIf bpmm < 230 Or bphg < 120 Then
        bpcomment.Value = "High! - To high for Spiro & Temp Driving Resitricion MPE/FLT"
    Else
        bpcomment.Value = "URGENT! - Review required"
    End If

End Sub
它所做的是找到符合指定值的第一个值,然后停止。它应该继续检查其他标准

所以基本上,在医生给你的两个数字中,有一个可以确定你的血压是否正常。所以当我们在表格中输入一个bp,比如说200/80,你可能永远不会得到这个,但我正在通过,它会发现第一个数字是高的,第二个是正常的。然而,我的脚本首先发现第二个数字是正常的,而没有检查第一个数字,因此它只是在事实上是高的时候显示正常。

选择病例是处理血压问题的更好方法:

Option Explicit

Public Sub TestMe()

    Dim bpmm        As Long
    Dim bphg        As Long

    bpmm = 100   'assign these two somehow. E.g.-> bpmm = ActiveSheet.Range("A1")
    bphg = 100

    Select Case True
        Case bpmm <= 100 Or bphg <= 60
            Debug.Print "LOW! - Seek Advice"
        Case bpmm < 140 Or bphg < 90
            Debug.Print "Normal BP"
        Case bpmm < 180 Or bphg < 100
            Debug.Print "High!"
        Case Else
            Debug.Print "URGENT! - Review required"
    End Select

End Sub

根据您的描述,您似乎希望返回两个条件中最高的一个的结果。在这种情况下,您需要颠倒检查顺序:

If bpmm >= 230 Or bphg >= 120 Then
    bpcomment.Value = "URGENT! - Review required"
ElseIf bpmm >= 200 Then
    bpcomment.Value = "High! - To high for Spiro & Temp Driving Resitricion MPE/FLT"
ElseIf bpmm >= 180 Or bphg >= 100 Then
    bpcomment.Value = "High! - Temp restriction to driving MPE/FLT"
ElseIf bpmm >= 140 Or bphg >= 90 Then
    bpcomment.Value = "High! - GP Review"
ElseIf bpmm >= 120 Or bphg >= 70 Then
    bpcomment.Value = "Normal BP"
Else
    bpcomment.Value = "LOW! - Seek Advice"
End If
但是,从说明中不清楚,在100/60和120/70之间的情况下,函数顶部有什么操作。上面的代码认为它很低。如果你想把它看作是正常的,那么把最后一个ELSIF改为:

致:


如果使用Select用例,您的代码会更干净。测试的bpmm和bphg是什么?理想情况下,可以将这些值作为参数传递给方法。代码乍一看很好。如果逻辑停止,这是由于这些全局变量的值。bpmm和bphg是文本框,用户completesCode对我来说工作正常。你没有给我们看的代码呢?我想如果。。。很好,这是整个sub,而不是表单。@JamesFenwick-请确保您正确地排序条件-如果第一个条件为真,检查将不会进一步。因此,我尝试了这个方法,并将其余的添加到中,它仍然会给我相同的问题。测试值为bpmm=240和bphg=80。它找到80显示答案,然后结束。谢谢你,有点道理,实际上,我会测试它。
If bpmm >= 230 Or bphg >= 120 Then
    bpcomment.Value = "URGENT! - Review required"
ElseIf bpmm >= 200 Then
    bpcomment.Value = "High! - To high for Spiro & Temp Driving Resitricion MPE/FLT"
ElseIf bpmm >= 180 Or bphg >= 100 Then
    bpcomment.Value = "High! - Temp restriction to driving MPE/FLT"
ElseIf bpmm >= 140 Or bphg >= 90 Then
    bpcomment.Value = "High! - GP Review"
ElseIf bpmm >= 120 Or bphg >= 70 Then
    bpcomment.Value = "Normal BP"
Else
    bpcomment.Value = "LOW! - Seek Advice"
End If
ElseIf bpmm >= 120 Or bphg >= 70 Then
ElseIf bpmm >= 100 Or bphg >= 60 Then