我正在创建一个配方来形成设备的名称。第一部分(Bname =" H"或Bname =" S")运作良好。第二部分(ElseIf Bname =" 04"或Bname = 4或Bname =" 03"或Bname =" 02"或Bname =" 01&# 34;或Bname =" 00"或Bname =" B"或Bname =" B1")没有响应。
我很确定此代码在早期版本2010中有效。任何人都可以建议代码出错了。
输入:
位置设备传感器
H-00-15-0-27 FCU-GF-03放电温度,
输出:
传感器名称出现
FCUGF03_H_00_15.0_27_DsTmp
Function Name_Alpha(Equipment_Tag As String, Sensor_Tag As String, Location_Tag As String) As String
Dim Bname As String
Dim Bname2 As String
Dim Bname3 As String
Dim Bname4 As String
Dim Bname5 As String
Dim EquipTag As Variant
Dim EquipTag2 As String
Dim EquipTag3 As String
Dim SensorTag As String
Bname = Split(Location_Tag, "-")(0)
Bname2 = Split(Trim(Split(Location_Tag, "-")(1)), "-")(0)
Bname3 = Split(Trim(Split(Location_Tag, "-")(2)), "-")(0)
Bname4 = Split(Trim(Split(Location_Tag, "-")(3)), "-")(0)
Bname5 = Split(Trim(Split(Location_Tag, "-")(4)), "-")(0)
EquipTag = Split(Equipment_Tag, "-")(0)
EquipTag2 = Split(Trim(Split(Equipment_Tag, "-")(1)), "-")(0)
EquipTag3 = Split(Trim(Split(Equipment_Tag, "-")(2)), "-")(0)
SensorTag = Split(Sensor_Tag, " ")(0)
If Bname = "H" Or Bname = "S" Then
If EquipTag = "FCU" Or EquipTag = "WMU" Then
If SensorTag = "TEMPERATURE" Then
Name_Alpha = EquipTag & EquipTag2 & EquipTag3 & "_" & Bname & "_" & Bname2 & "_" & Bname3 & "." & Bname4 & "_" & Bname5 & "_ZnTmp"
ElseIf SensorTag = "DISCHARGE" Then
Name_Alpha = EquipTag & EquipTag2 & EquipTag3 & "_" & Bname & "_" & Bname2 & "_" & Bname3 & "." & Bname4 & "_" & Bname5 & "_DsTmp"
End If
End If
ElseIf Bname = "04" Or Bname = 4 Or Bname = "03" Or Bname = "02" Or Bname = "01" Or Bname = "00" Or Bname = "B" Or Bname = "B1" Then
If EquipTag = "FCU" Or EquipTag = "WMU" Then
If SensorTag = "TEMPERATURE" Then
Name_Alpha = EquipTag & EquipTag2 & EquipTag3 & "_" & Bname & "_" & Bname2 & "_" & Bname3 & "." & Bname4 & "_ZnTmp"
ElseIf SensorTag = "DISCHARGE" Then
Name_Alpha = EquipTag & EquipTag2 & EquipTag3 & "_" & Bname & "_" & Bname2 & "_" & Bname3 & "." & Bname4 & "_DsTmp"
End If
End If
End If
End Function
答案 0 :(得分:1)
通过以下更改,可以正确使用您的测试数据:
更改
Dim EquipTag As Variant
要
Dim EquipTag As String
并改变
ElseIf Bname = "04" Or Bname = 4 Or Bname = "03" Or Bname = "02" Or Bname = "01" Or Bname = "00" Or Bname = "B" Or Bname = "B1" Then
到
ElseIf Bname = "04" Or Bname = "4" Or Bname = "03" Or Bname = "02" Or Bname = "01" Or Bname = "00" Or Bname = "B" Or Bname = "B1" Then