Using Barcode ActiveX Plus with a Perl CGI Script

“CGI” stands for “Common Gateway Interface”. CGI is a popular method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. A CGI can be written in any programming language, but Perl is the most popular.

System Requirements

  • PERL 5 or later for Windows.
  • A Microsoft Windows based Server running either Microsoft Personal Web Server (PWS) or Microsoft Internet Information Server (IIS).
  • TAL Bar Code ActiveX Control (Plus version).
  • Microsoft Internet Explorer 4.01 or higher (recommended)
  • Microsoft Visual Basic 6.0 (To create and compile your own VB program)

While investigating how to create server side bar codes, we found that it is possible to use Perl CGI code to do the job however it was also determined that using Active Server Pages is far easier, quicker and requires less work to implement. Since we had developed a method of using a Perl CGI Script (with some help from a compiled Visual Basic program) to achieve the same results as our ASP page example, we have included here.

How it Works

The user completes an HTML form with information about the bar code they wish to create, such as the symbology, the text to be encoded, the text for the comment, etc. and submits the information to the server.

This information is decoded by the Perl script and passed to an executable program, written in Visual Basic. The VB program generates a bar code to the visitors’ specifications and saves it as an image file with a unique filename. The unique filename is based on a number, generated by the Perl script using a file called “Counter.txt”. Counter.txt contains nothing more than a number, which the Perl script reads into a variable called “$COUNT”. Count is then incremented and the text file updated. The script then passes the number to the VB program along with the form data.

The VB program also generates some HTML that can be used to display the image the correct size in the visitors browser, and saves it to a text file. The Perl Script opens this text file and copies the HTML from it as it generates the page to display in the Browser.

Using this Example

  1. Download, unzip and install Perl 5
  2. Configure your Web Server to run Perl Scripts
  3. Download the files discussed in the example below. This is a self extracting zip file containing the HTML form, Perl script, Visual Basic project files, the compiled program for those of you who do not have Visual Basic, but would still like to test it, and the “counter” file.
  4. Extract the files. Copy “Getbarcode.exe”,”Barcode.pl” and “counter.txt” into your “Scripts” folder (usually “C:WebshareScripts”).
  5. Copy “perlForm.htm” into the root directory of your web site (usually C:WebshareWwwroot).
  6. Open your Web browser and type in “http://your.Server.name/perlForm.htm” into the address line, change the properties that interest you on the form, and submit it. You should be rewarded with a barcode. If you are not, check out the troubleshooting section at the end of this document.
  7. If you have Visual Basic 6 you can open the VB project and make changes to the “Getbarcode” program and recompile it. (If you have an older version of Visual Basic you may not be able to open the project but can still import the form and the module, or copy and paste the code from this page into your own project).

Sample HTML Form Code

Click here for the sample code for building an HTML Form.

Sample Perl Script

# Tell the server that this is a Perl Script, and where to find the Perl interpreter.

 # This should point to your Perl location

#!C:/Perl5/bin/perl.exe

# This is a content header that tells the receiving web browser what sort of data it is about to receive, in this case an HTML document. (If you omit this line you will receive an internal server error in your Browser when the script is run).
print "Content-type:text/htmlnn";
# Decode data from form - The following routine is a standard piece of code used to decode form data submitted via the POST method and can be reused without any needfor modification:
#################### Start decoding data ##################
# We're using Perl's read function to store the data into a variable called "$buffer". The read function has 3 arguments: read(FILEHANDLE, $variable, $length). The input stream is coming over STDIN (standard input), we're storing the data in a variable called $buffer, and the length of the data is determined by the Server's Environment Variable "CONTENT_LENGTH".
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Next we split the buffer into an array of pairs:
@pairs = split(/&/, $buffer);

