Clearly Define Order Of Execution Of Vbscript Events, And Let One Event (Onopen?) Execute Before Anything Else! Follow

0
Avatar
Legacy Poster

Trying to work with VBscript in BarTender is currently extremely frustrating unless you only want to do very basic alteration of objects/data. The scripts for different events seem unable to communicate with each other, and there is no clearly defined order in which document level events, data source scripts, and control events execute. Loading data into objects during OnOpen, then trying to use those objects to load data sources in their single or multiline scripts doesn't work! Why don't you make the OnOpen event execute before anything else, especially the data source scripts?? It makes very little sense to me why you would have it set up this way. I'm currently running into tons of problems because of this where I have to come up with cumbersome workarounds that are normally programming taboos but are unavoidable due to the nature of your event scripts. 

 

Also, must you make the script for an event execute every single time I move between events in the script editor? I haven't found a way to disable this auto execution and it is very annoying. I don't see the point of the Test Script button when it is automatically running every time I click on the event anyway...

10 comments

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

Which version of BarTender are you running?

 

In BarTender 2016 you'll see a "Procedures for all events" script, into which you can define and set the values of script variables.  Then in each VB script/data source you can reference the script variable as set in this top level script, which is accessible to all other scripts in the document no matter what type they are, to set the value of your data source.

 

To avoid the annoying auto-execution of scripts surround them within something like the below example:

 

If Format.IsPrinting Or Format.IsPrintPreview Then
   Msgbox "Hello World"
End If

In this example the Hello World message box will only display when either printing or previewing the document.

0
Avatar
Legacy Poster
Comment actions Permalink

I am running BarTender 2016, and I think maybe that feature is not working as you intended, because it has not worked for me at all. I have tried declaring a variable and loading it with data in 'Procedures for All Events', but when I try to use that variable in other event scripts or data source scripts, I get 'Object Required' errors.

 

More specifically: I would declare an uninitialized variable 'labelArr' at the top of the 'Procedures for All Events' script. Then, in that same script I would define a Sub or Function that re-dimensions the variable to an array and loads each index with a Label object (my own custom Class that is defined in a separate script library) that holds information for a label, all based on user input that I prompt for. When I tried to use VBscript data sources to extract the information I want from a Label object in that 'global' array for a certain template, I get 'Object Required' errors, presumably because the data source scripts execute before my array is loaded with information.

 

I've tried both Subs and Functions for loading my 'global' variable with data, by either directing manipulating the variable in a Sub, or creating the desired array of objects at function scope level, using it as the return value, and initializing my 'global' variable  using that function in 'Procedures for All Events', outside any Sub or Function definitions (i.e. the first two lines in that script would be "Dim labelArr" followed by "labelArr = LoadFunction()"). I've also tried declaring the variable in that top level script and then calling the sub or function to load it during the OnOpen event, in hopes that would execute before the data source scripts try to access the array/objects, but that doesn't work either.

 

I suggest you try out what I am explaining, because if it magically works for you, then something is wrong with my copy of the software.

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

Can you attach to this thread a simplified version (a BTW document file) of what you're trying to achieve so that we can take a look at it?

0
Avatar
Legacy Poster
Comment actions Permalink

Sure, I cut some code out of the actual files I'm working with, other things I left in but commented out because I think they are important for you to see in order to understand what's actually going on in the real file. 

 

You can enter any numbers you want in the prompts that will appear when you open the file, they aren't doing much in this simplified version. To start over, clear the "LoadedData" named data source (delete any text in its properties page or set it equal to an empty string some other way) and save the file, which will clear all data sources. Then close and reopen the file to get the prompts to appear again.

 

In addition to not being able to get VBscript data sources to work as desired, I am also experiencing Error #3628 when trying to print this document ("BarTender failed to create any printed items. Please check your setup and try again."). This error is occurring even when all my data is loaded into the templates correctly, using all Embedded Named Data Sources like this document illustrates, and the Valid property for the document returning True.... not sure what is invalid that is causing it to not be able to print.

 

Any insight you can provide would be helpful.

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

We're looking into this.  However, in the meantime, can you explain in simple terms what you're trying to achieve as an end goal and why?  I want to understand the needs of what you're trying to do here as there may well be a better way of implementing this rather than with complex VB scripting in the document.

0
Avatar
Legacy Poster
Comment actions Permalink

