Sign in to follow this  
Followers 0
remin

GuiCtrlRead and GUICtrlSetData values not updated

8 posts in this topic

#1 ·  Posted (edited)

I created a search GUI with an InputBox and a Button to empty the input box.

I read the inputbox using GuiCtrlRead and empty the input box using GUICtrlSetData.

When I click a search button or click the "empty inputbox" button, everything works fine.

However after having done the 1st search and I click again on the search button

or whatever other button the input box field is not updated 

GUICtrlRead($RWSearch)  --> gives a value '0'

What did I wrong?

Same thing when I empty the input box.

The 1st time it works well.

When I empty the inputbox after having done a search it doesn't

work anymore. Nothing happens.

My search GUI is always on TOP so I don't reuse the hotkey between searches.

(The GUI is not deleted after a search), 

 

My code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")


While 1
    Sleep(10000)
WEnd

Func searchmenu()

global $url
Send("^c")
$InEditBox = ClipGet()

;========GUI=============
 $Form5 =         GUICreate("Search Menu", 345, 410, 100, 100)
 $RWSearch =      GUICtrlCreateInput($InEditBox,                      16,  10, 270, 25)
 $clipc =         GUICtrlCreateButton("x",                           300,  10,  15, 20)
 $textGoogle  =   GUICtrlCreateLabel("Google:",                       20,  50, 100, 20)
 $bsearch =       GUICtrlCreateButton("Search",                      110,  50,  60, 20)
 $bimages =       GUICtrlCreateButton("Images",                      175,  50,  60, 20)

GUISetState(@SW_SHOW)
;========GUI=============

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

   Case $GUI_EVENT_CLOSE
        GuiDelete($Form5)
        ExitLoop

      Case $clipc
           ; empty inputbox
           GUICtrlSetData($RWSearch, "")

      Case $bsearch
           ; search text in google 
           $RWSearch = GUICtrlRead($RWSearch)
           $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
           $url = "https://www.google.com/search?q=" & $RWSearch
           SearchMenuExec()

      Case $bimages
           ; search images in google
           $RWSearch = GUICtrlRead($RWSearch)
           $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
           $url = "http://images.google.com/images?hl=en&q=" & $RWSearch
           SearchMenuExec()

EndSwitch
 WEnd
EndFunc

Func SearchMenuExec()
  ClipPut($url)
  ShellExecute($url) 
EndFunc
Edited by remin

Share this post


Link to post
Share on other sites



Hi Remin,

  It is working fine for me, I did notice that every time you hit CTRL + 4 it opens a new GUI. Did you want that?

Maybe deleting the GUI after the search would solve some of the problems you are having, and the hotkey will just open anew GUI every time.

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")
Global $url


While 1
    Sleep(10000)
WEnd

Func searchmenu()

    Send("^c")
    $InEditBox = ClipGet()

    ;========GUI=============
    $Form5 = GUICreate("Search Menu", 345, 410, 100, 100)
    $RWSearch = GUICtrlCreateInput($InEditBox, 16, 10, 270, 25)
    $clipc = GUICtrlCreateButton("x", 300, 10, 15, 20)
    $textGoogle = GUICtrlCreateLabel("Google:", 20, 50, 100, 20)
    $bsearch = GUICtrlCreateButton("Search", 110, 50, 60, 20)
    $bimages = GUICtrlCreateButton("Images", 175, 50, 60, 20)

    GUISetState(@SW_SHOW)
    ;========GUI=============

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg

            Case $GUI_EVENT_CLOSE
                GUIDelete($Form5)
                ExitLoop
                Return 0

            Case $clipc
                ; empty inputbox
                GUICtrlSetData($RWSearch, "")
                ExitLoop
            Case $bsearch
                ; search text in google
                $RWSearch = GUICtrlRead($RWSearch)
                $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
                $url = "https://www.google.com/search?q=" & $RWSearch
                SearchMenuExec()
                ExitLoop

            Case $bimages
                ; search images in google
                $RWSearch = GUICtrlRead($RWSearch)
                $RWSearch = StringRegExpReplace($RWSearch, "(\s+)", "+")
                $url = "http://images.google.com/images?hl=en&q=" & $RWSearch
                SearchMenuExec()
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete()

EndFunc   ;==>searchmenu



Func SearchMenuExec()
    ClipPut($url)
    ShellExecute($url)
EndFunc   ;==>SearchMenuExec

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@Billo,

Thank you for your reply.

I forgot to write in my question that my search GUI is always on TOP so I don't reuse the hotkey between searches.

(The GUI is not deleted after a search), 

