rklingaman Posted June 17, 2010 Share Posted June 17, 2010 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. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
zorphnog Posted June 17, 2010 Share Posted June 17, 2010 (edited) _GUICtrlListBox_GetSelItemsText returns an array, not a string. Either use$select = _GUICtrlListBox_GetSelItemsText($list1) If $select[0] = 1 Then AddPrinter ($select[1])or$select = _GUICtrlListBox_GetText($list1, _GUICtrlListBox_GetCurSel($list1)) Edited June 17, 2010 by zorphnog Link to comment Share on other sites More sharing options...
rklingaman Posted June 17, 2010 Author Share Posted June 17, 2010 Thank you for the information worked like a charm. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now