Sign in to follow this  
Followers 0
rklingaman

Having Trouble returning List Box Selection Text

3 posts in this topic

I'm having trouble with a part of my Program. When I'm finished I will have two list boxes one with the print server list of printers and one with users computer list of printers.

The trouble I'm having now is getting the function _GUICtrlListBox_GetSelItemsText to return the value that I have selected in the list box

The function AddPrinter at the moment just displays a message box with the printer name but its not going through for some reason.

#include <GUIListBox.au3>
#include <GUIConstants.au3>
Global $objWMIService1, $objWMIService2, $result1, $result2, $select

$Form1 = GUICreate("Printer Setup", 750, 850, 50, 50)
$Button1 = GUICtrlCreateButton("Add Printer", 325, 50, 97, 33, 0)
$list1 = GUICtrlCreateList("", 8, 16, 300, 800)
$list2 = GUICtrlCreateList("", 435, 16, 300, 400)
GUISetState(@SW_SHOW)

$result1 = GetPrinterList1()
GUICtrlSetData($list1, $result1)

$result2 = GetPrinterList2()
GUICtrlSetData($list2, $result2)

while 1
    $MSG = GUIGetMsg()
    Select
            Case $MSG = $GUI_EVENT_CLOSE
                Exit
            Case $MSG = $Button1
                $select = _GUICtrlListBox_GetSelItemsText($list1)
                AddPrinter ($select)
    EndSelect
WEnd

Func GetPrinterList1()
    Local $result1, $strComputer1, $colEvents1, $np,$result1
    $strComputer1 = "ares"
    If $objWMIService1 = 0 Then $objWMIService1 = ObjGet("winmgmts:\\" & $strComputer1 & "\root\cimv2")
    $colEvents1 = $objWMIService1.ExecQuery _
            (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE
    $np = 0
    For $objPrinter1 in $colEvents1
        $result1 &= $objPrinter1.DeviceID & '|'
    Next   
   $Result1 = StringLeft($result1,StringLen($result1) - 1)
    Return $result1;return the list of printers
EndFunc

Func GetPrinterList2()
    Local $result2, $strComputer2, $colEvents2, $np,$result2
    $strComputer2 = "."
    If $objWMIService2 = 0 Then $objWMIService2 = ObjGet("winmgmts:\\" & $strComputer2 & "\root\cimv2")
    $colEvents2 = $objWMIService2.ExecQuery _
            (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE
    $np = 0
    For $objPrinter2 in $colEvents2
        $result2 &= $objPrinter2.DeviceID & '|'
    Next   
   $Result2 = StringLeft($result2,StringLen($result2) - 1)
    Return $result2;return the list of printers
EndFunc

Func AddPrinter($select)
    MsgBox(4160, "Information", "Printer: " & $select)
EndFunc

Share this post


Link to post
Share on other sites



Thank you for the information worked like a charm.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0