Page 1 of 2 12>
Topic Options
#93016 - 2003-09-29 04:23 PM Clock counting with Execution of functions
dasiguer Offline
Fresh Scripter

Registered: 2003-09-10
Posts: 22
Loc: Rio de Janeiro - Brazil
[Moderatror (Sealeopard): Moved thread from 'Scripts' to 'COM' forum]

Friends had indicated me so that the clock is counting, to use this code:

code:
 while $frmMain.Visible 
$_ = execute($frmMain.DoEvents)
loop

This is my code of execution of the functions:

code:
 $prgStatus.Max = Ubound($FuncToExecute)+1 
For Each $sFunction in $FuncToExecute
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
Sleep 1
Next

But if I to use the two codes, the clock is counting and the functions are stops until finishing the counting it clock.

If I to inside place the line

code:
 $_ = execute($frmMain.DoEvents) 

in my code

code:
 $prgStatus.Max = Ubound($FuncToExecute)+1 
For Each $sFunction in $FuncToExecute
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
$_ = execute($frmMain.DoEvents)
Sleep 1
Next

the clock starts to count until being executed the first function. The clock stop until being executed the function, later the clock continue and stop again to be executed the second function. This happens until being executed all the functions.

How I can make so that a clock is counting together on the execution of the functions in a form?

[ 29. September 2003, 23:33: Message edited by: sealeopard ]

Top
#93017 - 2003-09-29 04:32 PM Re: Clock counting with Execution of functions
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
First of all, you should specify that you are actually talking about a KiXforms script.

Secondly, you should also post the script you are talking about as the fragments are not really helpful.

I also do not see any clock referenced inside your script. I only see a counter being incremented.

Based on the insufficient info provided by you, I'd say that
code:
$prgStatus.Max = Ubound($FuncToExecute)+1
For Each $sFunction in $FuncToExecute
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
Sleep 1
Next

shound be sufficient for you.

Finally, please read the KiXforms Manual and the example scripts on http://www.kixforms.org as they do explain what the DoEvents loop does, namely process events happening withoin KiXforms.