# The data pairs are separated by "&" signs when they are transmitted, such as 
# fname=joe&lname=smith. Now we'll use a foreach loop to further split each pair: 
foreach $pair (@pairs) {

# First using using the "=" sign:
($name, $value) = split(/=/, $pair);
# next we translate every "+" sign back into a space:
$value =~ tr/+/ /;

# The next line is a rather complicated expression that substitutes every %HH 
# hex pair back to its equivalent ASCII character by using the pack() function: 

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/e.g.;

# Finally, we store the values into a hash variable called %FORM (a hash is a 2 dimensional array which is used to pair elements - a key and a data value). For example, in the %FORM hash we are storing the name of the field and the value of that field. Suppose you have a form with a text box called "FirstName" and the user types in "Joe" and submits the form to be processed by this script. When this routine decodes the data the %FORM hash would look like this:

# %FORM = ("FirstName", "Joe")
# In order to print "your firstname is Joe" onto the HTML page you would type: 
# print "your firstname is $FORM{$FirstName}";

$FORM{$name} = $value;
}

##################### End Decoding Data ########################

# To simplify referring to the form data later in the script you can store each form field into a new variable name:

$message = $FORM{'txtMessage'};
$scrHeight = $FORM{'scrHeight'};
$scrWidth = $FORM{'scrWidth'};
$Browser = $FORM{'Browser'};
$Version = $FORM{'Version'};
$Comment = $FORM{'txtComment'};
$CommentAlign = $FORM{'commentalignment'};
$Barheight = $FORM{'barheight'};
$Narrowbarwidth = $FORM{'narrowbarwidth'};
$Symbology = $FORM{'symbology'};
$Rotation = $FORM{'rotation'};
$Forecolor = $FORM{'forecolor'};
$Backcolor = $FORM{'backcolor'};
$Quietzones = $FORM{'quietzones'};
$Bearerbars = $FORM{'bearerbars'};

# Insert Header HTML:

print "";

# Alternatively, if you had a text file containing your HTML header information (Perhaps you have a standard header on every page of your site containing logos and JavaScript etc.,) you could 'import' it using the following code rather than reproduce it all here:

# Read the file "header.txt" into a variable called "INF". Note: "header.txt is assumed in this case to be in the same folder as the executing script, usually the "cgi-bin" folder.

# open(INF,"header.txt");

# Convert INF into an array variable called "@ary"
# @ary = ;

# Close the file header.txt
# close(INF);
# for each line in @ary...
# foreach $line(@ary){

# remove trailing line feeds
# chomp($line);

# print the line to the HTML file we are creating
# print "$linen";
# }

# In order to avoid the possibility of 2 users creating the same file at the same time we use a unique file number for each image file.

# Create variable representing the Maximum number of image files to store on server. This should exceed expected number of concurrent users or one user could be overwriting another's image. We shall use this number when incrementing the filename:

# If the last filename (number) is the same as our maximum number of files, then reset the numbering to 1, otherwise increment the number.

$maxfiles = 10;

# open the counter file with read and write access.
Open(COUNTER, "+< counter.txt");

# read the current value.
$COUNT = ;

if ($COUNT < $maxfiles) { 

# increment it by one. 
$COUNT++;
}
else {
# Reset counter
$COUNT = 1;
}

#rewind the file. 
seek(COUNTER, 0 , 0); 

#write the new value to the file. 
print COUNTER $COUNT; 
close COUNTER;

# Interacting with the Visual Basic Program:
# Because we cannot initialize or use the ActiveX control directly in Perl, we shall send the form information to a compiled Visual Basic Program, which will generate the barcode, save it as an image file and write a line of HTML to include the resulting image in this web page: First we send the form information (in tilde delimited format with no spaces): 

