Sign in to follow this  
Followers 0
jozizo

Beginner Issue: Continually Checking and Returning Text with WinGetText

5 posts in this topic

I think everything is working as designed, I'm just not understanding...well...I'm not sure what I'm not understanding. I'm a bit new, so please forgive if this is an easy one.

I have the following function:

Func WrapCheck()
   Local $sText = WinGetText("Direction")
   $iWrap = StringRegExp($sText, "UP")

If $iWrap == 1 Then
    $iWrapMsg = "It's Up!"
ElseIf $iWrap == 0 Then
    $iWrapMsg = ""
EndIf
Return $iWrapMsg
EndFunc

And when I need the results, I use:

$iWrapLabel = GUICtrlCreateLabel(WrapCheck(), 10, 140, 225, 60)

The window "Direction" has a bit of text. Either Up....or something else all together. I'm checking for "Up" explicitly. That's all I want to look for. If it's not there, I don't need anything returned really.

The problem is, this only works once I run the script. I have the Label within my main loop (the 'While 1' part).

When I run the script, manually changing the text from my source window, it works. It returns exactly what I want it to. But, if the text in the window changes to "Up", my label doesn't update with it.

If at all possible, I would really like to learn HOW to fish. So a direction in a concept or perhaps I'm not seeing the logic or something I would really appreciate that. But if I'm way off base I'll totally just take the fish for now. Any help is greatly appreciated.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Change the call to StringRegExp to StringReplace and instead of checking the variable, check @extended for the number of time it's been replaced. Like so: (optional, you can keep doing it the way you have been)

If @extended > 0 Then
    $iWrapsMsg = "It's Up!"
Else
    $iWrapMsg = ""
EndIf

;I wouldn't try remaking the label control everytime, but use:
;If you don't use the above conditional, at least try GUICtlSetData intead of creating it everytime in your while loop

GUICtrlSetData($iWrapLabel, $iWrapMsg) ; this will update the label with the value you have gotten from doing your conditional statement

Also, storing the creation of the Label control in the while loop is not a good practice, I would keep it where you create the GUI, and update it everytime the function is ran.

Please let me know if you have questions or comments :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Jozizo,

Look up AdlibRegister

It will run that function by default every 250ms

Share this post


Link to post
Share on other sites

Posting your whole script will also help us help you ;)

1 person likes this

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Jozizo,

Look up AdlibRegister

It will run that function by default every 250ms

 

this is your best bet. You can also call it with a button, and even turn it off with AdlibUnRegister, its a very handy and simple func and I use it often for watchdog functions.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

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