Sample Code: Activex Automation Via Vb Script Follow

0
Avatar
Shotaro Ito

Hi There -

It demonstrates how to print a format from Windows VB Script via ActiveX Automation.
Extract zip contents to a folder then double click to run "ActiveXSample.vbs".
(it will print a label format "ActiveXSample.btw" to your default printer.)
*this script is NOT for embedded VB Script in BarTender label format.

Shotaro
--- ActiveXSample.vbs
'VBScript sample of activeX automation
'Create a format with named substring "SUBSTRING1","SUBSTRING2" and save as "ActiveXSample.btw" in the same folder as this vbs
'Works with BarTender Automation Edition or above
'(Tested on BT9.4.2760 on Windows XP SP3)
dim btApp
dim btFmt

'*** start BarTender
set btApp = Createobject("BarTender.Application")

'*** Show BarTender window (false to not show)
btApp.Visible = true

'*** open format "ActiveXSample.btw" in current directory without specifying printer
Set wShell = CreateObject("WScript.Shell")
set btFmt = btApp.Formats.Open(wShell.CurrentDirectory & "\ActiveXSample.btw",false,"")
Set WShell = Nothing

'*** open a format with specifying printer.
'set btFmt = btApp.Formats.Open("c:\ActiveXSample.btw",false,"Zebra TLP-3844Z")

'*** change printer
'btFmt.Printer = "Adobe PDF"

'*** disable user prompt of the format
btFmt.EnablePrompting = false

'*** set variable data
'(if too many substrings causes slow to update, consider to use SetAll method instead.)
btFmt.SetNamedSubStringValue "SUBSTRING1","Hello!"
btFmt.SetNamedSubStringValue "SUBSTRING2","BARTENDER"

'*** set number of copies
btFmt.IdenticalCopiesOfLabel = 1

'*** Cutter control (only available for Seagull driver + Cutter enabled printer)
'*** Enable cutter(0:use driver setting, 4:cut)
'btFmt.PageSetup.MediaHandling.Action = 4
'*** Set cut timing(0:end of job, 1:end of page)
'btFmt.PageSetup.MediaHandling.Occurrence = 0

'*** print format without showing print dialog, status window
btFmt.PrintOut false,false

'*** Close format(1:not save, 2:overwrite)
btFmt.Close(1)

'*** Close BarTender(1:not save, 2:overwrite all)
btApp.Quit(1)

set btFmt = nothing
set btApp = nothing

13 comments

0
Avatar
Legacy Poster

Cool, something I've been looking for and will need to try out.
0
Avatar
Legacy Poster

Thanks you very much ..
0
Avatar
Legacy Poster

Thanks for the code example.

I have created a VB program as below with a form that has 2 buttons.

[code]
Public BtApp As BarTender.Application
Public BtFormat As BarTender.Format

Private Sub Command1_Click()
'button to end the application

BtApp.Quit (1)

Set BtFormat = Nothing
Set BtApp = Nothing

End

End Sub


Private Sub Command2_Click()

'button to print the label

'locate the label design
Set BtFormat = BtApp.Formats.Open("c:\barcode\Label2.btw", False, "")

'assign the field values
BtFormat.SetNamedSubStringValue "BCNumber", "M0000000000005"
BtFormat.SetNamedSubStringValue "BCTitle", "Warehouse 1"


'print the label
BtFormat.PrintOut False, False

'close the app
BtFormat.Close (1)

End Sub

Private Sub Form_Load()

'define the BarTender application object
Set BtApp = CreateObject("BarTender.Application")

'set the captions for Buttons
Command1.Caption = "Quit"
Command2.Caption = "Print"

End Sub

[/code]

I have created a label design with 2 share/name fields BCTitle and BCNumber both with empty strings.


When I run the VB program the barcode prints out but the fields have not been populated with the set values. I have added a fixed text field to check that the correct label file is being accessed.

Can you explain exactly how to set up a share/name field in a label design as I must be missing something.

