Link to home
Start Free TrialLog in
Avatar of Allen Pitts
Allen PittsFlag for United States of America

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.RetrievePlantsWithOutRecords (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>Plant&nbsp;#&nbsp;<%Response.write strNewPlantNumber%></td><TD></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>Plant&nbsp;#&nbsp;<%Response.write strNewPlantNumber%></td><TD></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++++++++++++++++++++++         
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Is this really VB6? If so, some of the code has not come out correctly. Try pasting it as a snippet.

Can you define 'breaks the system', please? Is there an error message?
ASKER CERTIFIED SOLUTION
Avatar of Antagony1960
Antagony1960

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Antagony1960
Antagony1960

^^ 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.