Jump to content

odd loop question/problem


Recommended Posts

i got a script with a GUI and my script updates the GUI every second or so but if I hit close on the GUI it sleeps for that second and the data being told in while loop to be send to the GUI has to be constant

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Cancel
            Exit
    EndSwitch
    Sleep(250)
    ;do something 
WEnd

i don't like seeing flicking while updating gui thats what the sleeps for

Edited by testingtest
Link to comment
Share on other sites

i got a script with a GUI and my script updates the GUI every second or so but if I hit close on the GUI it sleeps for that second and the data being told in while loop to be send to the GUI has to be constant

i don't like seeing flicking while updating gui thats what the sleeps for

The code you showed does not reproduce the symptoms as it will not flicker the GUI because it doesn't change anything. Write a short demo that creates a GUI and shows how you are updating it.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thats why you check to see if somehting needs updating before updating it on the gui

but i want it to have a good effect

#include <GUIConstants.au3>
$Example = GUICreate("Length = 16" , 252 , 120, 0 , 0 , $WS_CLIPSIBLINGS)
$Encode = GUICtrlCreateInput("133-A75-321-8K26", 8, 32, 233, 21)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Cancel
            Exit
    EndSwitch
    Sleep(250)
    WinSetTitle($Example , "" , "Length = " & StringLen(GUICtrlRead($Encode)))
WEnd
Link to comment
Share on other sites

but i want it to have a good effect

This does a few things:

1. Adds $Cancel, which was causing an error

2. Eliminates flickering by only updating when there is a change (as danwilli suggested)

3. Tightens up the message loop so it doesn't miss clicking on things

Note that there is no Sleep(). GuiGetMsg() has an effective Sleep(10) built into it, so you don't need any more.

#include <GUIConstants.au3>

$Example = GUICreate("Length = 16", 252, 120, 0, 0)
$Encode = GUICtrlCreateInput("133-A75-321-8K26", 8, 32, 233, 21)
$Cancel = GUICtrlCreateButton("Cancel", 76, 80, 100, 30)
GUISetState(@SW_SHOW)

$sEncode = ""
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit
    EndSwitch
    If GUICtrlRead($Encode) <> $sEncode Then
        $sEncode = GUICtrlRead($Encode)
        WinSetTitle($Example, "", "Length = " & StringLen($sEncode))
    EndIf
WEnd

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This does a few things:

1. Adds $Cancel, which was causing an error

2. Eliminates flickering by only updating when there is a change (as danwilli suggested)

3. Tightens up the message loop so it doesn't miss clicking on things

Note that there is no Sleep(). GuiGetMsg() has an effective Sleep(10) built into it, so you don't need any more.

#include <GUIConstants.au3>

$Example = GUICreate("Length = 16", 252, 120, 0, 0)
$Encode = GUICtrlCreateInput("133-A75-321-8K26", 8, 32, 233, 21)
$Cancel = GUICtrlCreateButton("Cancel", 76, 80, 100, 30)
GUISetState(@SW_SHOW)

$sEncode = ""
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit
    EndSwitch
    If GUICtrlRead($Encode) <> $sEncode Then
        $sEncode = GUICtrlRead($Encode)
        WinSetTitle($Example, "", "Length = " & StringLen($sEncode))
    EndIf
WEnd

:)

works great but can you explain so I can learn from it please.

I thought <> was another form of =

and is it checking for input

Link to comment
Share on other sites

works great but can you explain so I can learn from it please.

I thought <> was another form of =

and is it checking for input

Auto it doesn't use '!' for 'NOT', but '<>' would be equivalent to '!=' if it did.

Read the help file under 'Operators'

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...