$errcode = system("C:\webshare\scripts\getbarcode.exe $COUNT~$Browser~$Version~$message
~$Comment~$CommentAlign~$Barheight~$Narrowbarwidth~$Symbology~$Rotation~$Forecolor
~$Backcolor~$Quitzones~$Bearerbars");

# The system command allows us to run an external program and then continue running this script.
# 2 Backslashes ("") are needed because in Perl the backslash is an escape key, in other words when the Perl interpreter sees a backslash it ignores the meaning of the next character. We are saving the value returned by the system command into a variable called $errcode. If the system command runs as expected $errcode will be 0, otherwise there will be a value other than 0. It is important to know this since whether the system command runs correctly or not the Perl script will continue to execute. 
# If the system command fails, or the results are unexpected, you may wish to capture the command line for debugging purposes.

# Here we send the same string we sent to the system command, to a text file called "outdata.txt". The ">" sign indicates that we are opening outdata.txt for overwriting as opposed to appending:

open(OUT, ">outdata.txt");
print OUT "C:\webshare\scripts\getbarcode.exe $COUNT~$Browser~$Version~$message
~$Comment~$CommentAlign~$Barheight~$Narrowbarwidth~$Symbology~$Rotation~$Forecolor
~$Backcolor~$Quitzones~$Bearerbars";
close(OUT);

# If the errcode is not 0 then there was an error running our VB program. If this is the case there is no point trying to display the image since it was never generated. Instead we display an error:

if ($errcode != 0){
print "There was a problem running a system command on the Server - Error: $errcode";
}
else {

# If there was no error then we open the html file created by the VB program that contains the image information and copy its contents:

open(INF,"C:\webshare\wwwroot\image$COUNT.html");
@ary = ;
close(INF);
foreach $line(@ary){
chomp($line);
print "$linen";
}
}

# insert an HTML line feed for a new line and explain what lies beneath
print "



The following data was submitted:

"; # Display all the data received from the form: foreach $key (keys(%FORM)) { print "$key = $FORM{$key} n"; } print "Current counter number is: $COUNT"; # Insert Footer HTML: print ""; # Alternatively, if you have a long footer that you always insert at the bottom of a web page you can copy and paste it into a text file and save it as footer.txt, then have your scripts open and read it into the web page on the fly in the same way that we insert the image information and html header information above. # Open(INF,"footer.txt"); # @ary = ; # close(INF); # foreach $line(@ary){ # chomp($line); # print "$linen"; # }

Sample Visual Basic Code

Module 1 Code

This is the code that generates the barcodes. The parameters specified by the user are passed by the Perl Script to this routine as one long string of data separated by the tilde (~) character. The routine below parses out the parameters into an array of data, then sets the properties of the activeX control with the data supplied by the user. The properties are matched to the data based on the order in which they were received. The barcode is then saved as an image file using the SaveBarCode Method. The image is saved in a format appropriate for the user’s Browser (PNG is preferable because its compression technique generates smaller images than GIF files, meaning that the page will load faster and less space is required on the server). The HTML code required to display the image is written to a text file with the same name as the image, which the perl script opens up and uses to display the final image on the page.

Note: In the code below there is no data validation to verify that submitted data is appropriate for the symbology selected, nor does it check to see if all required information was supplied. If you plan to use this technique such additional checking will be required.

 Sub Main()

'Declare variables
Dim cmdline$, i As Long
Dim StartPos As Long, DelimPos As Long
Dim MyArray(15), lngPixelsPerInch As Long
Dim pxlHeight As Long, pxlWidth As Long
Dim filenum As Long, ImagePath As String

'set number of pixels per inch (Windows always assumes 96 regardless of screen resolution)
lngPixelsPerInch = 96

'Visitors to the page will use the HTML form to record information about the barcode they wish to generate, for example the message to be encoded, the symbology, and the height of the bars. This program will look at the form data (passed by the Perl Script), set the Properties of the ActiveX control to those specified on the form, then generate a barcode image .PNG or .GIF (depending on the Browser since not all browsers suport .PNG files). This Barcode Image must be saved on the Server, so we shall specify a folder in which to save it. The filename has to be different for every visitor or one visitors barcode will be overwritten by the next. To this end we shall use an incrementing filename: "1.png", "2.png", etc. In order for the Server to "remember" the last filename it created, we must store it somewhere on the server, so we shall create a registry key to store the latest file number used and then read the last number from the registry and add one to it when generating the next one:

'get path to save images to
ImagePath = GetSetting("BCGen", "Settings", "imagepath", "C:WebshareWwwroot")

'Get command line arguments used to call this program
cmdline$ = Command$

'If you need to see what was received from the Perl script use:
'MsgBox "You typed:" & cmdline$

'if arguments were passed:
If Len(cmdline$) Then
'add final delimiter
cmdline$ = Command$ + "~"
'decode command line: separate each argument into an array
StartPos = 1
i = 1
While StartPos < Len(cmdline$)
DelimPos = InStr(StartPos, cmdline$, "~")
MyArray(i) = Mid$(cmdline$, StartPos, DelimPos - StartPos)
StartPos = DelimPos + 1
i = i + 1
Wend

'MyArray looks like = (Counter, Browser, version, message, comment, comment alignment, bar height, _
Narrow bar width, symbology, rotation, foreground, background, quitzones, bearerbars)

