Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Make your voice heard! Participate in the 2020 Wisdom of Crowds® Survey. BEGIN SURVEY
dzhsa001
New Contributor III

Getting available printer names in listbox

Hello community,

I am currently dealing with reports printing using QlikView 11.2. "Report Print" action does it's best, but I don't want a user always select the printer. Rather than, I would like him to select a printer from the configuration sheet and this printer remains.

I have written a macro that returns a list of all possible printer names in the system using registry data. A partial code is here:

Sub AAA()

        Dim Printers() As String

        Dim N As Long

        Dim S As String

        Printers = GetPrinters()

        For N = LBound(Printers) To UBound(Printers)

            S = S & Printers(N) & vbNewLine

        Next N

End Sub

The thing is I want these data to be in a list box, where a user can select one of the printer names and, once selected - the value of the $(pName) is changed to the name of the printer. But, I am not sure how to enter a data as separate strings into listbox.

One idea, which comes to my mind is to concatinate all the names and assign to variable and then split this variable into substrings and add to listbox. Haven't tried yet, but not sure if it is the optimal solution.

Any suggestions or improvement is appreciated.

1 Solution

Accepted Solutions
Highlighted

Re: Getting available printer names in listbox

Listboxes can only display field values or expression results after performing some calculations. Fields or their values cannot be added/modified by macros (only the Load script can change field values).

AFAIK your best option is what you were already partially creating in your macro: a variable containing a list of Printer names. Replace the newline separator with a semicolon and you're all set.

Now create a new variable that will hold the selected printer name. Add an Input Box to your UI, and assign the new variable as recipient. On the Constraints tab, select "Predefine Values Only" from the Input Constraints list, from Value list select you preferred display method (drop-down or scroll bar) and in the input field at t he bottom of Predefined Values, expand the contents of the original variable that you filled in your macro.

Close and test.

View solution in original post

7 Replies
Highlighted

Re: Getting available printer names in listbox

Listboxes can only display field values or expression results after performing some calculations. Fields or their values cannot be added/modified by macros (only the Load script can change field values).

AFAIK your best option is what you were already partially creating in your macro: a variable containing a list of Printer names. Replace the newline separator with a semicolon and you're all set.

Now create a new variable that will hold the selected printer name. Add an Input Box to your UI, and assign the new variable as recipient. On the Constraints tab, select "Predefine Values Only" from the Input Constraints list, from Value list select you preferred display method (drop-down or scroll bar) and in the input field at t he bottom of Predefined Values, expand the contents of the original variable that you filled in your macro.

Close and test.

View solution in original post

Highlighted
dzhsa001
New Contributor III

Re: Getting available printer names in listbox

Thanks, for your suggestion, but I get somehow a weird error, when testing a script: "Expected end of the statements" and in Dim Printers() As String the "As String" part is highlighted. Have you got any idea, of why is it so?

Highlighted
MVP & Luminary
MVP & Luminary

Re: Getting available printer names in listbox

VBS didn't know data/object-types like VBA - therefore just remove all the "As ...".

- Marcus

Highlighted

Re: Getting available printer names in listbox

Indeed, VBS only has Objects and Variant-type variables. The latter can contain (almost) anything.

Highlighted
dzhsa001
New Contributor III

Re: Getting available printer names in listbox

I somehow missed the moment that the macro should be VBS rather than VBA. Thanks.

Now I get it like ActiveX  component cannot create object "GetObject":

Set objWMIService = GetObject("","winmgmts:\\" & strComputer & "\root\cimv2")

Highlighted
MVP & Luminary
MVP & Luminary

Re: Getting available printer names in listbox

You need to enable system-access for this module - about in the mid of the left pane within the module editor.

- Marcus

Highlighted
dzhsa001
New Contributor III

Re: Getting available printer names in listbox

marcus_sommer, also have done so, but the Error remains (