UPC


imports System
imports System.Diagnostics
Imports Microsoft.VisualBasic

Class EquationScript
inherits FcProcFuncSetEQ

Function evaluate() As Long
  Dim pCode as String
 If Context._OBJECTSYMBOL = "ITEM" Then
    pCode = ObjProperty("KeyCode")
 Else
    If Context._OBJECTSYMBOL = "FORMULA" Then
       pCode = ObjProperty("ItemCode")
 End If
 End If
   Dim pLen as Integer = pCode.Length
   If pLen = 5 Then
 Dim coCode as String = tparam("Company Code")
 Dim cLen as Integer = coCode.Length
 If cLen = 6 Then
   Dim upcCode as String = "10" & coCode & pCode
   Dim i, oddSum, evenSum as Integer
   For i = upcCode.Length - 1 to 0 Step -1
 If i Mod 2 = 0 Then
    evenSum = evenSum + CInt(upcCode.Substring(i, 1))
   Else
   oddSum = oddSum + CInt(upcCode.Substring(i, 1))
 End If
   Next i
 oddSum = oddSum * 3
 Dim codeSum as Integer = oddSum + evenSum
 Dim checkDigit as Integer = Math.Ceiling(codeSum/10) * 10
 checkDigit = checkDigit - codeSum
 Dim contextReturnValue As String = upcCode & checkDigit
 return upcCode & checkDigit
 End If
 End If
End Function
End Class