'file number variable is to prevent multiple users seeing the same file

filenum = MyArray(1)

'set activeX properties based on command line arguments
'This program assumes that all these arguments are passed, additional checking will be required
'if some arguments are null
'Also, by setting the relevent controls on the form to the new values, the dafaults can be changed


'Note: Properties that you do not set will use their default values

MainForm.TALBarCd1.Message = MyArray(4)
MainForm.TALBarCd1.Comment = MyArray(5)
MainForm.TALBarCd1.CommentAlignment = MyArray(6)
MainForm.TALBarCd1.BarHeight = MyArray(7)
MainForm.txtBarHeight = MyArray(7)
MainForm.TALBarCd1.NarrowBarWidth = MyArray(8)
MainForm.txtNarrowBW = MyArray(8)
MainForm.TALBarCd1.Symbology = MyArray(9)
MainForm.Combo1.ListIndex = MyArray(9)
MainForm.TALBarCd1.Rotation = MyArray(10)
MainForm.Combo2.ListIndex = MyArray(10)
MainForm.TALBarCd1.ForeColor = MyArray(11)
MainForm.TALBarCd1.BackColor = MyArray(12)

'in HTML forms unchecked checkboxes return nulls
If MyArray(13) = "" Or IsNull(MyArray(13)) Then
'no quietzones
MainForm.TALBarCd1.QuietZones = False
Else
MainForm.TALBarCd1.QuietZones = True
End If

If MyArray(14) = "" Or IsNull(MyArray(14)) Then
'no bearer bars
MainForm.TALBarCd1.BearerBars = False
Else
MainForm.TALBarCd1.BearerBars = True
End If

'Get height and width for display in Browser
pxlWidth = ConvertTwipsToPixels(MainForm.TALBarCd1.Width, lngPixelsPerInch)
pxlHeight = ConvertTwipsToPixels(MainForm.TALBarCd1.Height, lngPixelsPerInch)

'Check Browser and version, create .Png file if supported, otherwise .gif


If MyArray(2) = "Microsoft Internet Explorer" And MyArray(3) >= 4 Then
'save barcode in chosen directory in a format suitable for the browser (The form uses JavaScript to evaluate the browser, then writes the most suitable filetype to a "hidden" field in the form called "Imagetype". When we requested the form information from the server "Imagetype" was saved into a new variable called "strFileType". Below we concatenate 3 variables together in order to save the barcode:

MainForm.TALBarCd1.SaveBarCode ImagePath & filenum & ".png"

'Since our ImgDir is stored in a constant above as "c:websharewwwroot", filenum will be a number between 1 and 10 (since 10 is the maximum number of files we wish to store on the server) and strFileType will be either "PNG" or "GIF". The "&" character simply joins the three variables together in order to create a single string, for example ""c:websharewwwroot6.png"

'Write HTML to output file to be read by script when final page generated
Open "c:websharewwwrootimage" & filenum & ".html" For Output As #1
Print #1, ""
Close #1
Else
MainForm.TALBarCd1.SaveBarCode ImagePath & filenum & ".gif"
'Write HTML to output file to be read by script when final page generated
Open "c:websharewwwrootimage" & filenum & ".html" For Output As #1
Print #1, ""
Close #1
End If

'unload form from memory
Unload MainForm
Else
'no command line arguments specified: show form
MainForm.Show
End If

End Sub

