COM .NET interop in Classic ASP

[reference: link]

Advertisements

barcode code 128 in classic asp

ASP Version of code 128 barcode

just follow three easy step to create barcode code 128 in classic asp.

step 1. create object from function and call stringToBarcode with string value, function returns code 128 compatible string

step 2. use font code 128 from here http://www.jtbarton.com/Barcodes/Code128.aspx and install on web server

setp 3. use font “Code 128” to print output string from function

<% 	class barcode128 		
                    Public Function stringToBarcode (ByVal value) 			
                               stringToBarcode ="" 			
                               Dim charPos, minCharPos, currentChar, checkSum 			
                               Dim isTableB : isTableB = True 			
                               Dim isValid : isValid = True 			
                               Dim returnValue : returnValue = "" 			
                               currentChar = "" 			
                               If Len(value) > 0 Then
				' devermie validity of data
				For charCount = 1 To Len(value)
					currentChar = Asc(Mid(value, charCount, 1))
					If Not (currentChar >= 32 And currentChar <= 126) Then
						isValid = False
						Exit For 
					End if
				Next 
				If isValid = True Then
					charPos = 1
					Do While charPos =< Len(value)
						If isTableB = True Then
							If charPos = 1 Or charPos + 3 = Len(value) Then
								minCharPos = 4
							Else
								minCharPos = 6
							End If
							minCharPos = isNumber(value, charPos, minCharPos)
							If minCharPos =< 0 Then
								If charPos = 1 Then
									returnValue =  chr(205)
								Else
									returnValue = returnValue & chr(199)
								End If 
								isTableB = false
							Else
								If charPos = 1 Then
									returnValue = chr(204)
								End If 
							End If 
						End if
						If Not isTableB Then
							minCharPos = 2
							minCharPos = isNumber(value, charPos, minCharPos)
							If minCharPos < 0 Then
								currentChar = Mid(value, charPos, 2)
								If currentChar < 95 Then 
									currentChar = currentChar + 32 
								Else 
									currentChar = currentChar + 100 
								End if
								returnValue = returnValue & chr(currentChar)
								charPos = charPos + 2
							Else
								returnValue = returnValue & chr(200)
								isTableB = true
							End If
						End If 
						If isTableB = true Then
							returnValue = returnValue & Mid(value, charPos, 1)
							charPos = charPos + 1
						End If													
					Loop 
					checkSum = 0
					Dim loopVar : loopVar = 0
					For loopVar = 1 To Len(returnValue)
						currentChar = Asc(Mid(returnValue, loopVar,1))
						If currentChar < 127 Then 
							currentChar = currentChar - 32 
						Else 
							currentChar = currentChar - 100
						End if
						If loopVar = 1 Then 
							checkSum = currentChar 
						Else 
							checkSum = (checkSum + ((loopVar - 1 )* currentChar)) Mod 103							
						End if
					Next
					If checkSum < 95 Then checkSum = checksum + 32 Else checkSum = checkSum + 100
					returnValue = returnValue & Chr(checkSum) & Chr(206)					
				End if
			End If
			stringToBarcode = returnValue
		End Function 
		Public Function isNumber(ByVal inputValue, ByVal charPos, ByVal minCharPos)
			minCharPos = minCharPos - 1
			If (charPos + minCharPos) =< Len(inputValue) Then 				
                                Do While minCharPos >= 0
					var_1 = Asc(Mid(inputValue, charPos + minCharPos, 1))
					If var_1 < 48  Or var_1 > 57 Then
						Exit do
					End If
					minCharPos = minCharPos - 1					
				Loop 
			End If
			isNumber = minCharPos
		End Function 
	End class
%>

Just copy this above asp script and use as class and create object from class like as below

<%
dim barcodeobj
set barcodeobj = new barcode128
barcodetext = barcodeobj.stringtobarcode("12345678910")
%>

Import code128 font from above link and import using css3 font-face

@font-face
{
font-family: mybarcode128;
src: url('barcode128.ttf'),
url('barcode128.eot'); /* IE9 */
}
.barcodetext{
font-family: 'mybarcode128';
}

and use to display barcodetext

<div class="barcodetext"><%=barcodetext%></div>

cheers,