Loading Files from Folder into DropDownList with VBScript Follow

0
Avatar
Brian Jobmann

Hello. Having trouble loading a DropDownList into a form in BarTender. I have a Document (there will be many) located in a folder. The label requires artwork (many different options) and they will be located in the same folder as the document file. I have set up Named Data Sources to get the path of the folder (as that will vary from Document to Document depending on the folder it is located in). These are working perfectly. 

I set up the VB Script to populate the DropDownList, and in the VB Script Editor, it appears to be working. The output is correct. When I go to print preview, all but one time, I get a "<Script Error>". I don't know how to debug this when its working in the script editor, and when it worked once in the in the print preview. I have added the path to the form to make sure its value is correct and it is.

So two questions: 

1. Obvious, what am I doing wrong?

2. Is there more debugging that can be recommended at the runtime so I can figure out what's going on?

I downloaded the latest release today, and still am having the issue. I am running the 32-Bit version on Windows 7.

Here is the my VB Script:

-----

Dim dir, foundFile

dir = Format.NamedSubStrings("Path").Value


Dim fileNames, fso, folder

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(dir)

For Each foundFile In folder.Files

fileNames = foundFile.name

If(Right(fileNames,4) = ".pdf") then
fileNames = Left(fileNames,(Len(fileNames)-4))
Value = Value + vbCR + fileNames
End If
Next

-------

The output seems correct, although there is a blank line above the file names. This is consistent when I close the script editor, and look at the DropDown List Properties --> List Items. There is a blank row there as well. 

It almost seems that I need to reset the list to empty before running the script. Which, would actually be good, because artwork could be added to the folder between print jobs, and the dialog will stay open after each print job ready for the next job.

Any help would be GREATLY appreciated. And if you need screen shots, let me know and I will get them to you. Thanks for your help in advance!

-Brian

3 comments

0
Avatar
Shotaro Ito
Comment actions Permalink

Hello Brian,

There's no other debug method than trial and error. I often do like

msgbox("I'm here")

From BarTender 2016 You have drop down item option to get source from files in a folder, so no need to use VB Script.

About the script, At first, "Value" 's value wasn't defined so that's better be clear out. (don't try to keep "Value" from previous print etc)
Try below..

Value = "" 'Initialize Value

Dim dir, foundFile

dir = Format.NamedSubStrings("Path").Value

Dim fileNames, fso, folder

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(dir)

For Each foundFile In folder.Files

fileNames = foundFile.name

If(Right(fileNames,4) = ".png") then
fileNames = Left(fileNames,(Len(fileNames)-4))
Value = Value & fileNames & vbCr 'Connect strings by &. add vbCr after filename to avoid 1st line to become empty
End If
Next
0
Avatar
Brian Jobmann
Comment actions Permalink

Hello Shotaro,

 

Thank you for your help. I actually had gotten this figured out, but I appreciate your effort. 

The problem with using the built in dropdown list source from a folder, is two fold. One, the source seems to only be read when the filed is setup, not constantly (or at least at print time) as the artwork in that folder continues to change over time. So that was an issue. The second is that I could not hardwire the folder, as it needed to be based on the document folder. The document is a basis for the label setup. The user will copy and paste the document into new folders as government agencies require slight differences in the format of the date for instance. So I needed to be able to read the artwork files on demand so that the wrong artwork file could not be printed with the wrong format. Everything has to be separated. 

Anyway, thanks for you attention I appreciate it. I have run into another problem though. I need to set the quantity at the time of print via the data form. No problem, I can do that no problem. But I need to write the number of copies to an audit log. The problem is that while I can link a data entry field to the print dialog copies, I can't get that back to the template VB to get that in the audit log. While it's a named source in the form, it's not a named source in the template. 

I made a workaround, where I have a named datasource in the template - zCopies. I then linked the data entry for quantity on the form to zCopies. I then set the copies in the print dialog (the actual dialog) to "Set by Data Source" and set it to zCopies. This seems to work, but there is a very, very long delay (>120 seconds) between clicking print on the data form and BarTender actually processing the pages.

Is there a better way? Can I access, via VB, the built in copies data source from the print dialog from a template like I can using the linked data source from the form? Or am I already doing it the best way?

0
Avatar
Shotaro Ito
Comment actions Permalink

Hello Brian,
Good to hear that you could overcome file listing part.
Your procedure (name copy's data source) is right, and the setup itself should not slow down print job.

I would try to identify what causes the slow down. such as

  • Number of records: Often bartender document opens slow when you have large database connected.
  • VB Script: What if you disable VB Scripts?

Please sign in to leave a comment.