'The following function is required because we intend to insert a Raster style image into the resulting web page. The dimensions of a Raster image are dependent upon the dot resolution of the device used to display it. For example a graphic that is 300 pixels wide and has 300 rows of pixels displayed on a printer that has a dot resolution of 300 dots per inch will be one inch square. But if you display the same image on a computer screen that has a dot resolution of approx 100 dots per inch, you end up with an image that is three inches square. When we Query the ActiveX control to find out it's height and Width the returning information is in "Twips". In order to Set the Height and Width Properties of the  tag, we need this information to be converted into Pixels.

Function ConvertTwipsToPixels(lngTwips As Long, _
lngPixelsPerInch As Long) As Long

Const nTwipsPerInch = 1440

ConvertTwipsToPixels = (lngTwips * lngPixelsPerInch) / nTwipsPerInch

End Function

Form Code

If no command line arguments are passed to the program the following form appears. It can be used by the administrator to set the Default settings on the Server. If command line arguments are passed to the form, then the form will not be displayed.

This is the code behind the Visual Basic Main Form:

Private Sub chkBearer_Click()

 'set Bearer bars
TALBarCd1.BearerBars = chkBearer.Value
End Sub

Private Sub chkQuiet_Click()
'set quiet zones
TALBarCd1.QuietZones = chkQuiet.Value
End Sub

Private Sub cmdBrowse_Click()
'This routine displays a dialog box from which the user can select a folder
PathForm.Show 1
End Sub

Private Sub Combo1_Click()
'Set Symbology
TALBarCd1.Symbology = Combo1.ListIndex
End Sub

Private Sub Combo2_Click()
'Set rotation
TALBarCd1.Rotation = Combo2.ListIndex
End Sub

Private Sub Combo3_Click()
'set comment alignment
TALBarCd1.CommentAlignment = Combo3.ListIndex
End Sub

Private Sub Combo4_Click()
'set Fore color
Select Case Combo4.ListIndex
Case 0: C& = 0
Case 1: C& = &HFFFFFF
Case 2: C& = &HFF
Case 3: C& = &HFF00&
Case 4: C& = &HFF0000
End Select
TALBarCd1.ForeColor = C&
End Sub

Private Sub Combo5_Click()
'Set Back color
Select Case Combo5.ListIndex
Case 0: C& = 0
Case 1: C& = &HFFFFFF
Case 2: C& = &HFF
Case 3: C& = &HFF00&
Case 4: C& = &HFF0000
End Select
TALBarCd1.BackColor = C&
End Sub

Private Sub Dir1_Change()
'After changing the image path update the textbox on the form
txtImagePath.Text = Dir1.Path
End Sub

Private Sub Form_Load()
'When the form loads...

'fill Symbology dropdown with list of symbologies
Combo1.AddItem "Code 39"
Combo1.AddItem "Code 39 Full ASCII"
Combo1.AddItem "Code 39 HIBC"
Combo1.AddItem "Codabar"
Combo1.AddItem "Code 93"
Combo1.AddItem "Code 128"
Combo1.AddItem "EAN/UCC 128"
Combo1.AddItem "Interleaved 2 of 5"
Combo1.AddItem "Postnet"
Combo1.AddItem "UPC-A"
Combo1.AddItem "UPC-E"
Combo1.AddItem "EAN-8"
Combo1.AddItem "EAN-13"
Combo1.AddItem "Bookland"
Combo1.AddItem "MSI/Plessey"
Combo1.AddItem "PDF417"
Combo1.AddItem "Aztec Code"
Combo1.AddItem "Data Matrix"
Combo1.AddItem "Maxicode"

'Get the last symbology used from the registry.
Combo1.ListIndex = GetSetting("BCGen", "Settings", "Symbology", "0")

'fill Rotation dropdown 
Combo2.AddItem "0 Degrees"
Combo2.AddItem "90 Degrees"
Combo2.AddItem "180 Degrees"
Combo2.AddItem "270 Degrees"

'Get the last Rotation setting from the registry.
Combo2.ListIndex = GetSetting("BCGen", "Settings", "Rotation", "0")

