Jump to content

General Help... :D [NOT-SOLVED] my bad... :P


Recommended Posts

I'm working on a program that will monitor the time he has been connected to a VNC session, because he does remote support... etc.

The label flickers like a pissed off seizure, and I'm stuck doing a logical function (Should be easy)... Start/Stop timer...

I just can't get the math to work, my attempts were stripped right before I pasted the script so you guys wouldn't know just how bad I am with math... >.<

You will see the main 2 problems in the code below... :)

; INCLUDES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; Situating Things before GUI;;;;;;;;;;;;;;;;;;
Global $Start, $Sec, $Min, $Hour, $Time, $Begin
$TimerDone = False
$Time = 0
$StoredTime = 0
FileInstall("C:\Users\BinaryBrother\Downloads\new\winvnc_SCIII.exe",@TempDir & "\SC-VNC.exe",1)
FileInstall("C:\Users\BinaryBrother\Downloads\new\helpdesk.txt",@TempDir & "\helpdesk.txt",1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;HIDE VNC FOR 6 SECONDS;;;;;;;;;;;;;;;;;;;;;;;;;;
Run(@TempDir & "\SC-VNC.exe",@TempDir)
AdlibEnable("TimerVNC",1000)
While $TimerDone = False
    WinSetState("Blanked #48291","",@SW_HIDE)
WEnd
AdlibDisable()
Func TimerVNC()
    $Time += 1
    If $Time >= 6 Then
        $TimerDone = True
    EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; BEGIN GUI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Opt("GUIOnEventMode", 1)
$TimerGUI = GUICreate("Timer", 395, 243, 264, 261)
GUISetOnEvent($GUI_EVENT_CLOSE, "TimerClose")

$Button1 = GUICtrlCreateButton("Start Timer", 24, 176, 153, 49, 0)
GUICtrlSetFont($Button1, 12, 800, 0, "Arial")
GUICtrlSetOnEvent($Button1, "StartClick")

$Button2 = GUICtrlCreateButton("Stop Timer", 216, 176, 153, 49, 0)
GUICtrlSetFont($Button2, 12, 800, 0, "Arial")
GUICtrlSetOnEvent($Button2, "StopClick")

$Label1 = GUICtrlCreateLabel("", 90, 32, 320, 113)
GUICtrlSetFont($Label1, 72, 800, 0, "Arial Narrow")
GUICtrlSetColor($Label1, 0x800000)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;AdlibEnable("UpdateGUI",1000)

While 1
    If $Start = True Then

        AdlibEnable("Timer",1000)
    EndIf
WEnd

; calculate with time

;_TicksToTime($EndTicks,$Hour,$Min,$Sec)
;TrayTip("New Time:" &  $Hour & ":" & $Min & ":" & $Sec) 


Func StartClick()
    $Begin = TimerInit()
    AdlibEnable("Timer",1000)
EndFunc

Func StopClick()
    AdlibDisable()
EndFunc

Func TimerClose()
    Exit
EndFunc

Func Timer()
    $Difference = TimerDiff($Begin)
    _TicksToTime($Difference,$Hour,$Min,$Sec)
    GUICtrlSetData($Label1,$Hour & ":" & $Min & ":" & $Sec)
EndFunc


Func UpdateGUI()
    GUISetState(@SW_SHOW)
EndFunc
Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

If you continually change the label text it will flicker so don't keep changing it when there is no need.

For example

$LaelSetCase1 = False
.
.
.
while $start
 if not $labelsetCase1
   GuicTrlSetData($label.....
   $LabelSetCase1 = true
 endIf
wend
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

here is the change it wont flicker anymore.

by the way you need to change putty.exe back to your vnc.exe

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
; INCLUDES;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; Situating Things before GUI;;;;;;;;;;;;;;;;;;
Global $Start, $Sec, $Min, $Hour, $Time
$TimerDone = False
$Time = 0
$StoredTime = 0
;FileInstall("C:\Users\BinaryBrother\Downloads\new\winvnc_SCIII.exe",@TempDir & "\SC-VNC.exe",1)
;FileInstall("C:\Users\BinaryBrother\Downloads\new\helpdesk.txt",@TempDir & "\helpdesk.txt",1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;HIDE VNC FOR 6 SECONDS;;;;;;;;;;;;;;;;;;;;;;;;;;
Run(@ScriptDir & "\putty.exe",@TempDir)
AdlibEnable("Timer",1000)
While $TimerDone = False
    WinSetState("Blanked #48291","",@SW_HIDE)
WEnd
Func Timer()
    $Time += 1
    If $Time >= 6 Then
        $TimerDone = True
    EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; BEGIN GUI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Opt("GUIOnEventMode", 1)
$TimerGUI = GUICreate("Timer", 395, 243, 264, 261)
GUISetOnEvent($GUI_EVENT_CLOSE, "TimerClose")

$Button1 = GUICtrlCreateButton("Start Timer", 24, 176, 153, 49, 0)
GUICtrlSetFont($Button1, 12, 800, 0, "Arial")
GUICtrlSetOnEvent($Button1, "StartClick")

$Button2 = GUICtrlCreateButton("Stop Timer", 216, 176, 153, 49, 0)
GUICtrlSetFont($Button2, 12, 800, 0, "Arial")
GUICtrlSetOnEvent($Button2, "StopClick")

$Label1 = GUICtrlCreateLabel("", 90, 32, 320, 113)
GUICtrlSetFont($Label1, 72, 800, 0, "Arial Narrow")
GUICtrlSetColor($Label1, 0x800000)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;AdlibEnable("UpdateGUI",1000)

While 1
    Sleep(100)
WEnd

; calculate with time

;_TicksToTime($EndTicks,$Hour,$Min,$Sec)
;TrayTip("New Time:" &  $Hour & ":" & $Min & ":" & $Sec) 


Func StartClick()
    $Start = True
    
    If Not $StoredTime = 0 Then
        $Begin = Timerinit()
        While $Start = True
            _TicksToTime(TimerDiff($Begin) - 1000,$Hour,$Min,$Sec)
            Sleep(1000)
            GUICtrlSetData($Label1,$Hour & ":" & $Min & ":" & $Sec)
        WEnd
    Else
        $Begin = TimerInit()
        While $Start = True
            $Difference = TimerDiff($Begin)
            _TicksToTime($Difference - 1000,$Hour,$Min,$Sec)
            Sleep(1000)
            GUICtrlSetData($Label1,$Hour & ":" & $Min & ":" & $Sec)
        WEnd
    EndIf
    $StoredTime = $Begin + TimerDiff($Begin)
EndFunc
Func StopClick()
    $Start = False
EndFunc
Func TimerClose()
    Exit
EndFunc

Func UpdateGUI()
    GUISetState(@SW_SHOW)
EndFunc
Edited by unixu
Link to comment
Share on other sites

@Martin

Great suggestion! Dunno why I didn't think of that. :)

@unixu

I actually don't see what you changed in the script... :idea:

I thought I edited that in... apparently not... I found it... :P

I'm probably going to stick with Martin's idea so that I can eliminate Sleeping in the proggy, but thanks for all the support guys...

Any ideas on how to effectively Start/Stop a timer? I'm giving the above link a look as we speak. :party:

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

look over your StartClick function and you will notice what i changed :)

you can change the gui constantly without problems but you must add a small delay.

the problem the delay is sleep

sleep pauses all functions so the sleepdelay must be abstracted from the timer just look you will see :party:

sry dont have much time gtg to work

Edited by unixu
Link to comment
Share on other sites

Ahh... No Start/Stop ideas in the above link... :)

If I was just a bit smarter with Math I really believe this would be cake... My instructor always said Math was an important part of programming, which I never believed until now... >.<

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Stopping is easy... "Restarting" "Resuming" is the hard part... :party:

Because the previous time has to be calculated in with the new into the timer... :idea:

First Post with Script has been revised.

@unixu

I'm listening to you, sorry my posts haven't seemed like it... :P

I removed the loops, and went with Adlib instead, as far as Sleep() I try to avoid that as much as possible. :P

It's just a habit I've formed...

The only thing I need to figure out now is How to save the time, so that I can "Resume" the timer... :D

Upper management is probably thinking 'Jeez... Give this guy a math lesson...' The logic seems easy, it's just one of those things I can't think straight on... :D

For reference:

First issue was resolved with Martin's method. (Only update the label with it needs updating)

Second issue was resolved by (http://www.autoitscript.com/forum/index.ph...mp;hl=stopwatch)

@unixu

Thanks for all the helpful suggestions, and please don't let the fact that I used Martin's idea discourage you from trying to help me in the future, God knows I'll need it... :)

I am brain-dead and still need help... Simply put... WHY doesn't this work???

Func StartClick()
    If $FirstRun = True Then
        $Begin = TimerInit()
        $FirstRun = False
    EndIf
    AdlibEnable("Timer",1000)
EndFunc

Func StopClick()
    $Begin += TimerDiff($Begin)
    AdlibDisable()
EndFunc

Func TimerClose()
    Exit
EndFunc

Func Timer()

    $Difference = TimerDiff($Begin)
    
    _TicksToTime($Difference,$Hour,$Min,$Sec)
    GUICtrlSetData($Label1,$Hour & ":" & $Min & ":" & $Sec)
EndFunc
Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

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...