Basic Windows Script Host Example for Barcode ActiveX

System Requirements

Using this Example

  1. Install Microsoft Windows Script Host if necessary (WSH is an intrinsic part of Windows 98 and 2000).
  2. Install TAL Barcode ActiveX Plus on your Web Server.
  3. Download the files discussed in the example below. This is a self extracting zip file containing the VBScript code.
  4. Double click on the downloaded file and extract the files. (By default they are extracted to your temp folder (“C:Windowstemp” on Windows 95/98 machines and “C:temp” on Windows NT/2000 machines)
  5. Locate the file test.vbs through Windows Explorer and double click on it to run the code.
  6. Open Microsoft Word, go to the INSERT menu and choose PICTURE, then FROM FILE, type or navigate to “C:barcode.wmf” and click OK. You should be rewarded with a barcode

Creating and Saving a bar code to disk

 '################# Test1.vbs ###############

'The following code will generate a barcode with the message "Test1" and the comment "my comment", then save the barcode as a windows metafile in the root directory of the C drive.

'declare a variable to store the barcode object
dim myBarcode
'Assign taltech activex to the myBarocde variable using the CreateObject method of the Wscript object.
set myBarcode = Wscript.CreateObject("TALBarCd.TALBarCd.1")

'set message and comment properties of Barcode.
myBarcode.Message = "Test1" 
myBarcode.Comment = "my comment" 
myBarcode.Symbology = "0"

'save barcode using SaveBarCode method of ActiveX control: 
'Note: with ActiveX Plus version you can also specify .png, .gif, .jpg, .bmp extentions to create that sort of graphic file.
myBarcode.SaveBarCode "c:barcode.wmf"

'remove ActiveX control and barcode info from memory:
set myBarcode=nothing

Discussion

Test1 demonstrates how to use the Windows Script Host with our ActiveX control, but unless you always intend to create the same barcode this is not a very useful real world example. To make it a little more interactive we can add input boxes that prompt the user for information:

 

 '########### test2.vbs ##################
'The following code will prompt the user for a message and comment, then generate and save the barcode as a windows metafile in the root directory of the C drive.

'declare a variable to store the barcode object
dim myBarcode
'Assign taltech activex to the myBarocde variable using the CreateObject method of the Wscript object.
set myBarcode = Wscript.CreateObject("TALBarCd.TALBarCd.1")

'Prompt user for barcode information: the information they type into the input box is saved into the variable names "Message$" and "Comment$" (the "$" indicates that the information will be saved as a text string, even if they type in numbers.
Message = inputbox("Type in the information you want to convert to a barcode")
Comment= inputbox("Type in the information you want to include in the comment")

'set message and comment properties of Barcode.
myBarcode.Message = Message
myBarcode.Comment = Comment

'save barcode using SaveBarCode method of ActiveX control: 
'Note: with ActiveX Plus version you can also specify .png, .gif, .jpg, .bmp extentions to create that sort of graphic file.
myBarcode.SaveBarCode "c:barcode.wmf"

'remove ActiveX control and barcode info from memory:
set myBarcode=nothing

This is all well and good for creating a handful of similar barcodes, but if you try to prompt the user in this fashion for all the information (message, comment, symbology, rotation, colors, fonts, etc) it will be very time consuming and frustrating for the user. One way to fix this is to create a form in Visual basic and call it as a com object from the VBScript file. More advanced examples to demonstrate this and other techniques will be made available soon.

Troubleshooting

When I double click on a .vbs file an “Open With…” box is displayed.

This would indicate that the Windows Script Host is not installed.

When I double click on a .vbs file the code appears in Notepad.

This would indicate that the .VBS extention has been associated with notepad, either because the Windows Script Host is not installed, or because (perhaps as a security precaution) the default open method for .VBS files has been modified to “edit” instead of “run”.

Contact Us