'fill Comment alignment dropdown
Combo3.AddItem "Left"
Combo3.AddItem "Center"
Combo3.AddItem "Right"

'Get the last Comment Alignment setting from the registry.
Combo3.ListIndex = GetSetting("BCGen", "Settings", "commentAlignment", "0")

'fill Fore Color dropdown
Combo4.AddItem "Black"
Combo4.AddItem "White"
Combo4.AddItem "Red"
Combo4.AddItem "Green"
Combo4.AddItem "Blue"

'Get the last Forecolor setting from the registry.
Combo4.ListIndex = GetSetting("BCGen", "Settings", "ForeColor", "0")

'fill Back Color dropdown
Combo5.AddItem "Black"
Combo5.AddItem "White"
Combo5.AddItem "Red"
Combo5.AddItem "Green"
Combo5.AddItem "Blue"

'Get the last Backcolor setting from the registry.
Combo5.ListIndex = GetSetting("BCGen", "Settings", "BackColor", "1")
'MainForm.TALBarCd1.BackColor = Combo5.ListIndex

'Get the last Image resolution used from the registry or use a default of 300
txtImageResolution = GetSetting("BCGen", "Settings", "RasterResolution", "300")
'set image resolution property
MainForm.TALBarCd1.RasterImageResolution = txtImageResolution.Text

'Get the last Narrow Bar Width setting from registry or use a default of 13
txtNarrowBW = GetSetting("BCGen", "Settings", "NarrowBarWidth", "13")
'set narrow bar width property
MainForm.TALBarCd1.NarrowBarWidth = txtNarrowBW.Text

'Get the last BarHeight setting from registry or use a default of 1000
txtBarHeight = GetSetting("BCGen", "Settings", "BarHeight", "1000")
MainForm.TALBarCd1.BarHeight = txtBarHeight.Text

'Get the last Bar Width Reduction setting from registry or use a default of 0 
txtBarWidthRed = GetSetting("BCGen", "Settings", "BarWidthReduction", "0")
MainForm.TALBarCd1.BarWidthReduction = txtBarWidthRed.Text

'Get the last Matrix Module size setting from registry or use a default of 20 
txtMatrixModSize = GetSetting("BCGen", "Settings", "MatrixModuleSize", "20")
MainForm.TALBarCd1.MatrixModuleSize = txtMatrixModSize.Text

'Get the last Quiet Zones setting from registry or use a default of 1 (meaning "On")
chkQuiet = GetSetting("BCGen", "Settings", "QuietZones", "1")
MainForm.TALBarCd1.QuietZones = chkQuiet.Value

'Get the last BearerBars setting from registry or use a default of 0 (meaning "Off")
chkBearer = GetSetting("BCGen", "Settings", "BearerBars", "0")
MainForm.TALBarCd1.BearerBars = chkBearer.Value
End Sub

Private Sub Form_Unload(Cancel As Integer)
'save new settings to the registry
SaveSetting "BCGen", "Settings", "Symbology", Combo1.ListIndex
SaveSetting "BCGen", "Settings", "Rotation", Combo2.ListIndex
SaveSetting "BCGen", "Settings", "CommentAlignment", Combo3.ListIndex
SaveSetting "BCGen", "Settings", "ForeColor", Combo4.ListIndex
SaveSetting "BCGen", "Settings", "BackColor", Combo5.ListIndex
SaveSetting "BCGen", "Settings", "imagepath", txtImagePath
SaveSetting "BCGen", "Settings", "RasterResolution", txtImageResolution
SaveSetting "BCGen", "Settings", "NarrowBarWidth", txtNarrowBW
SaveSetting "BCGen", "Settings", "BarHeight", txtBarHeight
SaveSetting "BCGen", "Settings", "BarWidthReduction", txtBarWidthRed
SaveSetting "BCGen", "Settings", "MatrixModuleSize", txtMatrixModSize
SaveSetting "BCGen", "Settings", "QuietZones", chkQuiet
SaveSetting "BCGen", "Settings", "BearerBars", chkBearer
End Sub

