matthardwick Posted May 4, 2010 Share Posted May 4, 2010 OK so I have an array as follows;[0]|CE - Personnel (Penmorfa)|Canon iR 5870C EUR|131072 [1]|DECS - Early Years (FenlinFach)|HP LaserJet 2015|0 [2]|DESH - Reception (Morgan Street)|HP LaserJet 2055dn|0 [3]|DF - Recovery (Canolfan Rheidol)|HP LaserJet 4055|0 [4]|DHPW - Estates (Regent Street)|Konica Minolta BizHub C451|131072 [5]|DHPW - General Office (County Hall)|Konica Minolta BizHub C650|131072 [6]|DSS - Adult Team North (Gorwelian)|HP LaserJet 1320|0I want to populate a drop down list with the first column, I can do this no problem with an array walk, but how would I then get the information in the other two columns to display in the GUI?So if I selected "DHPW - General Office (County Hall)" from the drop down, I would want to display information in the window from the rest of the array - so here the model number and current status code would be "Konica Minolta BizHub C650" and "131072" respectivly.I would appreciate some guidance as I haven't the foggiest where to start.Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 4, 2010 Moderators Share Posted May 4, 2010 matthardwick, Welcome to the AutoIt forum. It is as easy to code it as to explain: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $aList[7] $aList[0] = "|CE - Personnel (Penmorfa)|Canon iR 5870C EUR|131072" $aList[1] = "|DECS - Early Years (FenlinFach)|HP LaserJet 2015|0" $aList[2] = "|DESH - Reception (Morgan Street)|HP LaserJet 2055dn|0" $aList[3] = "|DF - Recovery (Canolfan Rheidol)|HP LaserJet 4055|0" $aList[4] = "|DHPW - Estates (Regent Street)|Konica Minolta BizHub C451|131072" $aList[5] = "|DHPW - General Office (County Hall)|Konica Minolta BizHub C650|131072" $aList[6] = "|DSS - Adult Team North (Gorwelian)|HP LaserJet 1320|0" $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) $hLabel = GUICtrlCreateLabel("", 10, 50, 200, 200) GUISetState() $sList = "|" For $i = 0 To UBound($aList) -1 $aSplit = StringSplit($aList[$i], "|") $sList &= $aSplit[2] & "|" Next GUICtrlSetData($hCombo, $sList) $sCurrSel = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($hCombo) <> $sCurrSel Then ; Set new selection value $sCurrSel = GUICtrlRead($hCombo) ; Search for the value in the array $iIndex = _ArraySearch($aList, $sCurrSel, 0, 0, 0, 1) ; Read teh whoel array element $sText = $aList[$iIndex] ; Split it $aSplit = StringSplit($sText, "|") ; Extract the data you need GUICtrlSetData($hLabel, $aSplit[3] & @CRLF & $aSplit[4]) EndIf WEnd Please ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
matthardwick Posted May 6, 2010 Author Share Posted May 6, 2010 I could have sworn I replied to this sooner, I just came back and saw I had not! Thanks for your help, but I should have been more clear in my first post - that array is dynamic, I just gave a small selection of possible entries in the array - is there a way to make the array in the format you suggested? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 matthardwick,there a way to make the array in the format you suggested?Of course. But it all depends on how your data starts. Do you already have lists or is it added dynamically?If, as I suspect, it is the latter then you will need a GUI with some inputs to receive the data and a button to run some code to add the contents of the inputs to the array. You can then refill the combo with the new list.Give it a go - you know where we are when you run into problems. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
matthardwick Posted May 6, 2010 Author Share Posted May 6, 2010 (edited) matthardwick, Of course. But it all depends on how your data starts. Do you already have lists or is it added dynamically? If, as I suspect, it is the latter then you will need a GUI with some inputs to receive the data and a button to run some code to add the contents of the inputs to the array. You can then refill the combo with the new list. Give it a go - you know where we are when you run into problems. M23 I will show you how I am building the array, that might be easier than explaining! Basically I am building it out of WMI output from a print server. $strComputer = "cereprint" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer WHERE Shared = True", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Local $printerTotal = 0 Local $printerArray[1][3] For $objItem In $colItems $printerArray[$printerTotal][0] = $objItem.Name $printerArray[$printerTotal][1] = $objItem.Comment $printerArray[$printerTotal][2] = $objItem.PrinterState $printerTotal += 1 ReDim $printerArray[$printerTotal + 1][3] Next ReDim $printerArray[$printerTotal][3] ; kill that dead record at the end of the array. If I _ArrayDisplay then I get that output which I originally showed you in the first post. Edited May 6, 2010 by matthardwick Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 matthardwick, that might be easier than explainingTouché! If you have the values in an array then life is really easy - why bother to change it to the format you had at the beginning? Just leave it as an array: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $printerarray[7][3] = [ _ ["CE - Personnel (Penmorfa)", "Canon iR 5870C EUR", "131072"], _ ["DECS - Early Years (FenlinFach)", "HP LaserJet 2015", "0"], _ ["DESH - Reception (Morgan Street)", "HP LaserJet 2055dn", "0"], _ ["DF - Recovery (Canolfan Rheidol)", "HP LaserJet 4055", "0"], _ ["DHPW - Estates (Regent Street)", "Konica Minolta BizHub C451", "131072"], _ ["DHPW - General Office (County Hall)", "Konica Minolta BizHub C650", "131072"], _ ["DSS - Adult Team North (Gorwelian)", "HP LaserJet 1320", "0"]] $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) $hLabel = GUICtrlCreateLabel("", 10, 50, 200, 200) GUISetState() $sList = "|" For $i = 0 To UBound($printerarray) -1 $sList &= $printerarray[$i][0] & "|" Next GUICtrlSetData($hCombo, $sList) $sCurrSel = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($hCombo) <> $sCurrSel Then ; Set new selection value $sCurrSel = GUICtrlRead($hCombo) ; Search for the value in the array $iIndex = _ArraySearch($printerarray, $sCurrSel, 0, 0, 0, 1) ; Read the other array elements $sText_1 = $printerarray[$iIndex][1] $sText_2 = $printerarray[$iIndex][2] ; Show the data GUICtrlSetData($hLabel, $sText_1 & @CRLF & $sText_2) EndIf WEnd How is that? I am off to watch the election results now, but I have some ideas to smarten up your array filling - look in again tomorrow. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
matthardwick Posted May 7, 2010 Author Share Posted May 7, 2010 I don't get what you mean keep the original format... what I pasted originally was output from that array I built using WMI. I don't want to have to change my code, everytime anything is changed on the server... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2010 Moderators Share Posted May 7, 2010 matthardwick,No, you have misunderstood - all I did in the script above was declare an array to match the one you created via WMI (because I obviously cannot create it directly as you did ). Just put your WMI code where I declared the array:expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> ; get your array here $strComputer = "cereprint" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer WHERE Shared = True", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Local $printerTotal = 0 Local $printerArray[1][3] For $objItem In $colItems $printerArray[$printerTotal][0] = $objItem.Name $printerArray[$printerTotal][1] = $objItem.Comment $printerArray[$printerTotal][2] = $objItem.PrinterState $printerTotal += 1 ReDim $printerArray[$printerTotal + 1][3] Next ReDim $printerArray[$printerTotal][3] ; kill that dead record at the end of the array. ; create the GUI $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) $hLabel = GUICtrlCreateLabel("", 10, 50, 200, 200) GUISetState() ; now use the array you have just generated to populate the combo $sList = "|" For $i = 0 To UBound($printerarray) -1 $sList &= $printerarray[$i][0] & "|" Next GUICtrlSetData($hCombo, $sList) $sCurrSel = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($hCombo) <> $sCurrSel Then ; Set new selection value $sCurrSel = GUICtrlRead($hCombo) ; Search for the value in the array $iIndex = _ArraySearch($printerarray, $sCurrSel, 0, 0, 0, 1) ; Read the other array elements $sText_1 = $printerarray[$iIndex][1] $sText_2 = $printerarray[$iIndex][2] ; Show the data GUICtrlSetData($hLabel, $sText_1 & @CRLF & $sText_2) EndIf WEndOf course, if you do not want to generate the array every time you run the script, then you will need to save it somewhere. Use _FileWriteFromArray to save it and then _FileReadToArray to get it back again. Is that closer to what you want?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
matthardwick Posted May 7, 2010 Author Share Posted May 7, 2010 (edited) OMG I am so stupid, I didn't scroll so didn't full read what you put. That code is perfect... Lol thanks so much for your help. I feel guilty for just taking code from you - I was just after pointing in teh right direction All I gotta do now is figure out how to change an icon acording to status code, and then add the printer on the press of the button. Thansk again! Edited May 7, 2010 by matthardwick Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2010 Moderators Share Posted May 7, 2010 matthardwickI feel guilty for just taking code from youNo reason to - it is why I posted it here! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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