Newb Posted April 14, 2011 Share Posted April 14, 2011 Hi all. I wrote a function to fetch pieces of strings from a bigger string. Function is StringFetch. It's very similar to _Stringbetween, but since it wasn't working, I wrote my own function. My aim is to get the text of the current combo box selection and to strip the number out of it without the "%". Alternatively, I've tried all the commands related to _GuiCtrlComboBoxEx_Create,_GUICtrlComboBoxEx_SetItemParam,_GUICtrlComboBoxEx_GetItemParam, but I failed someway to implement it, because the creation of a ComboBox with _GuiCtrlComboBoxEx_Create doesn not allow to create it into a Tab (it will override every tab and will be set always visible over all GUI controls) So here's my solution (it's more easy to just run it examining the code later, just run it first ): expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $menu1, $n1, $n2, $msg, $menustate, $menutext GUICreate("My GUICtrlRead") ; will create a dialog box that when displayed is centered Local $msg GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $menu1=GUICtrlCreateCombo("", 10, 10) ; create first item GUICtrlSetData(-1, "25%|50%|100%", "25%") $n2 = GUICtrlCreateButton("Read", 10, 110, 50) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $msg = GUIGetMsg() If $msg = $n2 Then MsgBox(0, "String Extracted with Stringfetch", GUICtrlRead($n1)) ; display the selected listbox entry $menustate = StringFetch(GUICtrlRead($menu1),StringLeft(GUICtrlRead($menu1),1),"%"); return the state of the menu item $menutext = GUICtrlRead($menu1) ; return the text of the menu item MsgBox(0, "State and text of the menuitem", "state:" & $menustate & @LF & "text:" & $menutext) EndIf Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000) Local $c_StringASize=StringLen($c_StringSearchA) If $i_InstrStart=False Then $c_StringASize=1 Return StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _ +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,StringInStr($c_String,$c_StringSearchA),$i_InstrCount) _ -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize)) EndFunc As you can see the first messagebox that uses StringFetch will just retrieve a "0", instead, when using GuiCtrlRead alone, all works fine. Any help will be appreciated, also, alternative solutions are welcome too. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
JScript Posted April 14, 2011 Share Posted April 14, 2011 (edited) You did not set the variable $n1! Look more closely your code and you'll see... Edit: Instead: MsgBox(0, "String Extracted with Stringfetch", GUICtrlRead($n1)) ; display the selected listbox entry Use this: MsgBox(0, "String Extracted with Stringfetch", GUICtrlRead($menu1)) ; display the selected listbox entry Edited April 14, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
JScript Posted April 14, 2011 Share Posted April 14, 2011 (edited) Work better your code! $menu1=GUICtrlCreateCombo("", 10, 10) "$menu1" has nothing to do with "GUICtrlCreateCombo" The logical thing would be: $iCombo1 = GuictrlCreateCombo("", 10, 10) Edited April 14, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Newb Posted April 14, 2011 Author Share Posted April 14, 2011 (edited) Ok, now is fine, but why the stringfetch just takes 5, instead of 25? #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $menu1, $n2, $msg, $menustate, $menutext GUICreate("My GUICtrlRead") ; will create a dialog box that when displayed is centered Local $msg GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $menu1=GUICtrlCreateCombo("", 10, 10) ; create first item GUICtrlSetData(-1, "25%|50%|100%", "25%") $n2 = GUICtrlCreateButton("Read", 10, 110, 50) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $msg = GUIGetMsg() If $msg = $n2 Then MsgBox(0, "Selected listbox entry", StringFetch(GUICtrlRead($menu1),StringLeft(GUICtrlRead($menu1),1),"%")) ; display the selected listbox entry $menutext = GUICtrlRead($menu1) ; return the text of the menu item MsgBox(0, "State and text of the menuitem","text:" & $menutext) EndIf Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000) Local $c_StringASize=StringLen($c_StringSearchA) If $i_InstrStart=False Then $c_StringASize=1 Return StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _ +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,StringInStr($c_String,$c_StringSearchA),$i_InstrCount) _ -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize)) EndFunc Edit: I solved it. Just need to set stringfetch like this StringFetch(GUICtrlRead($menu1)," ","%") with a blank space in the second argument Thanks for the help Edited April 14, 2011 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. 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