Published: Friday, August 25, 2000
Dynamically Generating I25 Bar Codes, Part 2
By Daniel Goncalves
Read Part 1
In Part 1 we looked at creating the I25Encode() function.
We now need to write our ASP code that will take the results of this function and display the correct bar
codes!
Creating An Apropriated Graphics Set
Now we must create a simple graphics (GIF) set. One for the narrow bar (black, 2 pixels wide), one for the
narrow space (white, 2 pixels wide), one for the wide bar (black, 4 pixels wide) and one for the wide space
(white 4 pixels wide), all these graphics can have 39 pixels height or more. I have included a
ZIP file
containing these graphics. The file names are:
| File Name | Description | Image |
nb.gif | Narrow bar |  |
ns.gif | Narrow space |  |
wb.gif | Wide bar |  |
ws.gif | Wide space |  |
These graphics will be used to generate the resulting HTTP that will mount the full barcode through
<IMG ...> tags.
Writing The Final Code
Now we'll write the final code. This code will read the string returned by I25Encode() function
and generate the resulting HTTP using our gifs. (While I don't show the I25Encode() function in
the script below, it must be included (either cut and pasted into the file or via a
server-side include.)
<HTML>
<HEAD><TITLE>Interleaved 2-of-5 Example</TITLE></HEAD>
<%
' Ensure that the I25Encode function is in this file...
' (For this example it has been removed for brevity
%>
<BODY BGCOLOR='#FFFFFF'>
<P><FONT FACE='Verdana, Arial' SIZE='1'>
Enter the number to be encoded as Interleaved 2-of-5 Specification.
</FONT></P>
<FORM NAME='I25' ACTION='i25.asp' METHOD='post'>
<INPUT TYPE='text' NAME='txtNUM'>
<INPUT TYPE='hidden' NAME='hidFORM' VALUE='fromFORM'>
<INPUT TYPE='submit'>
</FORM>
<P> </P>
<P><FONT FACE='Verdana, Arial' SIZE='1'>
<%
If Request("hidFORM") = "fromFORM" Then
sMyI25 = I25Encode(Request("txtNUM"))
If (sMyI25 = "") Then
Response.Write """" & Request("txtNUM") & _
""" is invalid. Try another number."
Else
Dim iPos, sGIF, bBAR
bBAR = True
For iPos = 1 To Len(sMyI25)
If (bBar) Then
'Bar
sGIF = Mid(sMyI25, iPos, 1) & "b.gif"
Else
'Space
sGIF = Mid(sMyI25, iPos, 1) & "s.gif"
End If
Response.Write "<IMG SRC='" & sGIF & "'>"
bBar = Not bBar
Next
End if
End If
%>
</FONT></P>
</BODY>
</HTML>
|
(If you are interested in seeing the
results, go ahead and give the live demo a whirl!)
Well done and Happy Programming!
By Daniel Goncalves
Attachments:
Try the live demo!
View the source for the I25Encode function in text format
Download the Bar graphics in ZIP format
Read Generating Dynamic Bar Code on a Web Page (using Code 39 barcodes)