Jump to content
Sign in to follow this  
lavascript

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

Recommended Posts

lavascript

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
PhoenixXL

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
lavascript

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
Spiff59

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
lavascript

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  

  • Similar Content

    • ShakeelAhmad
      By ShakeelAhmad
      I've to upload different number of photos online in different assignments. There is a problem that all photos cannot be selected at once to upload. I have to choose and upload photos one by one. For this purpose I have made a script to automate whatever I have to do manually for choosing and uploading photos one by one.
      Please see my script below and check the last "MouseClick" command. This command clicks the button to choose and upload next photo. The problem I'm facing is; the last "MouseClick" works 1 step extra when all photos have been selected and uploaded. I mean if 7 photos are to be uploaded, this command opens the box from where next photo is selected and uploaded then it again opens the box and next photo is choosen and so on.... when last photo is selected and uploaded, this button once again opens the box. When all photos are uploaded, it should not click the button to select next photo. Please suggest how can I resolve this issue.
      #include <AutoItConstants.au3> Sleep(200) HotKeySet("{ESC}","Quit") ;Press ESC key to quit Send("{ALT DOWN}") Send("{TAB}") Send("{ALT UP}") Sleep(200) Local $photos = InputBox("Question", "How many photos to upload?", "#", "", _ - 1, -1, 0, 0) ; How many photos to upload Local $selector = 0 While $photos <> $selector MouseClick("Left", 281, 238, 1) ; mouse click on very first photo in the box. if $selector = 0 Then Send("{ENTER}") ; for selecting very first photo from "open" window. Sleep(800) Else sleep(200) Send("{RIGHT " & $selector & "}") ; for selecting 2nd to onward photos from "open" window. sleep(1000) Send("{ENTER}") sleep(1000) EndIf MouseClick("Left", 495, 198, 1) ; for clicking a button to choose next photo to upload $selector = $selector + 1 WEnd Beep(1500, 300) ; beep when all photos uploaded Exit Regards,
       
      Shakeel
    • Dzenan03
      By Dzenan03
      I want to make a while loop, that creates variables based on a array. For thist I created the array $iDsO with the number and the name of folders in an other folder. Every folder has a different name an I want to create variables(arrays) for each folder that show me all the files in that folder. For example: I have the Folder \Folder1. In it there are the Folders \1, \2, \3. In 1, 2 and 3 there are some files(.png). The array for Folder1 is $iDsO and now I want to crate the arrays $iDsO1, $iDsO2 and $iDsO3 with the files in them can I make something like this:
      While $iDs > 0 ;$iDs is the number of files in Folder1>> $iDsO[0] $iDs#here should come the Foldername for example '1'# = _FileListtoArray(@ProgramFilesDir&"\Folder1\"&$iDsO[$iDs]) $iDs = $iDs - 1 Wend So that in the End I have three variabels ($iDs1, $iDs2 and $iDs3)
       
      Is this posible or if not what could I do instead ( I don´t know the number of folders in Folder1 in the begining).
    • 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
×