我有一个如下表,我在每列中填充了“通过”和“失败”记录的数量。然后,我尝试计算每列的故障率以及 3 个“IR Room”设备和 3 个“Employee Exit”设备的平均故障率。
我正在使用本文底部的代码填充标签,但是我有两个问题:-
我在第 86 行收到“输入字符串格式不正确”错误(将 irAverageFailureRate 调暗为字符串)
我不禁想到有更好的方法来做到这一点。我是 ASP/VB 的新手,因此我们将不胜感激地收到任何有关如何改进它的建议。
Sub getYesterdayStats() Dim con As OleDbConnection Dim cmdClockings As OleDbDataAdapter Dim dsClockings As New DataSet Dim yesterday As String = DateTime.Today.AddDays(-1).ToString("yyyy/MM/dd") con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=\\XXX.XX.XXX.XX\XXXX.mdb;Jet OLEDB:Database Password=XXXXX;") cmdClockings = New OleDbDataAdapter("SELECT efrLog.PID, efrLog.LType, efrLog.LDName from efrLog WHERE LDate = '" & yesterday & "'", con) cmdClockings.Fill(dsClockings, "Clockings") ' Get pass and fail count for each device Dim ir1Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'IR Room 1'").Count Dim ir1Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'IR Room 1'").Count Dim ir2Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'IR Room 2'").Count Dim ir2Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'IR Room 2'").Count Dim ir3Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'IR Room 3'").Count Dim ir3Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'IR Room 3'").Count Dim ee1Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'Employee Exit 1'").Count Dim ee1Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'Employee Exit 1'").Count Dim ee2Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'Employee Exit 2'").Count Dim ee2Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'Employee Exit 2'").Count Dim ee3Pass As Integer = dsClockings.Tables("Clockings").Select("LType = 'PASS' AND LDName = 'Employee Exit 3'").Count Dim ee3Fail As Integer = dsClockings.Tables("Clockings").Select("LType = 'DENY' AND LDName = 'Employee Exit 3'").Count ' Calculate totals for each device Dim ir1total As Integer = ir1Pass + ir1Fail Dim ir2total As Integer = ir2Pass + ir2Fail Dim ir3total As Integer = ir3Pass + ir3Fail Dim ee1total As Integer = ee1Pass + ee1Fail Dim ee2total As Integer = ee2Pass + ee2Fail Dim ee3total As Integer = ee3Pass + ee3Fail ' Calcualte failure rate for each device Dim ir1failureRate As String = Format((ir1Fail / ir1Pass) * 100, "0.00") Dim ir2failureRate As String = Format((ir2Fail / ir2Pass) * 100, "0.00") Dim ir3failureRate As String = Format((ir3Fail / ir3Pass) * 100, "0.00") Dim ee1failureRate As String = Format((ee1Fail / ee1Pass) * 100, "0.00") Dim ee2failureRate As String = Format((ee2Fail / ee2Pass) * 100, "0.00") Dim ee3failureRate As String = Format((ee3Fail / ee3Pass) * 100, "0.00") ' Calculate average failure rate for IR and EE devices Dim irAverageFailureRate As String = Format((Format((ir1Fail / ir1Pass) * 100, "0.00") + Format((ir2Fail / ir2Pass) * 100, "0.00") + Format((ir3Fail / ir3Pass) * 100, "0.00")) / 3, "0.00") Dim eeAverageFailureRate As String = Format((Format((ee1Fail / ee1Pass) * 100, "0.00") + Format((ee2Fail / ee2Pass) * 100, "0.00") + Format((ee3Fail / ee3Pass) * 100, "0.00")) / 3, "0.00") ' Assign values to labels lblIR1pass.Text = ir1Pass lblIR1fail.Text = ir1Fail lblIR2pass.Text = ir2Pass lblIR2fail.Text = ir2Fail lblIR3pass.Text = ir3Pass lblIR3fail.Text = ir3Fail lblEE1pass.Text = ee1Pass lblEE1fail.Text = ee1Fail lblEE2pass.Text = ee2Pass lblEE2fail.Text = ee2Fail lblEE3pass.Text = ee3Pass lblEE3fail.Text = ee3Fail lblIR1tot.Text = ir1total lblIR2tot.Text = ir2total lblIR3tot.Text = ir3total lblEE1tot.Text = ee1total lblEE2tot.Text = ee2total lblEE3tot.Text = ee3total lblIR1fr.Text = ir1failureRate & "%" lblIR2fr.Text = ir2failureRate & "%" lblIR3fr.Text = ir3failureRate & "%" lblEE1fr.Text = ee1failureRate & "%" lblEE2fr.Text = ee2failureRate & "%" lblEE3fr.Text = ee3failureRate & "%" lblIRafr.Text = irAverageFailureRate & "%" lblEEafr.Text = eeAverageFailureRate & "%"
结束子