#93016 - 2003-09-29 04:23 PM
Clock counting with Execution of functions
|
dasiguer
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
|
|
|
|
#93025 - 2003-10-01 02:16 PM
Re: Clock counting with Execution of functions
|
dasiguer
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
   
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
   
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
|
|
|
|
#93030 - 2003-10-01 05:08 PM
Re: Clock counting with Execution of functions
|
Shawn
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
|
|
|
|
#93033 - 2003-10-01 06:35 PM
Re: Clock counting with Execution of functions
|
Shawn
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
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
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|