Sign in to follow this  
Followers 0
lavascript

While loop while input field is active not working as expected?

6 posts in this topic

Hopefully this is a dumb, easy question.

I have three input fields, and I would like to parse the data entered in the first field to generate default data for the other two. But I only want that to run while the first field has focus, or else the data could not be changed.

So I imagined I could use a While loop testing the state of $name, expecting it to be 256 (The value of $GUI_FOCUS from GUIConstantsEx.au3). But when I do that, the functions never run. I checked the state of the field with a Label, and it shows that the state is 80. (There's no GUI Constant for 80.) It seems to return 80, though, regardless of whether the field has focus or not.

When I While Loop on 80, as soon as the field loses focus, it locks up.

What gives?

GUICreate("New Account",265,110,-1,-1,-1,-1,$mainwindow)
GUICtrlCreateLabel("Full Name:",5,7)
GUICtrlCreateLabel("Username:",5,32)
GUICtrlCreateLabel("Password:",5,57)
Dim $name = GUICtrlCreateInput("",60,5,200,20)
Dim $uname = GUICtrlCreateInput("",60,30,200,20)
Dim $pass = GUICtrlCreateInput("",60,55,200,20)
Dim $newacctbtn = GUICtrlCreateButton("Create Account",5,80,100,25)
Dim $state = GUICtrlCreateLabel("",230,90)
GUISetState(@SW_SHOW)

While True
Dim $msg2 = GUIGetMsg()
;GUICtrlSetData($state,GUICtrlGetState($name))
While GUICtrlGetState($name) = XXX
GUICtrlSetData($uname,NameToUname(GUICtrlRead($name)))
GUICtrlSetData($pass,GenPass(GUICtrlRead($name)))
WEnd
If $msg2 = $newacctbtn Then MsgBox(0,"","snth")
If $msg2 = -3 Then ExitLoop
WEnd

Func NameToUname($input)
If $input <> "" And StringInStr($input," ") > 0 Then
Local $finit = StringLeft($input,1)
Local $array = StringSplit($input," ")
Local $lname = $array[$array[0]]
Return StringLower($finit & $lname)
Else
Return ""
EndIf
EndFunc

Func GenPass($input)
If $input <> "" And StringInStr($input," ") > 0 Then
Local $finit = StringLeft($input,1)
Local $array = StringSplit($input," ")
Local $linit = StringLeft($array[$array[0]],1)
Return StringLower($finit & $linit & @YEAR)
Else
Return ""
EndIf
EndFunc

Share this post


Link to post
Share on other sites



State values can be summed up as for example $GUI_DISABLE + $GUI_HIDE sets the control in an disabled and hidden state.

There fore you should use

BitAnd()
to get your result

More preferably you could use _Winapi_GetFocus() with the GuiCtrlGetHandle of the Input/Label whichever you want

Hope it helps

Feel free to ask if any doubts are there

Regards

Phoenix XL


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Sorry, brain fart. Of course these numbers are binary!

So my GUICtrlGetState is returning 80, which is 64+16, which is $GUI_ENABLE + $GUI_SHOW. But if the field has focus, shouldn't that also be $GUI_FOCUS?, so 336?

Share this post


Link to post
Share on other sites

You might have better luck getting what you want by intercepting the WM_COMMAND message.

I stuck some beeps() and tooltips() in this example to make it more entertaining:

#include <GuiConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Dim $msg2, $update_flag

GUICreate("New Account",265,110,-1,-1,-1,-1)
GUICtrlCreateLabel("Full Name:",5,7)
GUICtrlCreateLabel("Username:",5,32)
GUICtrlCreateLabel("Password:",5,57)
Dim $name = GUICtrlCreateInput("",60,5,200,20)
Dim $uname = GUICtrlCreateInput("",60,30,200,20)
Dim $pass = GUICtrlCreateInput("",60,55,200,20)
Dim $newacctbtn = GUICtrlCreateButton("Create Account",5,80,100,25)
Dim $state = GUICtrlCreateLabel("",230,90)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While True
    If $update_flag Then
        Beep(800,50)
        $sName = GUICtrlRead($name)
        GUICtrlSetData($uname,NameToUname($sName))
        GUICtrlSetData($pass,GenPass($sName))
        $update_flag = 0
    EndIf
    $msg2 = GUIGetMsg()
    If $msg2 = $newacctbtn Then MsgBox(0,"","snth")
    If $msg2 = -3 Then ExitLoop
WEnd

Func NameToUname($input)
If $input <> "" And StringInStr($input," ") > 0 Then
Local $finit = StringLeft($input,1)
Local $array = StringSplit($input," ")
Local $lname = $array[$array[0]]
Return StringLower($finit & $lname)
Else
Return ""
EndIf
EndFunc

Func GenPass($input)
If $input <> "" And StringInStr($input," ") > 0 Then
Local $finit = StringLeft($input,1)
Local $array = StringSplit($input," ")
Local $linit = StringLeft($array[$array[0]],1)
Return StringLower($finit & $linit & @YEAR)
Else
Return ""
EndIf
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)    ;HiWord
    $nID            = BitAnd($wParam, 0x0000FFFF) ;LoWord
    Switch $nID
        Case $name
            Switch $nNotifyCode
                Case 256 ; gained focus
                 ToolTip("Gained Focus")
                Case 512 ; lost focus
                    ToolTip("Lost Focus")
                Case 768 ; data updated
                 ToolTip("Data Updated")
                 $update_flag = 1
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

Great! I always think about things in a backwards sort of way.

If you wouldn't mind, can you explain a little about what's going on here? Or point me to a resource where I can learn more about Windows Message Codes?

Thanks!

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

    • oceanwind
      By oceanwind
      Hi All:
       How to set the input border color?
      tks in advance
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
    • 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

    • nacerbaaziz
      By nacerbaaziz
      hello
      Greetings to all
      dears i have a big problem in the bass.dll
      e.g
      If you play an audio file using the bass.dll
      and  You changed the audio output
      Such as setting or removing headphones
      The sound output of bass.dll does not change
      Is there any solution
      If it exists, please give it to me
      Greetings and thanks in advance
      I apologize for my bad English