VBScript如果Instr带有记录集

时间:2018-01-31 13:55:22

标签: vbscript compare recordset

我正在尝试使用VBScript中的记录集执行if语句来执行"喜欢"比较记录集。

While Not rs.EOF
    result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
             " background-color: " & RowColors(number mod 2) & "'>" &_
             Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
             Tdc(ChooseStatusColor(rs("Backup Status"))) & _
             Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
             Td(rs("Last Backup End")) & _
             If InStr(rs("Next Backup"), "*M") > 0 Then Td(rs("Next Backup")) Else Td(rs("Next Backup")) & "12:00:00 AM" & _
             End If &_
             "</tr>"
    rs.MoveNext
    number = number + 1
Wend

如果我只使用Td(rs("Next Backup")) & "12:00:00 AM" &_它可以正常工作,但如果我添加比较If Instr(rs("Next Backup"), "*M") > 0 then Td(rs("Next Backup")) Else Td(rs("Next Backup")) & "12:00:00 AM" &_,我会收到VB编译错误。我不确定这个逻辑中的错误在哪里,或者我甚至可以在InStr函数中使用记录集。我在这里做错了什么?

当我使用多行时,我得到相同的结果:

While Not rs.EOF
    result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
             " background-color: " & RowColors(number mod 2) & "'>" & _
             Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
             Tdc(ChooseStatusColor(rs("Backup Status"))) & _
             Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
             Td(rs("Last Backup End")) & _
             If InStr(1, (rs("Next Backup")), "*M") > 0 Then & _
             Td(rs("Next Backup")) & _
             Else Td(rs("Next Backup")) & "12:00:00 AM" & _
             End If &_
             "</tr>"
    rs.MoveNext
    number = number + 1
Wend

1 个答案:

答案 0 :(得分:2)

你不能在VBScript中内联条件。将您的代码更改为以下内容:

While Not rs.EOF
    result = result & "<tr style='" & FontStyle(FontFamily, FontSize) & _
             " background-color: " & RowColors(number mod 2) & "'>" & _
             Tdc(number) & Td(rs("Name")) & Tdc(rs("Machine Type")) & _
             Tdc(ChooseStatusColor(rs("Backup Status"))) & _
             Tdc(rs("Backup State")) & Td(rs("Last Backup Start")) & _
             Td(rs("Last Backup End"))
    If InStr(rs("Next Backup"), "M") > 0 Then
        result = result & Td(rs("Next Backup"))
    Else
        result = result & Td(rs("Next Backup") & "12:00:00 AM")
    End If
    result = result & "</tr>"
    rs.MoveNext
    number = number + 1
Wend