(I'll update my question)

Edited by remin

Share this post


Link to post
Share on other sites

No Problem,

  it seems to me the idea was pretty cool to be able to hotkey paste anything you've hi-lited into your search box and then hit search or image and have the gui disappear until needed again.

  anyway, thats what the one does that I posted above. just like yours with a few minor changes.

Good luck.

Share this post


Link to post
Share on other sites

Tnx, but it is not what I want.

I want to keep the GUI, clicking on a button and read with every search the inputbox again.

Share this post


Link to post
Share on other sites

Maybe something like this? I tried to clean it up a bit but it still is very bad formated. Clean up whatever you dont need and remove the #includes that are useless...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>

HotKeySet("^4", "searchmenu")
Global $url


While 1
Sleep(10000)
WEnd

Func searchmenu()

Send("^c")
$InEditBox = ClipGet()

;========GUI=============
$Form5 = GUICreate("Search Menu", 345, 410, 100, 100)
$RWSearch = GUICtrlCreateInput($InEditBox, 16, 10, 270, 25)
$clipc = GUICtrlCreateButton("x", 300, 10, 15, 20)
$textGoogle = GUICtrlCreateLabel("Google:", 20, 50, 100, 20)
$bsearch = GUICtrlCreateButton("Search", 110, 50, 60, 20)
$bimages = GUICtrlCreateButton("Images", 175, 50, 60, 20)
GUISetState(@SW_SHOW)
;========GUI=============

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE
GUIDelete($Form5)
Exit
Case $clipc
; empty inputbox
GUICtrlSetData($RWSearch, "")
Case $bsearch
; search text in google
$RWSearch1 = GUICtrlRead($RWSearch)
$RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")
$url = "https://www.google.com/search?q=" & $RWSearch2
SearchMenuExec()
Case $bimages
; search images in google
$RWSearch1 = GUICtrlRead($RWSearch)
$RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")
$url = "http://images.google.com/images?hl=en&q=" & $RWSearch2
SearchMenuExec()
EndSwitch
WEnd
EndFunc ;==>searchmenu



Func SearchMenuExec()
ClipPut($url)
ShellExecute($url)
EndFunc ;==>SearchMenuExec

Share this post


Link to post
Share on other sites

Wow.. great thank you.

That resolved my question  :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • XinYoung
      By XinYoung
      Hello all,
      I've been working on 4 standalone scripts. They each have their own GUI and are now independent .exe's. But instead of having 4 separate icons on my computer, is it possible to put them all together into one .exe?
      What I want is one interface with tabs. Each script's GUI would be on their own respective tab. Is this possible?
      The different scripts don't need to communicate with one another. I just want them all in one .exe.
      I can't find this anywhere... Any help would be greatly appreciated. Thank you!
    • way1000
      By way1000
      i'm trying to create a program that let's the user type a word in an input field (gui) and when a button is pressed the letters of the word are replaced by 1 word each from a list of words in a text file
      i created the gui for it but i need help to add some more code to make it work like intented

      each letter of a word should be replaced by a word from a text file
      the text file is a source for replacing letters is a file with 2 columns separated by tab that contains the entire alphabet (26 rows)
       
      please help if possible
       
      i posted an example gui screenshot

    • kawliga751
      By kawliga751
      I have a workplace GUI that has a search field function that pulls up customer records to allow changes. I am attempting to 1)LOGIN 2)Enter Search field, enter a number and then {ENTER} 3)change specific field once customer record loads. I have very limited experience in GUI manipulation but I am able to login using the below:
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/ASAG/index.htm') Call ("RacksheetSignIn") Func RacksheetSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/RackSheets/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc However I can't seem to use the _IEGetObjByName or Mouseclick to focus on the search field to allow me to enter my search criteria. When I "inspect element" in the Search field I get the attached:
       
      Any help would be MUCH appreciated
       
       
       

    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • FMS
      By FMS
      Hello,
      As I was searching this forum I came along something intresting what was new to me.
      CUI/GUI hybrid.
      Whish sounds very usefull to me to compile it all into 1 script.
      So i was fideling around whit it but couldn't get it to work.
      In the real script (not this simplified version) i got a lot of functions whish i can use whan talking to it by commandline and switches.
      I could not get this to work and hope somebody could give me some pointers on how to make it work.
      Also I was hoping iff somebody could help me whit the /? function?
      (I don't know how to output the help text back to the commandline or the function that can help me do it)
      please advice and thanks in advanced.
      #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #include <Process.au3> #include <Array.au3> If $CmdLine[0] = 0 Then If _ProcessGetName(ProcessGetParent(@AutoItPID)) = "cmd.exe" Then ;ConsoleWrite("Program was started in CMD" & @CRLF) If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!") If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!") For $i = 1 To $CmdLine[0] Step 2 If $CmdLine[$i] = "/switch" Then MsgBox(64, "Passed Parameters", "/switch is " & $CmdLine[$i+1]) If $CmdLine[$i] = "/?" Then MsgBox(64, "Passed Parameters", "/? " ) Next _ArrayDisplay($CmdLine) Else #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 239, 65, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 32, 24, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 120, 24, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 button1() Case $button2 button2() EndSwitch WEnd EndIf EndIf Exit Func button1() MsgBox(16, "title", "button1()!") EndFunc Func button2() MsgBox(16, "title", "button1()!") EndFunc Func ProcessGetParent($i_PID) ;get PID from parent process done by SmOke_N Local $TH32CS_SNAPPROCESS = 0x00000002 Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0) If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_PID) Local $tagPROCESSENTRY32 = _ DllStructCreate( _ "dword dwsize;" & _ "dword cntUsage;" & _ "dword th32ProcessID;" & _ "uint th32DefaultHeapID;" & _ "dword th32ModuleID;" & _ "dword cntThreads;" & _ "dword th32ParentProcessID;" & _ "long pcPriClassBase;" & _ "dword dwFlags;" & _ "char szExeFile[260]" _ ) DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32)) Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32) Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_PID) Local $a_pnext, $i_return = 0 If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) If $i_return Then Return $i_return Return $i_PID EndIf While @error = 0 $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") If $i_return Then ExitLoop $i_return = $i_PID ExitLoop EndIf WEnd DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) Return $i_return EndFunc ;==>ProcessGetParent