pintas Posted May 20, 2011 Share Posted May 20, 2011 Ok.... i have a php file like this called configuration.php: <?php $PUBLISHED_FOLDERS = array( "1" => array("name" => "Client1", "path" => "/client1"), "2" => array("name" => "Client2", "path" => "/client2"), "3" => array("name" => "Client3", "path" => "/client3"), "4" => array("name" => "Client4", "path" => "/client4"), ); $USERS = array( "1" => array("name" => "Client1", "password" => "111111", "default_permission" => "rw", "folders" => array( "1" => NULL, "2" => NULL, "3" => NULL )), "1" => array("name" => "Client2", "password" => "222222", "default_permission" => "rw", "folders" => array( "1" => NULL, "2" => NULL, "3" => NULL )), "3" => array("name" => "Client3", "password" => "333333", "default_permission" => "rw", "folders" => array( "1" => NULL, "2" => NULL, "3" => NULL )), "4" => array("name" => "Clien4", "password" => "444444", "default_permission" => "ro", "folders" => array( "1" => "Custom name for Folder A", "2" => NULL )) ); ?> And this is my code: expandcollapse popup#include <String.au3> #include <array.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> local $trimclient, $trimpassword, $Combo1 Func ReadClients() $clientlist = fileread("configuration.php");read the whole file to one long string $clientlist = stringleft($clientlist,stringinstr($clientlist,"$USERS = array(") + stringlen("$USERS = array("));get rid of anything after $Users $trimclient = _StringBetween($clientlist, '=> array("name" => "', '",') EndFunc ReadClients() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 242, 178, 505, 295) $Combo1 = GUICtrlCreateCombo("Clientes", 48, 64, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, _ArrayToString($trimclient)) $Button1 = GUICtrlCreateButton("Start", 50, 32, 97, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func ReadClientsPasswords() $passwordlist = fileread("configuration.php");read the whole file to one long string $passwordlist = StringTrimLeft($passwordlist,stringinstr($passwordlist,"$USERS = array(") + stringlen("$USERS = array("));get rid of anything after $Users $trimpassword = _StringBetween($passwordlist, GUICtrlRead($Combo1)&'", "password" => "', '",') EndFunc ReadClientsPasswords() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 IF GUICtrlRead($Combo1) = 'Clientes' Then msgBox(4160, "box",'Escolha um cliente') Else msgBox(4160, "box",GUICtrlRead($Combo1)) msgBox(4160, "box",$trimpassword) EndIf EndSwitch WEnd I'm trying to display the password if i select a specific client. For example... if i select Client1 I'd like a msgbox (or anything like that) displaying the specific password for that client. In this case 222222. My logic with GUICtrlRead($Combo1)&'", "password" => "', '" seems right, but it doesn't work. What am i doing wrong? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 20, 2011 Moderators Share Posted May 20, 2011 pintas,I would use SREs to extract the client names and passwords into arrays and then use _ArraySearch to do the matching like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $aClients, $aPasswords ReadData() $Form1 = GUICreate("Form1", 242, 178, 505, 295) $Combo1 = GUICtrlCreateCombo("Clientes", 48, 64, 145, 25) GUICtrlSetData(-1, _ArrayToString($aClients)) $Button1 = GUICtrlCreateButton("Start", 50, 32, 97, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If GUICtrlRead($Combo1) = 'Clientes' Then MsgBox(4160, "box", 'Escolha um cliente') Else MsgBox(4160, "box", GUICtrlRead($Combo1)) ; Now search the client array for the value in the combo $iIndex = _ArraySearch($aClients, GUICtrlRead($Combo1)) ; And display the corresponding element in the password array MsgBox(4160, "box", $aPasswords[$iIndex]) EndIf EndSwitch WEnd Func ReadData() ; Read file $sFile = FileRead("configuration.php") ; Extract the client names $aClients = StringRegExp($sFile, "(?i)(?U)\x22name\x22 => \x22(.*)\x22, \x22password", 3) ; Extract the passwords $aPasswords = StringRegExp($sFile, "(?i)(?U)\x22password\x22 => \x22(.*)\x22, \x22default_permission", 3) EndFunc ;==>ReadDataWith the flag parameter set to 3 the SRE looks for the values between the other parts of the pattern and returns them in an array - rather like a multiple _StringBetween (which actually uses an SRE to work!). Please ask if you have any questions. 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...
pintas Posted May 20, 2011 Author Share Posted May 20, 2011 Wow! It does work. In the help file the (?U) Invert greediness of quantifiers, i don't have a clue what that means. Could you please help me with this? And the \x22, well i understand it's the ", i'm i right? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 20, 2011 Moderators Share Posted May 20, 2011 pintas, Wow! It does workWhat did you expect! Invert greediness of quantifiersNormally SREs look for the longest match possible - (?U) makes them look for the shortest. This script should give you the idea: #include <Array.au3> $sString = "<>Tom<><>Dick<><>Harry<>" ; Longest match - looks for the first and last $aArray = StringRegExp($sString, "<>(.*)<>", 3) _ArrayDisplay($aArray) ; Invert and we look for the shortest match $aArray = StringRegExp($sString, "(?U)<>(.*)<>", 3) _ArrayDisplay($aArray) the \x22, well i understand it's the "Correct - much easier than trying to fiddle around with single and double quotes in the pattern. All clear? 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...
pintas Posted May 20, 2011 Author Share Posted May 20, 2011 Crystal clear. Great explanation. Thanks Melba! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 20, 2011 Moderators Share Posted May 20, 2011 pintas, Glad I could help. 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