Allen Pitts
asked on
VB6 contro structure, If
Good morning expert,
Currently in our payroll system, if the costr center number is 9 digits we display the first four digits of the cost center number as the plant number, 'current system' snippet below. We are adding Canadian plants that have 10 and 11 digit cost center numbers per 'new system' snippet below. But the way i wrote breaks the system. I also tried Else if for the new conditiosn but that didn't work either.
Thanks.
Allen in Dallas
Begin current system++++++++++++++++++++ ++
' Show plants with UN-CLOSED entries
vntPlants = objTimeEntry.RetrievePlant sWithOutRe cords (Session("intDB"),vntList( 0, lngCoCount), Session("EndDate"))
If isempty(vntPlants) = false Then
strOldPlantNumber = "" ' initialize to empty string
For lngCount = lbound(vntPlants, 2) to ubound(vntPlants, 2)
' strNewPlantNumber = Left(vntPlants(0, lngCount),3)
strNewPlantNumber = vntPlants(0, lngCount)
if len(strNewPlantNumber) = 9 then
strNewPlantNumber = Left(strNewPlantNumber,4)
else
strNewplantNumber = Left(strNewPlantNumber,3)
end if
If strOldPlantNumber <> strNewPlantNumber then
%></TR><TR><TD></TD><TD>Pl ant # <%Re sponse.wri te strNewPlantNumber%></td><T D></TD>
<TR><TD></TD><TD></TD><TD> <%
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
Else
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
End If
strOldPlantNumber = strNewPlantNumber
Next
End new system++++++++++++++++++++ ++
' Show plants with CLOSED entries
If isempty(vntPlants) = false Then
strOldPlantNumber = "" ' initialize to empty string
For lngCount = lbound(vntPlants, 2) to ubound(vntPlants, 2)
' strNewPlantNumber = Left(vntPlants(0, lngCount),3)
strNewPlantNumber = vntPlants(0, lngCount)
If len(strNewPlantNumber) = 9 then
strNewPlantNumber = Left(strNewPlantNumber,4)
If len(strNewPlantNumber) = 10 then
strNewPlantNumber = Left(strNewPlantNumber,5)
If len(strNewPlantNumber) = 11 then
strNewPlantNumber = Left(strNewPlantNumber,8)
else
strNewPlantNumber = Left(strNewPlantNumber,3)
end if
If strOldPlantNumber <> strNewPlantNumber then
%></TR><TR><TD></TD><TD>Pl ant # <%Re sponse.wri te strNewPlantNumber%></td><T D></TD>
<TR><TD></TD><TD></TD><TD> <%
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
Else
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
End If
strOldPlantNumber = strNewPlantNumber
Next
End new system++++++++++++++++++++ ++
Currently in our payroll system, if the costr center number is 9 digits we display the first four digits of the cost center number as the plant number, 'current system' snippet below. We are adding Canadian plants that have 10 and 11 digit cost center numbers per 'new system' snippet below. But the way i wrote breaks the system. I also tried Else if for the new conditiosn but that didn't work either.
Thanks.
Allen in Dallas
Begin current system++++++++++++++++++++
' Show plants with UN-CLOSED entries
vntPlants = objTimeEntry.RetrievePlant
If isempty(vntPlants) = false Then
strOldPlantNumber = "" ' initialize to empty string
For lngCount = lbound(vntPlants, 2) to ubound(vntPlants, 2)
' strNewPlantNumber = Left(vntPlants(0, lngCount),3)
strNewPlantNumber = vntPlants(0, lngCount)
if len(strNewPlantNumber) = 9 then
strNewPlantNumber = Left(strNewPlantNumber,4)
else
strNewplantNumber = Left(strNewPlantNumber,3)
end if
If strOldPlantNumber <> strNewPlantNumber then
%></TR><TR><TD></TD><TD>Pl
<TR><TD></TD><TD></TD><TD>
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
Else
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
End If
strOldPlantNumber = strNewPlantNumber
Next
End new system++++++++++++++++++++
' Show plants with CLOSED entries
If isempty(vntPlants) = false Then
strOldPlantNumber = "" ' initialize to empty string
For lngCount = lbound(vntPlants, 2) to ubound(vntPlants, 2)
' strNewPlantNumber = Left(vntPlants(0, lngCount),3)
strNewPlantNumber = vntPlants(0, lngCount)
If len(strNewPlantNumber) = 9 then
strNewPlantNumber = Left(strNewPlantNumber,4)
If len(strNewPlantNumber) = 10 then
strNewPlantNumber = Left(strNewPlantNumber,5)
If len(strNewPlantNumber) = 11 then
strNewPlantNumber = Left(strNewPlantNumber,8)
else
strNewPlantNumber = Left(strNewPlantNumber,3)
end if
If strOldPlantNumber <> strNewPlantNumber then
%></TR><TR><TD></TD><TD>Pl
<TR><TD></TD><TD></TD><TD>
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
Else
Response.write "<font color=" & Chr(34) & "#FF0000" & Chr(34) & ">" & vntPlants(0, lngCount) & "</Font>, "
End If
strOldPlantNumber = strNewPlantNumber
Next
End new system++++++++++++++++++++
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
^^ Gremlins :-D That should be Case 9, Case 10 & Case 11 of course.
Antagony has the best solution. The Select Case is cleaner and faster.
Explanation of failure:
If len(strNewPlantNumber) = 11 then
strNewPlantNumber = Left(strNewPlantNumber,8)
else
Since execution falls into this If statement after checking for lengths 9 and 10, the length=11 check is applied with no consideration for the immediately prior length checks.
Note: If implementing this with If statements, you would need ElseIf statements for the checks after 9.
Explanation of failure:
If len(strNewPlantNumber) = 11 then
strNewPlantNumber = Left(strNewPlantNumber,8)
else
Since execution falls into this If statement after checking for lengths 9 and 10, the length=11 check is applied with no consideration for the immediately prior length checks.
Note: If implementing this with If statements, you would need ElseIf statements for the checks after 9.
Can you define 'breaks the system', please? Is there an error message?