Jump to content

GuiCtrlread not retrieving informations correctly when into a function


Newb
 Share

Recommended Posts

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 :unsure:):

#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

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 by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

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 by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

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 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...