I know this is a lot to read, and it's not exactly in "simple terms" but I'm trying to illustrate why a lot of the built-in tools you would normally suggest I use are not going to work for me, as far as I can tell (if there is a way to make them work for me, please, please enlighten me). Hopefully having all this out in the open rather than through private communication with tech support will help others facing similar issues find solutions.

 

TL;DR my life would be a lot easier if BarTender:

1) allowed enabling serialization for a data source through VBS

2) allowed different size templates in the same document

3) allowed adjusting template sizes through VBS

 

 

What I'm Trying to Accomplish:

I am trying to automate our printing process as much as possible, and make it as simple as possible for our operators to get the correct information for a job loaded into appropriate sized templates/documents, formatted correctly, serialized correctly, and printed.

 

The issue is that there can be A LOT of variation among whole jobs and even a lot among the individual markers for each job. What we print is never held to a strict format or even to a couple different preset formats, since it is all dictated to us by the customer for every job. If we had preset formats that we would always print to, I agree that BarTender's built-in tools would be more than sufficient for handling automating our process.

 

Unfortunately, because of the large amount of variation, and because some of the features not available to your built-in VBS support (i.e. not allowing enabling/disabling serialization for data sources through VBS, not allowing different template sizes in the same document or adjusting them through VBS), the code is growing more and more complex as I run into issues that I need to develop workarounds for. 

 

The file I provided illustrates the sort of hybrid automated/manual set up process that we are going to start using first, while we work towards moving to 100% automation in the future. Our end goal of 100% automation would basically be the operator only having to scan a barcode for a job, and everything would work off that job number: it would filter our database (across multiple SQL tables) to look up all the relevant information, load the different sized labels for a job into separate .btw documents (since you can't have different size templates in the same document), load all text, use information from our database to properly format the text, begin printing all the documents/templates for the job, save the created .btw files together in a specific file location for the job, and also log all of the print job information.

 

 

Some explanations for the things you probably want me to use built-in tools for:

I am avoiding using the built-in database connection setup and data entry forms to retrieve information from the database because we need the information loaded from the database BEFORE print time, WITHOUT the operator messing with the database connection setup. This is so that the operator can preview everything that was loaded BEFORE print time, make any manual adjustments needed, and so that separate documents can be automatically created and loaded with data for different label sizes.

 

Using VBS to load information from the database makes me unable to use VBScript data sources (which would make subsequent processing easier/more organized), because of the issue I am experiencing with my objects that hold the retrieved data going out of scope or not functioning for some unknown reason when I try to call on them in data source scripts.

 

I am using programmatic serialization rather than built in serialization because the placement of serial numbers can be anywhere for a job, in any data source. Since I can't enable built in serialization when I detect a data source contains a serial number, I am forced to implement my own method for replacing data source text to serialize it in OnIdenticalCopies, and use number of copies in place of serializations.

0
Avatar
Legacy Poster
Comment actions Permalink

Has anyone taken a look at the file I posted yet? Everything works fine for me up until I try to print the templates I have loaded with data. I'm confused as to the origin of the Error #3628 ("BarTender failed to create any printed items. Please check your setup and try again.") that I am getting when trying to print. I have gone through my code and tried to pinpoint what could be causing the error but am coming up with nothing... Any ideas?

0
Avatar
Legacy Poster
Comment actions Permalink

Bumping this because the forum does not let me PM you, Ian. I had contacted BarTender tech support about this post a few weeks ago and they assured me someone would be looking into it and get back to me. Has anyone on the BarTender development team had a chance to look at this?

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

I suggest you follow up with the person you contacted in tech-support; I myself am not in the tech-support department.  Also, be advised that I only contribute to the forum in my spare time, and of late I've been pretty busy.  If I get the opportunity I'll take another look, I've kept the tab open in my browser as a reminder, but your issue is pretty complex and involved and thus is not something I can do at odd, spare moments in the day.  Sorry.

0
Avatar
Legacy Poster
Comment actions Permalink

Thanks for the quick response. That is completely understandable, I just was looking for some sort of status update on the issue.  :)  I think my solution is going to be performing all of the data retrieval and processing in Excel/VBA, then use VBA to send each individual item to BarTender (using a separate instance for each label size). Thanks for your suggestions so far, I'll update this topic when I have a final solution so others can learn from my experience.

Please sign in to leave a comment.