Sign in to follow this  
Followers 0
CodeTinkerer

Issue with While Loop

7 posts in this topic

#1 ·  Posted (edited)

Ok sorry if this counts as a Re-Post. I posted the question in my original thread but have not gotten any feedback, figured I would phrase it a little differently.

So, I have a full-screen (Static Dimensions for my screen) pop-up window activated by a button. Using WinSetTrans and a While loop when the window is called via the button I want it to fade in. ESC is set as a hotkey to exit the window and fade out and then deleting the GUI window and controls.

My issue is that on the machine that I am scripting on, it works beautifully. While on other systems with different specs it will close faster or slower by a huge margin.

Is there a way to have a constant fade speed regardless of the CPU processing?

Here is a snippet (sorry if my code is still messy looking, still working on etiquette lol):

Func PopJobForm()
global $BG = GUICreate("Job Forms", 1440, 900, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
global $Main_Gui = GUICreate("", 1440, 900, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
global $G = GUICtrlCreateLabel("Press ESC to Close", 1140, 12, 288, 36, $SS_CENTER)
global $GUIActiveX = GUICtrlCreateObj ($oIE, 35, 75, 1360, 768)
local $oIE = ObjCreate("Shell.Explorer.2")
$oIE.navigate("http://coin/sites/west/CentralDivision/WIFulfillCenter/Lists/SRO%20Filler%20Work/AllItems.aspx")
HotKeySet("{ESC}", "QuitPop")


$n = 0
$way = 0
   WinSetTrans($Main_Gui,"",0)
While WinExists($BG)
        WinSetTrans("Job Forms","",$n)
        if $n <= 35 then
            $n = $n + .05
        ElseIf $n > 35 And $n < 75 Then
            $n = $n + .1
        ElseIf $n > 75  And $n < 120 Then
            $n = $n + .2
        ElseIf $n > 120 And $n < 195 Then
            $n = $n + .3
         ElseIf $n > 195 AND $Way = 0 And $n < 250 Then
            $Way = 2
            _ShowBrowser($Way)
         EndIf
WEnd
QuitPop()
EndFunc

Func _ShowBrowser($oNF)
   GUISetControlsVisible($Main_Gui)
   GUISetState(@SW_SHOW,$Main_Gui)
   If $oNF = 2 Then
   Local $z = 0
   While 1
        WinSetTrans($Main_Gui,"",$z)
        if $z <= 35 then
            $z = $z + .4
        ElseIf $z > 35 And $z < 75 Then
            $z = $z + 1
        ElseIf $z > 75  And $z < 120 Then
            $z = $z + 2
        ElseIf $z > 120 And $z < 195 Then
            $z = $z + 3
         ElseIf $z > 195 and $z < 250 Then
            WinSetTrans($Main_Gui,"",255)
            ExitLoop
        EndIf
     WEnd
    EndIf
EndFunc


Func QuitPop()
   $n = 196

   While 1
      if $n <=  1 then
         $n = $n - .3
         exitloop
      ElseIf $n < 75 Then
         $n = $n - .1
      ElseIf $n < 300 and $n > 75 Then
         $n = $n - .05
      EndIf
      WinSetTrans($Main_Gui,"",$n)
      WinSetTrans($BG,"",$n)
WEnd
   HotKeySet("{ESC}")
   GUIDelete( $GUIActiveX )
   GUIDelete( $Main_Gui )
   GUIDelete( $BG )
EndFunc
Edited by CodeTinkerer

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

How are you sure that the CPU is the culprit?

 

 I guess im just assuming really. If I run the script on a machine matching specs with mine, runs fine. If its on a machine with older  specs, it behaves in the manner mentioned above. actually have not attempted on a faster machine yet. (Assumptions again, going to get me in some trouble. I apologize) first thing that came to mind was CPU processing speed. 

I am by no means concrete that its CPU, if someone has another hypothesis by all means im all ears!

Edited by CodeTinkerer

Share this post


Link to post
Share on other sites

Use a loop similar to this to control your fade in and fade out. This should result in a smooth fade taking approximately the same time on any PC.

Local $Trans = 0
   ;fade in
   While $Trans < 255
      WinSetTrans($Main_Gui,"",$Trans)
      $Trans += 1
      sleep(20) ; <<<<<===== This will keep the speed of fade approximately the same on slow and fast CPU Local
                ; <<<<< Lager value for sleep will slow it down small to speed it up
    WEnd

   ;fade out
   $Trans = 255
   While $Trans > 0
      WinSetTrans($Main_Gui,"",$Trans)
      $Trans -= 1
      sleep(20) ; <<<<<===== This will keep the speed of fade approximately the same on slow and fast CPU Local
                ; <<<<< Lager value for sleep will slow it down small to speed it up
    WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 

Use a loop similar to this to control your fade in and fade out. This should result in a smooth fade taking approximately the same time on any PC.

Local $Trans = 0
   ;fade in
   While $Trans < 255
      WinSetTrans($Main_Gui,"",$Trans)
      $Trans += 1
      sleep(20) ; <<<<<===== This will keep the speed of fade approximately the same on slow and fast CPU Local
                ; <<<<< Lager value for sleep will slow it down small to speed it up
    WEnd

   ;fade out
   $Trans = 255
   While $Trans > 0
      WinSetTrans($Main_Gui,"",$Trans)
      $Trans -= 1
      sleep(20) ; <<<<<===== This will keep the speed of fade approximately the same on slow and fast CPU Local
                ; <<<<< Lager value for sleep will slow it down small to speed it up
    WEnd

 

Thank you for your feedback! The issue with this method would be I wouldnt be able to have the screen show at the speed that I am wanting because of Sleep()'s limitation of how low the increment can be set, i need it to go lower. this way is considerably slower than my method (even though mine is probably not as clean/neat/efficient)

Edited by CodeTinkerer

Share this post


Link to post
Share on other sites

Replace the Sleep() with a timer loop.

$time = 1 ; 1 millisecond
$Timer = TimerInit()
While $Trans > 0
    WinSetTrans($Main_Gui, "", $Trans)
    $Trans -= 1
    Do
    Until TimerDiff($Timer) >= $time
    $Timer = TimerInit()
WEnd
1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

 

Replace the Sleep() with a timer loop.

$time = 1 ; 1 millisecond
$Timer = TimerInit()
While $Trans > 0
    WinSetTrans($Main_Gui, "", $Trans)
    $Trans -= 1
    Do
    Until TimerDiff($Timer) >= $time
    $Timer = TimerInit()
WEnd

 

Holy crap! MUCH smoother transition on the fade. will test this on the other machines to see if this hopefully resolved my issue! Thank you for your assistance, will post back with results :)

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