Private Sub mExit_Click()
'exit from menu
Unload Me
End Sub

Private Sub Text1_Change()
'When user types new text into Message text box, update barcode
TALBarCd1.Message = Text1.Text
End Sub

Private Sub Text2_Change()
'When user types new text into Comment text box, update barcode 
TALBarCd1.Comment = Text2.Text
End Sub

Private Sub txtImagePath_Change()
'if the imagepath is typed in without a trailing backslash, then put one in
If Right(Me.txtImagePath, 1) <> "" Then
Me.txtImagePath = Me.txtImagePath + ""
End If
End Sub

Private Sub txtBarHeight_Change()
'if the bar height is changed to a value between 11 and 6999 then set the bar height, otherwise beep. 
If Val(txtBarHeight.Text) > 10 And Val(txtBarHeight.Text) < 7000 Then
TALBarCd1.BarHeight = Val(txtBarHeight.Text)
Else
Beep
End If
End Sub

Private Sub txtBarWidthRed_Change()
'if the bar width reduction is changed to a value between 99 and -99 then set the bar width reduction, otherwise beep. 
If (Val(txtBarWidthRed.Text) < 100) And (Val(txtBarWidthRed.Text) > -100) Then
TALBarCd1.BarWidthReduction = Val(txtBarWidthRed.Text)
Else
Beep
End If
End Sub

Private Sub txtMatrixModSize_Change()
'if the Matrix Module size is changed to a value between 1 and 64 then set theMatrix Module size, otherwise beep. 
If Val(txtMatrixModSize.Text) > 0 And Val(txtMatrixModSize.Text) < 65 Then
TALBarCd1.MatrixModuleSize = Val(txtMatrixModSize.Text)
Else
Beep
End If
End Sub

Private Sub txtNarrowBW_Change()
'if the narrowbarwidth is changed to a value between 1 and 99 then set the narrowbarwidth, otherwise beep. 
If Val(txtNarrowBW.Text) > 0 And Val(txtNarrowBW.Text) < 100 Then
TALBarCd1.NarrowBarWidth = Val(txtNarrowBW.Text)
Else
Beep
End If
End Sub

Troubleshooting

How do I find out what the homepage or root directory of my web server is?

If you do not know your Server name or the root directory of your web server, then double click on the Web Server icon in your system tray to find out:

If you are running an older version of PWS or FrontPage Web Server, then your icon and PWS manager may look like this:

When I submit the Form there is a broken link where the barcode image should be

The most likely causes of this problem are:

  1. Check that the line of code that saves the barcode is saving it to the same folder that the tag expects to find it in. For example, in our code above we are saving the image into the root directory of the website. If we were to set the “src” (source) attribute to our image tag incorrectly (such as having it look in the scripts folder) we would get a broken link since the image is not going to be in that folder.
  2. Verify that the image is being created in the specified folder. If the image is not being created then it may be a permissions issue. Check that the public has write access to the folder in which you wish to save the barcodes.
  3. You tried to create a barcode with invalid parameters.

When I submit the Form I receive “Cannot find Server”

Verify that you have started the Web Server by double clicking on the icon in the system tray if a button marked “Start” is available then click on it to start the Web Server If the button says “Stop” then try stopping and restarting the Web Server.

If this does not resolve the problem make sure that you opened the form via http, rather than as a file on your hard drive. In other words, the address line in your Browser should read: “http://your.Server.Name/perlForm.htm” not “C:WEBSHAREWWWROOTperlForm.htm”.

When I submit the Form I receive “HTTP 404 Not Found”

This error means that the script (or the form) is in the wrong folder. For example, you may have copied both the form and the script into your “Scripts” folder (C:WEBSHAREScripts). Since your Web Server’s name is different to ours we used a relative link when telling the form where the barcode.asp script is located. When you submit the form, it tells the Web Server that the script is one level deeper than the form on the server, inside a folder called “Scripts”. If the form is already inside that folder, then the Server is looking for C:WEBSHAREScriptsScripts. Since this folder probably does not exist it cannot find the script it is looking for. To resolve the problem, either move the form to the C:\WEBSHARE\WWWRoot folder, or change the