[ 29. September 2003, 16:36: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#93018 - 2003-09-29 04:52 PM Re: Clock counting with Execution of functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
think Daniel refers to this topic on kixforms.org
_________________________



Top
#93019 - 2003-09-29 04:55 PM Re: Clock counting with Execution of functions
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If he refers to the same topic on the KiXforms BBS, then this topic does not make sense.
_________________________
There are two types of vessels, submarines and targets.

Top
#93020 - 2003-09-29 06:56 PM Re: Clock counting with Execution of functions
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Also, since this is a KiXforms issue, does this not rightfully belong in the COM forum?

Mods?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93021 - 2003-09-29 11:31 PM Re: Clock counting with Execution of functions
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
He did post script parts. But, yes, I'd rather have it in COM as I think he doesn't understand event-driven scripting with regards to KiXforms. I will therefore move it.
_________________________
There are two types of vessels, submarines and targets.

Top
#93022 - 2003-09-29 11:46 PM Re: Clock counting with Execution of functions
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I have no freaken idea neither.
but still I suggest you to change:
$_ = execute($frmMain.DoEvents)

to:
$_ = execute($frmMain.DoEvents(1))

[ 29. September 2003, 23:50: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#93023 - 2003-09-30 08:27 AM Re: Clock counting with Execution of functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
That's what we suggested at kixforms.org topic.
Still the clock display will be inaccurate as the task execution takes some time !

Oh yeah, it might get a bit better if you get rid of that sleep 1 statement [Wink]
_________________________



Top
#93024 - 2003-09-30 04:26 PM Re: Clock counting with Execution of functions
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
It's really hard to tell what acutally is going on as the posted script fragments don't make sense. If there's a code segemnt to update a trime display like @TIME, then there needs to be an OnTime event defined and the DoEvents section is necessary to trigger the timer event.

However, then the other code sections need to reworked, too. If it is just a linear script with an incrementing counter then the DoEvents section is not necessary.

But without the exact details of what the script is supposed to do and the complete code, it's hard to tell.
_________________________
There are two types of vessels, submarines and targets.

Top
#93025 - 2003-10-01 02:16 PM Re: Clock counting with Execution of functions
dasiguer Offline
Fresh Scripter

Registered: 2003-09-10
Posts: 22
Loc: Rio de Janeiro - Brazil
Sorry for all, but mine script is being executed perfectly. But I want to include a clock that is counting during the execution of all script in the same form.
I imagined that somebody already had thought about this situation and could have a problem as this.
I decided to place the same doubt in another forum, because I thought that here it would have other people who could help me, instead of criticizing me and snob me, only for cause that I am lay in the referring subject to the KiX.
In the other forum, I placed an example of script that use here in the company, thinking that somebody could help me with it, but...
Then script is here, showing the clock.
If you executing, summer that the clock will stop to the executed being each function.

code:
if @userid="user"
if @producttype="Windows 98"

Break On
SetConsole("Hide")

;==============================================================
;= Instala automaticamente a Biblioteca necessaria para o KIX.=
;==============================================================

shell "c:\windows\system\regsvr32 /s \\Dell_Server\KiXtart\DLL\kixforms.dll"

;============
;= Saudacao =
;============
$Hour = SubStr("@TIME",1,2)
Select
Case Val("$Hour") < 12
$Saudacao = "Bom Dia"
Case Val("$Hour") > 18
$Saudacao = "Boa Noite"
Case 1
$Saudacao = "Boa Tarde"
EndSelect

;==========================
;= Declaracao das Funcoes =
;==========================

$FuncToExecute=Split("userA,userB,userC,userD",",")

;======================
;= Formulario do Menu =
;======================
$frmMain = CreateObject("Kixtart.Form")
$frmMain.Size = 370,280
$frmMain.Center
$frmMain.Text = "Script de Logon da Rede"
$frmMain.SysMenu = 0

$frmMain.Picture = \\DELL_SERVER\KiXtart\Logo\logotipo2.bmp

;================================
;= Mostrando a Data e o Relogio =
;================================

$lblDay = $frmMain.Label("@DAY, @MDAYNO @MONTH @YEAR",180,5,175,15)
$lblDay.Alignment = 1
$lblDay.Borderstyle = 0

$lblTime = $frmMain.Label(@time,310,20,45,15)
$lblTime.Alignment = 1
$lblTime.Borderstyle = 0

$tmrTime = $frmMain.Timer
$tmrTime.Interval = 1000
$tmrTime.Enabled = 1
$tmrTime.OnTimer = "$$lblTime.Text = @@TIME"

;======================
;= Saudacao e Usuario =
;======================

$lblFName = $frmMain.Label("$Saudacao @FULLNAME!",5,35,350,25)
$lblFName.ForeColor = $frmMain.RGB(0,0,0)
$lblFName.Alignment = 2
$lblFName.FontSize = 15
$lblFName.FontBold = 1
$lblFName.BorderStyle = 0

$lblAdvNut = $frmMain.Label("Bem-vindo à Rede",3,60,356,25)
$lblAdvNut.ForeColor = $frmMain.RGB(0,0,0)
$lblAdvNut.Alignment = 2
$lblAdvNut.FontSize = 11.5
$lblAdvNut.FontBold = 1
$lblAdvNut.BorderStyle = 0

;==========================
;= Informacoes do Usuario =
;==========================
$fraUser = $frmMain.Frame
$fraUser.Size = 350,90
$fraUser.Text = "Informações do usuário:"
$fraUser.Alignment = 2
$fraUser.Center
$fraUser.FontBold = 0
$fraUser.FontSize = 8

$lblUserID = $fraUser.Label("Usuário:",10,20,70,20)
$lblUserID.Alignment = 0
$lblUserID.FontBold = 0
$lblUserID.FontSize = 10
$lblUserID.ForeColor = $frmMain.RGB(0,0,0)

$lblUserID2 = $fraUser.label(LCase(@USERID),80,20,185,20)
$lblUserID2.Alignment = 0
$lblUserID2.FontBold = 0
$lblUserID2.FontSize = 10
$lblUserID2.ForeColor = $frmMain.RGB(0,0,128)

$lblLServer = $fraUser.Label("Servidor:",10,42,70,20)
$lblLServer.Alignment = 0
$lblLServer.FontBold = 0
$lblLServer.FontSize = 10
$lblLServer.ForeColor = $frmMain.RGB(0,0,0)

$lblLServer2 = $fraUser.label(@LSERVER,80,42,185,20)
$lblLServer2.Alignment = 0
$lblLServer2.FontBold = 0
$lblLServer2.FontSize = 10
$lblLServer2.ForeColor = $frmMain.RGB(0,0,128)

$lblLDom = $fraUser.Label("Domínio:",10,64,70,20)
$lblLDom.Alignment = 0
$lblLDom.FontBold = 0
$lblLDom.FontSize = 10
$lblLDom.ForeColor = $frmMain.RGB(0,0,0)

$lblLDom2 = $fraUser.Label(LCase(@DOMAIN),80,64,185,20)
$lblLDom2.Alignment = 0
$lblLDom2.FontBold = 0
$lblLDom2.FontSize = 10
$lblLDom2.ForeColor = $frmMain.RGB(0,0,128)

;==================================
;= Status do Logon e Progress Bar =
;==================================
$fraStatus = $frmMain.Frame
$fraStatus.FontBold = 0
$fraStatus.FontSize = 8
$fraStatus.Alignment = 2
$fraStatus.Size = 350,70
$fraStatus.Center
$fraStatus.Top = $fraUser.Bottom + 5
$fraStatus.Text = "Aguarde enquanto o script de logon está sendo executado!"

$lblStatus = $fraStatus.Label("Processando logonscript...",10,20,260,20)

$prgStatus = $fraStatus.ProgressBar
$prgStatus.Size = 330,20
$prgStatus.Center
$prgStatus.Top = $lblStatus.Bottom

;=================================================
;= Status da Funcao e Formulario do Progress Bar =
;=================================================
$frmFuncStatus = CreateObject("Kixtart.Form")
$frmFuncStatus.Size = 300,80
$frmFuncStatus.Center
$frmFuncStatus.Top = $frmFuncStatus.Top + ($frmMain.Height/2)+50
$frmFuncStatus.SysMenu = 0
$frmFuncStatus.Text = "Processando script de rede..."

$lblFuncStatus = $frmFuncStatus.Label("Processando script de rede...")
$lblFuncStatus.Size = 280,20
$lblFuncStatus.Center
$lblFuncStatus.Top = 5

$prgFuncStatus = $frmFuncStatus.ProgressBar
$prgFuncStatus.Size = 280,20
$prgFuncStatus.Center
$prgFuncStatus.Top = $lblFuncStatus.Bottom

;==================================
;= Script de Execucao das Funcoes =
;==================================
$frmMain.Show

;While $frmMain.Visible
; $nul = execute($frmMain.DoEvents)
;Loop

$prgStatus.Max = Ubound($FuncToExecute)+1
For Each $sFunction in $FuncToExecute
$nul = execute($frmMain.DoEvents)
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
Sleep 1
Next

Exit()

$lblStatus.FontBold = 0
$lblStatus.FontSize = 8

;======================
;= Script das Funcoes =
;======================
Function guerA()
$lblStatus.Text = "Sincronizando o relógio com o Servidor..."
shell "net time \\DELL_SERVER /set /y"
Sleep 1
EndFunction

Function guerB()
$lblStatus.Text = "Mapeando os drives da rede..."

$sNetDrives=Split("H,I,J,L,M,S",",")
shell "net use h: \\dell_server\user /yes"
shell "net use i: \\dell_server\info /yes"
shell "net use j: \\dell_server\cdrom /yes"
shell "net use l: \\dell_server\informatica /yes"
shell "net use m: \\dell_server\manualsiga /yes"
shell "net use s: \\dell_server\ap6 /yes"

$frmFuncStatus.Text = "Mapeando os drives da rede..."
$prgFuncStatus.Max = Ubound($sNetDrives)+1
$prgFuncStatus.Value = ""
$frmFuncStatus.Show
Sleep 0.25
For Each $sDrive in $sNetDrives
$prgFuncStatus.Value = $prgFuncStatus.Value + 1
$lblFuncStatus.Text = "Mapeando $sDrive:\"
Sleep 1
Next
$frmFuncStatus.Hide
Exit()
EndFunction

Function guerC()
$lblStatus.Text = "Aplicando diretivas no registro..."
shell "regedit /s \\dell_server\KiXtart\registryfiles\driveicons.reg"
shell "regedit /s \\dell_server\KiXtart\registryfiles\windowtitle_ie.reg"
shell "regedit /s \\dell_server\KiXtart\registryfiles\Propriedades_do_Video_Ativa.reg"
Sleep 1
EndFunction

Function guerD()
$lblStatus.Text = "Script de logon executado com sucesso!"
Sleep 1
EndFunction

endif
endif

The KiX already was qualified for all the users, but without the clock.
I am trying to resolve this question with my difficulties, but if some of you will be able to help me would be very grateful.
Thanks for the attention of all!

Top
#93026 - 2003-10-01 02:55 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
The one thing you have to realize with event driven Kixscript is that a script can only be doing one thing at a time. A Kixscript has a single thread of execution. When your script is idling in the DoEvents and you have a Timer running, the event code will be executed and the clock will be updated. However, if you call a function, the timer events generated in the meanwhile go unhandled until the function returns to the main loop.

In fact, if timer events go unhandled, they are purposefully thrown into the perverbial bit-bucket to stop them from building up in the message queue. Timer "buildup" if you like. This is expected normal behavior in Kixforms and in single threaded scripts.

The solution to this, is if your calling a function that takes more than a few seconds to run, or if the function has a while or do loop in it, is to place this statement ...

$= Execute($Form.DoEvents(1))

... inside the function call, maybe somewhere in the middle or inside the loop. This is what is called an "asynchronous DoEvents" and it gives the script a chance to execute any pending events (Timers or Clicks), and the clock will be updated in a multi-threaded like fashion (but just by appearance only). Where the DoEvents goes depends on the nature of the function.

-Shawn

[ 01. October 2003, 14:58: Message edited by: Shawn ]

Top
#93027 - 2003-10-01 04:28 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just printed-off this thread and had a closer look. This whole script flow might work better if you changed your loop from this:

code:
For Each $sFunction in $FuncToExecute  
$nul = execute($frmMain.DoEvents)
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
Sleep 1
Next

to this:

code:
For Each $sFunction in $FuncToExecute  
$nul = execute($frmMain.DoEvents(1))
$prgStatus.Value = $prgStatus.Value+1
$nul = Execute($sFunction)
Next

-Shawn

Top
#93028 - 2003-10-01 04:47 PM Re: Clock counting with Execution of functions
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh [Big Grin]
you shawn are good writer.
me was tooo lazy to write that much [Wink]
_________________________
!

download KiXnet

Top
#93029 - 2003-10-01 04:54 PM Re: Clock counting with Execution of functions
dasiguer Offline
Fresh Scripter

Registered: 2003-09-10
Posts: 22
Loc: Rio de Janeiro - Brazil
But making this, the same thing with mine happens script.
It will be that some thing is missed?
I am using the last versions of the KiXtart and KiXform.

Top
#93030 - 2003-10-01 05:08 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmm, ja, then I would put one here too. and remove the sleep ...

code:
For Each $sDrive in $sNetDrives
$prgFuncStatus.Value = $prgFuncStatus.Value + 1
$lblFuncStatus.Text = "Mapeando $sDrive:\"
$=Execute($Form.DoEvents(1))
Next

-Shawn

The more DoEvents you put in, the better the eventing will be. But don't go over-board with this, you don't want "form" to steal from "function" that is to say, don't loose sight of what this script is trying to accomplish - its more important to have a readable script, and a script that works - versus a script that looks pretty and updates the clock accurately.

-Shawn

Top
#93031 - 2003-10-01 05:39 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Plus don't forget, when you do a Kixtart Sleep(), you are basically suspending the script from executing anything, no events can get through no matter how you slice it, so I would suggest you remove ALL your sleep commands.
Top
#93032 - 2003-10-01 05:57 PM Re: Clock counting with Execution of functions
dasiguer Offline
Fresh Scripter

Registered: 2003-09-10
Posts: 22
Loc: Rio de Janeiro - Brazil
Problem happens the same!
I am almost giving up to place the clock, but it is not possible that it is impossible to resolve this problem.

Top
#93033 - 2003-10-01 06:35 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Is there a certain portion of your script where this "problem" is happening specifically. Which lines in your script are taking more than a few seconds to run ? Remember, your script can only do one thing at time (regpoke the registry or update the clock) it can't do both at the same time, unless you want to get into the messy business of spawning-off subscripts (multi-threaded-like) using the RUN command. I don't think you really want to go there just to get a clock to update accurately.

In fact, if I was to recommend something, i would remove the timer from the script altogether, and just update the clock label at fortuitous points though-out your script. The clock will appear to update in a somewhat "chunky" fashion, but what the heck, its just the current time.

Anyways, if there is one part of your script that is taking alot of time, please post the lines ...

-Shawn

[ 01. October 2003, 18:37: Message edited by: Shawn ]

Top
#93034 - 2003-10-01 07:15 PM Re: Clock counting with Execution of functions
dasiguer Offline
Fresh Scripter

Registered: 2003-09-10
Posts: 22
Loc: Rio de Janeiro - Brazil
Well, for the time being I better find to show only the clock, or better, only the date.
Later I will go deep as I can conclude my doubt.
If I had placed my doubt here before, I would not have faced as much difficulty that I passed with one definitive person in the other forum.
You are an excellent profissinal, congratulations!

But plus one he asks!
In the first form that I mounted, I wanted that he appears in a textbox or a label all scripts of each user.
It would be same scripts that they are shown in DOS console. When the KiXtart without no form is used.
As for example, everything what he is executed in my functions

code:
shell "net time \\DELL_SERVER /set /y"
shell "net use h: \\dell_server\user /yes"
shell "net use i: \\dell_server\info /yes"
shell "net use j: \\dell_server\cdrom /yes"
shell "net use l: \\dell_server\informatica /yes"
shell "net use m: \\dell_server\manualsiga /yes"
shell "net use s: \\dell_server\ap6 /yes"
shell "regedit /s \\dell_server\KiXtart\registryfiles\driveicons.reg"
shell "regedit /s \\dell_server\KiXtart\registryfiles\windowtitle_ie.reg"
shell "regedit /s \\dell_server\KiXtart\registryfiles\Propriedades_do_Video_Ativa.reg"

it would be shown in a screen, that only not so fast, he would like to diminish the speed of the execution.

Are you would have some idea of as I can make this?

Top
#93035 - 2003-10-01 07:38 PM Re: Clock counting with Execution of functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, I would suggest that the quick and dirty way to do this would be to use the $lblStatus control to provide this extra level of detail ... in terms of slowing down your script, would suggest using short Sleep() delays for this ... example:

$lblStatus.Text = "Mapeando os drives ..."

$CMD = "net use h: \\dell_server\user /yes"
$lblStatus.Text = $CMD
shell $CMD
sleep(0.500)

$CMD = "net use i: \\dell_server\user /yes"
$lblStatus.Text = $CMD
shell $CMD
sleep(0.500)

$CMD = "net use j: \\dell_server\user /yes"
$lblStatus.Text = $CMD
shell $CMD
sleep(0.500)

And so on and so on ... you would have to customize the delay to suite your environment, etc.

-Shawn

[ 01. October 2003, 19:39: Message edited by: Shawn ]

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.23 seconds in which 0.197 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org