I am using the Trial version of the BarTender software.

Thanks in advance
0
Avatar
Shotaro Ito
Moderator

Hi GmA,
To me it looks your code is fine, so that makes me to think your named substring was not setup properly. Please check the format attached with the sample code above.
Show BarTender window while you set value and print, by
[code]btApp.Visible = true[/code]
So you can check any error happened, and actually see the value is updated or not.
0
Avatar
Legacy Poster

Thanks for the hint, I suspected it was the label design.

I have got the label printing now, I think the mistake was setting the Source to Visual Basic Script instead of Screen Data.

Thanks for the quick and accurate reply.

GmA
0
Avatar
Legacy Poster

Hello
I am slightly confused and would appreciate guidance
when I use in VB
BtFormat.PrintOut False, False
the format doesn't print but when I set dialog box to open it
BtFormat.PrintOut True, True
works when I click the ok button. Is it I am doing something wrong.
Do I need to add
btFormat.EnablePrompting = false

Also If I am using a printer that is on network how do I do identify that in opening of format. Normally I mention the particular zebra printer but the network name of printer is "Zebra1"
How do I provide the network path of the printer as I am assuming if I put Zebra1 it is going to assume it is local.
Set BtFormat = BtApp.Formats.Open("c:\barcode\Label2.btw", False, "Zebra1")

(Zebra1 is network name for Zebra GX230T)
0
Avatar
Shotaro Ito
Moderator

Hi Amit,
Most likely, you have an error at print time which prevents print, but the error was not shown.
Show BarTender window while you set value and print, by
[code]btApp.Visible = true[/code]
if not.
Also enable BarTender's message logging (Administer > Log setup > Text file log > Log Messages)

You don't have to add this line
[code]btFormat.EnablePrompting = false[/code]
The code just suppress prompts to pop up. If no prompt has been set to format, prompt dialog not shown.
The setting is BarTender's Print > Options > Enable prompting.

To specify network printer from code is "\\<computer name>\<printer name>", which should appear on BarTender's print dialog.
[code]Set BtFormat = BtApp.Formats.Open("c:\barcode\Label2.btw", False, "\\MYPC\Zebra1")[/code]

Hope that helps!
0
Avatar
Legacy Poster

Thanks for the tip. I found there was error that was not showing because I didnt have the app visible.

[quote name='Shotaro I -Seagull Support' timestamp='1322616291' post='1178']
Hi Amit,
Most likely, you have an error at print time which prevents print, but the error was not shown.
Show BarTender window while you set value and print, by
[code]btApp.Visible = true[/code]
if not.
Also enable BarTender's message logging (Administer > Log setup > Text file log > Log Messages)

You don't have to add this line
[code]btFormat.EnablePrompting = false[/code]
The code just suppress prompts to pop up. If no prompt has been set to format, prompt dialog not shown.
The setting is BarTender's Print > Options > Enable prompting.

To specify network printer from code is "\\<computer name>\<printer name>", which should appear on BarTender's print dialog.
[code]Set BtFormat = BtApp.Formats.Open("c:\barcode\Label2.btw", False, "\\MYPC\Zebra1")[/code]

Hope that helps!
[/quote]
0
Avatar
Legacy Poster

Do you know how to get the error message for vb? Like my error message is #3200, which is no records found. I want to be able to do something when that error comes up. Any ideas?
0
Avatar
Legacy Poster

Can you please elaborate on how to set the variable data? I have a query (qry_LABEL) that contains the fields that I want printed on my label, but I get a run-time error when I run this code.
0
Avatar
Legacy Poster

:o

0
Avatar
Legacy Poster

Hi Shotaro,

 

Could you make available ActiveXsample.zip for download. It's not available now.

0
Avatar
Shotaro Ito
Moderator

Sorry the forum banned zip long ago - this still works with BT2016R3. Place both files on the same folder, rename ActiveXPrint.vbs.txt to ActiveXPrint.vbs and run.

Please sign in to leave a comment.