tag in the html form to point to where the Script actually is. In this example, changing the line

to read

 would resolve the problem.

When I submit the Form I receive “HTTP Error 403 403.1 Forbidden”

This error indicates that the folder into which you copied the barcode.pl and “Getbarcode.exe” file does not have execute permissions. Either move the files to a folder that does have execute permissions such as the “Scripts” Folder, or grant execute permissions to that folder.

To grant execute permissions, open the Personal Web Server Manager, click on “Advanced”, double click on the folder you wish to use, then check the “Execute” and “Scripts” checkboxes and click “OK”. (On older versions of Personal Web Server click on “Administration”, and then change the properties of the folder).

When I submit the Form I receive “HTTP Error 405 – Method Not allowed”

This error means that your server is not configured to run Perl scripts. Configure your server to run Perl Scripts. If restarting the server doesn’t work then reboot the server machine.

When I submit the Form I receive “Error 500 – Internal Server Error”

This means that there is a syntax error in your Perl script. The best way to find it is to open an MSDOS window, navigate to the directory where you installed Perl and type: Perl -c script.pl (where “script.pl” is the name of your script. Note: If you script is in a different folder to the Perl interpreter – which for the sake of security it certainly should be! – then you must specify the full path to the script: e.g. Perl -c C:websharewwwrootCGI-binscript.pl). The “-c” argument tells Perl to compile the script without actually executing it.

If there is a compilation error Perl will inform you which line the error is on and often why the error occurred. Common syntax errors that cause an Error 500 include:

  • “Missing semicolon in previous line.”
  • “Can’t find terminator before EOF.” This message is usually the result of a missing right bracket or quotation mark.
  • “Might be a runaway multi-line string starting on line n.” This is usually a missing quotation mark.
  • “Missing right bracket”

By using Perl to compile your script you can turn a very baffling Error 500 into a simple “whoops I seem to have forgotten to close my quotations on line 10”.

It is also extremely important to remember that Perl is case sensitive. If you create a variable called $test and then later refer to it as $Test you will get unexpected results since $Test is considered by Perl to be a new and empty variable. For example:

$X = 6;
$Y = $x + 2;
print "$X + 2 = $Y";

Clearly, when the code was written I expected to print 6 + 2 = 8 onto my web page, but what I actually get is 6 + 2 = 2. While in this case we would not get a Server error, we would not get the result we expected and would be left looking rather silly.

When I submit the Form I see the Perl script as a text document

This means that your server is not configured to run Perl scripts. Configure your server to run Perl Scripts. If restarting the server doesn’t work then reboot the server machine.

When I try to run the Getbarcode.exe program it generates an “automation error” or something about a missing DLL file?

To resolve the problem, the latest Visual Basic Runtime files must be installed onto the client machine before the program can run successfully.

Where Do I Get these files?
The VBRUN60.EXE file is available for download here.

Reference :
For additional information, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID : Q192461
TITLE : FILE: VBRUN60.EXE Installs Visual Basic 6.0 Run-Time Files

If I change the symbology I sometimes get a broken link or a totally different barcode stretched out of proportion, why is this?

In our Example, we did not include any code to validate the data. Some Barcode symbologies have very strict rules about what can be encoded, UPC-A for instance, can only accept a 12 digit numeric message. If you type in “Test” and select UPC-A then the ActiveX control produces an error and sets the size properties back to the defaults for code 39 encoded with 1234567890, but it does not save a barcode to disk. You will recall that we allowed for 10 unique barcodes to be generated before it rolls over and starts overwriting. If you haven’t yet created 10 barcodes then you will probably get a broken link, otherwise you will get a distorted image of the last number n barcode.

To prevent this from happening you should write some code to do some basic data validation before and/or after the form data is submitted using javascript, Perl and/or VB code. You should also create a page or message that appears to inform the user that they entered invalid parameters. Examples of these techniques will be made available soon.

Contact Us