VBA - Excel类功能 - 逻辑

时间:2017-11-16 20:23:11

标签: vba excel-vba class excel

使用VBA对员工课程记录进行排序。我有一个员工班,我正在努力识别满足条件的人“有这个但不是那个”。除了我在<?php $rowe = 0; $exploded; $data; $ass = 0; $hardcore[0][0]; $swag = 0; if (($handle = fopen("price_list_EN.csv", "r")) !== FALSE) { $ass = 0; $swag++; while (($linebyline = fgetcsv($handle, 1000, ",")) !== FALSE) { //$linebyline = explode(",", $linebyline); $hardcore[$rowe][$ass] = $linebyline[$ass]; //echo $linebyline[$ass]; $exploded[$rowe][$ass] = $hardcore[$rowe][$ass]; //echo $exploded[$rowe][$ass]; //while (($explode = fgetcsv($linebyline, 1000, ",")) !== FALSE) { $num = count($data); if ($ass == count($linebyline)){ echo "<br>"; $ass = 0; $rowe++; }else{ $ass++; } } //} fclose($handle); } //$linebyline = explode("\n", $_POST['message']); //$linebyline = explode("\n", $data2); //echo count($data2); $imo=0; $normovalue=0; $normovalue2=0; $normovalue3=0; for ($i=0;$i<30000;$i++){ if ($exploded[$i][0] == ''){ $imo = $i; } } for ($rowe=0;$rowe<$imo;$rowe++){ for ($ass=0;$ass<9;$ass++){ //$exploded = explode(";", $linebyline[$i]); $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Not connected : ' . mysql_error()); } // make foo the current db $db_selected = mysql_select_db('moday', $link); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } } if ($exploded[$rowe][0] !== "" || $exploded[$rowe][4] !== "" || $exploded[$rowe][3] !== "" || $exploded[$rowe][1] !== ""){ $productid = $exploded[$rowe][0]; $price = round($exploded[$rowe][4],2); $disponibilita = $exploded[$rowe][3]; $indir = "null"; $descrizione = $exploded[$rowe][1]; $conn = new mysqli("localhost", "root", "", "moday"); $sql = "SELECT productid from data where productid='$productid'"; $result = $conn->query($sql); if ($result->num_rows == 0) { mysql_query("INSERT INTO data(productid,price,disponibilita,indir,descrizione) values('$productid','$price','$disponibilita','$indir','$descrizione')") or die("Query non valida: " . mysql_error()); $normovalue++; }else{ // output data of each row while($row = $result->fetch_assoc()) { if ($row["productid"] == $productid){ echo "here ". $row["productid"] ." - ". $productid .""; if ("$exploded[$rowe][0] == '' || $exploded[$rowe][1] == '' || $exploded[$rowe][3] == '' || $exploded[$rowe][4] == '' || $exploded[$rowe][2] == ''|| $exploded[$rowe][5] hh "){ echo $exploded[$rowe][0]; echo $rowe; } echo "<br /> \n"; $sql2 = "UPDATE data SET price='$price', disponibilita='$disponibilita' where productid='$productid'"; $normovalue2++; $result2 = $conn->query($sql2); }else{ } } } /*$risultato = mysql_query("INSERT INTO data(productid,price,disponibilita,indir,descrizione) values('$productid','$price','$disponibilita','$indir','$descrizione')") or die("Query non valida: " . mysql_error()); */ //echo "<br /> \n" } } $normovalue3 = $normovalue + $normovalue2; echo "N.1 is $normovalue 2 is $normovalue2 3 is $normovalue3"; ?> 中的条件测试之外,我已经完成了代码并且所有工作都很好。相关代码:

BlsHasIssue()

我遗漏了正确设置''''''''''''' 'clsEmployee' ''''''''''''' Option Explicit Private empID As String Private name As String Private hasBLSComp As Boolean Private hasBLSAssignment As Boolean Public Property Let id(value As String) empID = value End Property Property Get id() As String id = empID End Property Public Property Let setName(value As String) name = value End Property Public Property Get getName() As String getName = name End Property Public Sub addResusRecord(value As String) 'accepts name of course Select Case value Case "BLS Assignment": hasBLSAssignment = True Case "BLS Competency": hasBLSComp = True End Select End Sub Public Function BlsHasIssue() As Boolean If hasBLSComp And Not hasBLSAssignment Then BlsHasIssue = True Else BlsHasIssue = False End If End Function '''''''' 'Module' '''''''' Option Explicit Const STUDENT_NAME_COL As Integer = 3 Const USER_ID_COL As Integer = 4 Const COURSE_NAME_COL As Integer = 5 Public Function Contains(col As Collection, key As Variant) As Boolean Dim obj As Variant On Error GoTo err Contains = True IsObject (col(key)) Exit Function err: Contains = False End Function Sub ResusCardAudit() Dim row As Long Dim currEmpID As String Dim employees As New Collection Dim emp As Object For row = 2 To 5 'change to be last row of data 'Check to see if user exists in collection currEmpID = Cells(row, USER_ID_COL).value If Not Contains(employees, currEmpID) Then 'create User and add it to collection Set emp = New clsEmployee emp.id = currEmpID emp.setName = Cells(row, STUDENT_NAME_COL) emp.addResusRecord Cells(row, COURSE_NAME_COL) employees.Add emp, currEmpID Else employees.Item(currEmpID).addResusRecord Cells(row, COURSE_NAME_COL) End If Next row 'cycle through all employees and determine if any have a comp but not an assignment Set emp = New clsEmployee row = 2 For Each emp In employees If emp.BlsHasIssue Then row = row + 1 End If Next emp 'if they do, add their details to a new sheet named "Results" End Sub hasBLSComp的代码。在测试hasBLSAssignment.时,问题似乎是一个逻辑错误。带我到这里的测试是emp.BlsHasIssue为真且hasBLSComp为假 - > hasBLSAssignment导致错误。

注意:BlsHasIssue()为True且hasBLSAssignment为假是可以接受的。

思想?

1 个答案:

答案 0 :(得分:0)

感谢所有帮助。这是我测试用例中的错误 - 我将测试设置为我认为的相反。在确定某些问题之前,这有助于我认识到(有效的)多个测试用例的重要性。

基于对我的问题的回答:我将停止隐藏测试记录中的问题的简单逻辑并将其带到模块级别。我相信这将有助于我避免在代码扩展时出现问题。