Page 1 of 2 12>
Topic Options
#128072 - 2004-10-18 09:44 PM KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Is there a way that I can break out of the runscripts function when the start button is pressed. It locks up until it completes all the the scripts in the ini file.

Code:
;===============================================================================================

;**** Last Modified on 10/18/2004 at 2:29:07 PM by dkrogol ****
;===============================================================================================

Break On

$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 192,192,192
$Form.ForeColor = 0,128,0
$Form.Height = 550
$Form.Left = 88
$Form.Text = "Company Laptop Utility - @fullname - @wksta"
$Form.Top = 104
$Form.Width = 700
;**************************************

;************* ListView **************
$ListView = $Form.Controls.ListView()
$ListView.Height = 472
$ListView.HeaderStyle = 2
$ListView.Left = 0
$ListView.Top = 30
$ListView.Width = 698
$ListView.OnDoubleClick = "readlog"
;**************************************

;************* startbutton **************
$startbutton = $Form.Controls.Button()
$startbutton.Cancel = "True"
$startbutton.Default = "True"
$startbutton.FlatStyle = 3
$startbutton.FontBold = "True"
$startbutton.Height = 22
$startbutton.Left = 15
$startbutton.Text = "Start"
$startbutton.ToolTipText = "Executes daily tasks"
$startbutton.Top = 4
$startbutton.Width = 69
$startbutton.OnClick = "runscripts()"
;**************************************

;************* Exit **************
$Exit = $Form.Controls.Button()
$Exit.FlatStyle = 3
$Exit.FontBold = "True"
$Exit.Height = 22
$Exit.Left = 615
$Exit.Text = "Exit "
$Exit.ToolTipText = "Exit application"
$Exit.Top = 4
$Exit.Width = 71
$Exit.OnClick = "Quit()"
;**************************************

;************* logo **************
$logo = $Form.Controls.PictureBox()
$logo.BackColor = 192,192,192
$logo.BorderStyle = 0
$logo.Height = 50
$logo.Left = 285
$logo.Picture = "c:\mtglaptop\bmp\logo1.bmp"
$logo.Top = 0
$logo.Width = 125
;**************************************

;************* user **************
$user = $Form.Controls.Label()
$user.BackColor = 192,192,192
$user.FontBold = "True"
$user.ForeColor = 0,0,0
$user.Height = 13
$user.Left = 105
$user.Text = "User: @fullname"
$user.Top = 9
$user.Width = 160
;**************************************

;************* PCName **************
$PCName = $Form.Controls.Label()
$PCName.BackColor = 192,192,192
$PCName.FontBold = "True"
$PCName.ForeColor = 0,128,64
$PCName.Height = 15
$PCName.Left = 15
$PCName.Text = "Computer Name: @wksta"
$PCName.Top = 510
$PCName.Width = 211
;**************************************

;************* ipaddress **************
$ipaddress = $Form.Controls.Label()
$ipaddress.BackColor = 192,192,192
$ipaddress.FontBold = "True"
$ipaddress.ForeColor = 0,128,0
$ipaddress.Height = 16
$ipaddress.Left = 510
$ipaddress.Text = "IP Address: @ipaddress0"
$ipaddress.Top = 510
$ipaddress.Width = 171
;**************************************

;************* Date_Day **************
$Date_Day = $Form.Controls.Label()
$Date_Day.BackColor = 192,192,192
$Date_Day.FontBold = "True"
$Date_Day.ForeColor = 0,128,0
$Date_Day.Height = 15
$Date_Day.Left = 285
$Date_Day.Text = "@day - @Monthno/@Mdayno/@year"
$Date_Day.Top = 502
$Date_Day.Width = 128
;**************************************

;KD END


$= $ListView.Columns.Add("Job",175)
$= $ListView.Columns.Add("Start",100)
$= $listview.Columns.Add("End",100)
$= $ListView.Columns.Add("Logfile",200)
$= $ListView.Columns.Add("Status",119)


$Form.Show
While $Form.Visible
$=Execute($System.Application.DoEvents())
$item=$listview.items.add
$Item.SubItems(0).Text = ("Session Completed Sucessfully")
Loop
Exit 1

Function runscripts ()
$form.Refresh()
Del "c:\mtglaptop\logs\*.*"
If Exist($inifile)
$ScriptArray = Split(ReadProfileString($inifile,"",""),Chr(10))
For Each $script in $ScriptArray
If Val(ReadProfileString($inifile,$script,"run"))
$starttime=@TIME
$message=ReadProfileString($inifile,$script,"message")
$log=ReadProfileString($inifile,$script,"log")
If $testrun=3
MessageBox ("Requestable job available. Do you want to run $message?","Requestable job",36,0)
EndIf
$item=$listview.items.add
$Item.SubItems(0).Text = ($message)
$Item.SubItems(1).Text = ($starttime);(@FULLNAME +"\"+ @USERID)
$Item.SubItems(3).Text = ($log)
$Item.SubItems(4).Text = ("Running")
Select
Case InStr ($script,".exe")
Shell $script
Case InStr ($script,".kix")
Call $script
EndSelect
Do
Sleep 0.5
Until
Exist ("c:\mtglaptop\logs\"+$log)
$Item.SubItems(2).Text=(@time)
$Item.SubItems(4).Text=("Complete")

EndIf
Next
EndFunction




Edited by Fugazi (2004-10-18 09:51 PM)
_________________________
I haven't failed. I just found another way that did not work.

Top
#128073 - 2004-10-18 09:48 PM Re: KiXform Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well.,...
I don't see next in there...

fix the script first.
_________________________
!

download KiXnet

Top
#128074 - 2004-10-18 09:53 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Added the next. Missed it on the copy/paste.
_________________________
I haven't failed. I just found another way that did not work.

Top
#128075 - 2004-10-18 10:03 PM Re: KiXform Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, now do something like this:
$yourstopButton.onclick="$$yourstopButton.tag=1"

and in your loop:
if $yourstopButton.tag=1
exit 1 ;Exit the runscripts udf per users request
endif

good place might be right before the next.
_________________________
!

download KiXnet

Top
#128076 - 2004-10-19 04:42 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
I have tried that senario by placing it after the next and in the DO loop in runscripts() in both senarios the kixform shuts down after running the first script from the INI and leaving the Kixtart DOS window in a hung state. The line I am editing for the exit is

Code:
 $Exit.OnClick = "$$exit.tag=1" 



Runscripts()

Code:
Do 

If $$exit.tag=1
Quit()
EndIf
Until
Exist ("c:\mtglaptop\logs\"+$log)
$Item.SubItems(2).Text=(@time)
$Item.SubItems(4).Text=("Complete")
EndIf
Next







Edited by Fugazi (2004-10-19 04:43 PM)
_________________________
I haven't failed. I just found another way that did not work.

Top
#128077 - 2004-10-19 05:25 PM Re: KiXform Help
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
This isn't the complete 'runscripts()', it would spew errors if it were
Post it completely ...
_________________________



Top
#128078 - 2004-10-19 05:30 PM Re: KiXform Help
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There is no such function as Quit(). There is however a Quit command and as a command it does not need parens. You should always provide the not-so-optional parm to both Quit and Exit.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128079 - 2004-10-19 05:32 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
I have changed the "$Exit.OnClick" to "ExitApp.OnClick"

Code:
 $ExitApp.OnClick = "$$ExitApp.OnClick=1" 




Code:
Function runscripts ()

Del "c:\mtglaptop\logs\*.log"
If Exist($inifile)
$ScriptArray = Split(ReadProfileString($inifile,"",""),Chr(10))
For Each $script in $ScriptArray
If Val(ReadProfileString($inifile,$script,"run"))
$leave=0
$starttime=@TIME
$message=ReadProfileString($inifile,$script,"message")
$log=ReadProfileString($inifile,$script,"log")
If $testrun=3
MessageBox ("Requestable job available. Do you want to run $message?","Requestable job",36,0)
EndIf
$item=$listview.items.add
$Item.SubItems(0).Text = ($message)
$Item.SubItems(1).Text = ($starttime);(@FULLNAME +"\"+ @USERID)
$Item.SubItems(3).Text = ($log)
$Item.SubItems(4).Text = ("Running")
Select
Case InStr ($script,".exe")
Shell $script
Case InStr ($script,".kix")
Call $script
EndSelect
Do
If $$ExitApp.OnClick =1
Quit()
EndIf
Until
Exist ("c:\mtglaptop\logs\"+$log)
$Item.SubItems(2).Text=(@time)
$Item.SubItems(4).Text=("Complete")

EndIf
Next


EndFunction

_________________________
I haven't failed. I just found another way that did not work.

Top
#128080 - 2004-10-19 05:40 PM Re: KiXform Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Dont forget something VERY important - to do with events. Events don't get dispatched unless you stick a DoEvents call somewhere inside your long loops - very, very important. So for example, if you had a long loop like this:

For $i = 0 to 10000000

; Doing something ...

Next

Any events generated while in this loop will just stay pending until the loop finishes (and control is returned somehow back to the DoEvents loop). To get things to work as expected, have to do this:

For $i = 0 to 10000000

; Doing something ...

$= Execute($Form.DoEvents)

Next

This way, events will get checked and dispatched on each iteration.

-Shawn

Top
#128081 - 2004-10-19 07:06 PM Re: KiXform Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dunno why but all of you guys missed this:
If $$ExitApp.OnClick =1

which surely would cause problems.
remove the double dollar sign from there and shoot on.
_________________________
!

download KiXnet

Top
#128082 - 2004-10-19 07:49 PM Re: KiXform Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jooel, nice catch, even for a newbie (hehee chuckle)


Top
#128083 - 2004-10-19 10:13 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
I have removed the $$ and replaced with this string. It never seems to get to the UNTIL statement.

Code:
 Do 
sleep 0.5
If $exitapp.tag = 1
$=Execute($ExitApp.DoEvents)
$item=$listview.items.add
$Item.SubItems(0).Text = ("User Aborted Session")
$ExitApp.Tag = "1"
Quit 1
EndIf

Until
Exist ($locallog+$log)

_________________________
I haven't failed. I just found another way that did not work.

Top
#128084 - 2004-10-19 10:23 PM Re: KiXform Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
could you show your current full code now...
to see the big picture, sorta...
_________________________
!

download KiXnet

Top
#128085 - 2004-10-19 10:31 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
I have 2 scripts controling the program.


Laptop.kix

;This script will keep kixtart scripts and system files up to date
;and call the control script.

Break on
;SetConsole ("hide")
Global $localscripts,$netscripts,$workdir,$oralogon,$logpath,$netpath,
$locallog,$errmsg,$runerr,$clients,$logfile,$netlogs,$inifile
$workdir = "c:\mtglaptop\"
$localscripts = "c:\mtglaptop\scripts\"
$netscripts = "\\Server\Share\mtglaptop\scripts\"
$netpath = "\\Server\Share\mtglaptop\"
$netlogs="\\Server\Share\kixlogs\mtglaptop\@USERID\"
$oralogon = "c:\oracle\ora81\bin\sqlplus user/password" + Chr(64) + "database"
$locallog= "c:\mtglaptop\logs\"
$runerr="c:\mtglaptop\errmsg.kix"
$clients="\\Server\Share\clients\"
$inifile = "c:\mtglaptop\settings.ini"

If NOT Exist ($netpath +"control.kix")
$errmsg="Unable to contact SERVER."
Gosub error
EndIf

;VUIA = verify user is authorized
$veruser = ReadProfileString ($netpath + "vuia.dat",USER,@USERID)
Select
Case
$veruser="admin"
Case $veruser <> @WKSTA
$errmsg="INVALID USER-You are NOT authorized to run this application"
Gosub error
EndSelect

If NOT Exist ($localscripts)
MD $localscripts
EndIf

If NOT Exist ($netlogs)
MD $netlogs
EndIf

Del $workdir + "files.dat"
Del $locallog + "*.log"

$sysfile = CompareFileTimes ($netpath + "settings.ini", $workdir + "settings.ini")
Select
Case $sysfile = 1
Copy $netpath+"settings.ini" $workdir
Case $sysfile = -3
Copy $netpath+"settings.ini" $workdir
EndSelect

$sysfile = CompareFileTimes ($netpath + "control.kix", $workdir + "control.kix")
Select
Case $sysfile = 1
Copy $netpath+"control.kix" $workdir
Case $sysfile = -3
Copy $netpath+"control.kix" $workdir
EndSelect

Shell "%comspec% /e:1024 /c dir " + $netscripts + " /b > " + $workdir + "\files.dat"
Shell "%comspec% /e:1024 /c dir " + $localscripts + " /b >> " + $workdir + "\files.dat"

:filechk
If Open(1,$workdir+"files.dat",2)
"Error opening file list."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
$file=ReadLine(1)
While NOT @ERROR
$compare = CompareFileTimes($netscripts + $file,$localscripts+$file)
Select
Case $compare = 1
Copy $netscripts + $file $localscripts
?"Case 1 copying " + $netscripts + $file
Case $compare = -2
Del $localscripts + $file
?"Deleting " + $localscripts + $file
Case $compare = -3
Copy $netscripts + $file $localscripts
?"Case 2 copying " + $netscripts + $file
Case $compare = 0
?$file + " Did not need to be updated"
EndSelect
$file=ReadLine(1)
Loop
$=Close(1)
EndIf

Call $workdir +"control.kix"
Exit 0

:error
Call $runerr
Exit 0


Control.kix

Code:
 ;===============================================================================================

;**** Last Modified on 10/19/2004 at 3:22:45 PM by a021515 ****
;===============================================================================================


Break On
;SETOPTION('explicit','on')
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 192,192,192
$Form.ForeColor = 0,128,0
$Form.Height = 550
$Form.Left = 88
$Form.Text = "Company Laptop Utility - @fullname - @wksta"
$Form.Top = 104
$Form.Width = 700
$Form.DoEvents = ""
;**************************************

;************* ListView **************
$ListView = $Form.Controls.ListView()
$ListView.Height = 472
$ListView.HeaderStyle = 2
$ListView.Left = 0
$ListView.Top = 30
$ListView.Width = 698
$ListView.OnDoubleClick = ""
;**************************************

;************* startbutton **************
$startbutton = $Form.Controls.Button()
$startbutton.Cancel = "True"
$startbutton.Default = "True"
$startbutton.FlatStyle = 3
$startbutton.FontBold = "True"
$startbutton.Height = 22
$startbutton.Left = 15
$startbutton.Text = "Start"
$startbutton.ToolTipText = "Executes daily tasks"
$startbutton.Top = 4
$startbutton.Width = 69
$startbutton.OnClick = "runscripts()"
;**************************************

;************* ExitApp **************
$ExitApp = $Form.Controls.Button()
$ExitApp.FlatStyle = 3
$ExitApp.FontBold = "True"
$ExitApp.Height = 22
$ExitApp.Left = 610
$ExitApp.Text = "Exit "
$ExitApp.ToolTipText = "Exit application"
$ExitApp.Top = 4
$ExitApp.Width = 71
$ExitApp.OnClick = "$exitapp.tag = 1"
;**************************************

;************* logo **************
$logo = $Form.Controls.PictureBox()
$logo.BackColor = 192,192,192
$logo.BorderStyle = 0
$logo.Height = 50
$logo.Left = 285
$logo.Picture = "c:\mtglaptop\bmp\logo1.bmp"
$logo.Top = 0
$logo.Width = 125
;**************************************

;************* user **************
$user = $Form.Controls.Label()
$user.BackColor = 192,192,192
$user.FontBold = "True"
$User.ForeColor = 0,0,0
$user.Height = 13
$user.Left = 105
$user.Text = "User: @fullname"
$user.Top = 9
$user.Width = 160
;**************************************

;************* PCName **************
$PCName = $Form.Controls.Label()
$PCName.BackColor = 192,192,192
$PCName.FontBold = "True"
$PCName.ForeColor = 0,128,64
$PCName.Height = 15
$PCName.Left = 15
$PCName.Text = "Computer Name: @wksta"
$PCName.Top = 510
$PCName.Width = 211
;**************************************

;************* ipaddress **************
$ipaddress = $Form.Controls.Label()
$ipaddress.BackColor = 192,192,192
$ipaddress.FontBold = "True"
$ipaddress.ForeColor = 0,128,0
$ipaddress.Height = 16
$ipaddress.Left = 510
$ipaddress.Text = "IP Address: @ipaddress0"
$ipaddress.Top = 510
$ipaddress.Width = 171
;**************************************

;************* Date_Day **************
$Date_Day = $Form.Controls.Label()
$Date_Day.BackColor = 192,192,192
$Date_Day.FontBold = "True"
$Date_Day.ForeColor = 0,128,0
$Date_Day.Height = 15
$Date_Day.Left = 285
$Date_Day.Text = "@day-@Monthno/@Mdayno/@year"
$Date_Day.Top = 502
$Date_Day.Width = 128
;**************************************

?$ExitApp.OnClick

;KD END


$= $ListView.Columns.Add("Job",175)
$= $ListView.Columns.Add("Start",100)
$= $listview.Columns.Add("End",100)
$= $ListView.Columns.Add("Logfile",200)
$= $ListView.Columns.Add("Status",119)


$Form.Show

While $Form.Visible
$=Execute($System.Application.DoEvents())
$item=$listview.items.add
$Item.SubItems(0).Text = ("Session Completed Sucessfully")
Loop
Exit 1

Function runscripts ()
Del "c:\mtglaptop\logs\*.log"
If Exist($inifile)
$ScriptArray = Split(ReadProfileString($inifile,"",""),Chr(10))
For Each $script in $ScriptArray
If Val(ReadProfileString($inifile,$script,"run"))

$starttime=@TIME
$message=ReadProfileString($inifile,$script,"message")
$log=ReadProfileString($inifile,$script,"log")
If $testrun=3
MessageBox ("Requestable job available. Do you want to run $message?","Requestable job",36,0)
EndIf
$item=$listview.items.add
$Item.SubItems(0).Text = ($message)
$Item.SubItems(1).Text = ($starttime);(@FULLNAME +"\"+ @USERID)
$Item.SubItems(3).Text = ($locallog + $log)
$Item.SubItems(4).Text = ("Running")
Select
Case InStr ($script,".exe")
Shell $script
Case InStr ($script,".kix")
Call $script
EndSelect
EndIf

Do
sleep 0.5
If $exitapp.tag = 1

$=Execute($Form.DoEvents)
$item=$listview.items.add
$Item.SubItems(0).Text = ("User Aborted Session")
$ExitApp.Tag = "1"
Quit 1
EndIf

Until
Exist ($locallog+$log)


$Item.SubItems(2).Text=(@time)
$Item.SubItems(4).Text=("Complete")


Next

EndFunction



Edited by Fugazi (2004-10-19 11:08 PM)
_________________________
I haven't failed. I just found another way that did not work.

Top
#128086 - 2004-10-19 11:11 PM Re: KiXform Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Woops, my boo, should be:

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

This is the asynchronous doevent we want. The 1 means dont wait aroundif there aren't any events.


Top
#128087 - 2004-10-19 11:20 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Same results. I can cick on the "Exit Button" but nothing happens. Is the $= Execute($Form.DoEvents(1)) in the right location?


Code:
 Do

Sleep 0.5
If $exitapp.tag=1
$= Execute($Form.DoEvents(1))
$item=$listview.items.add
$Item.SubItems(0).Text = ("User Aborted Session")
$ExitApp.Tag = "1"
Quit 1
EndIf
Until
Exist ($locallog+$log)

_________________________
I haven't failed. I just found another way that did not work.

Top
#128088 - 2004-10-20 10:38 AM Re: KiXform Help
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Already wondered if you've changed something in that DoEvents method to Autorecognize the needed behavior
_________________________



Top
#128089 - 2004-10-20 10:41 AM Re: KiXform Help
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Fugazi no it isn't ... it should be not kept inside a conditional statement but rather be available throughout the whole loop cycle.
Reads: just place it right before until or right after do
_________________________



Top
#128090 - 2004-10-20 03:40 PM Re: KiXform Help
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Thanks moving the $= Execute($Form.DoEvents(1)) to after the do statement worked. I thought I tried that but obviously didn't since it now works.

I also change and added the following so events could be logged

Code:
$ExitApp.OnClick = "Leave()"  



and added the function Leave()

Code:

Function Leave()
Open (9,$locallog + @USERID +".csv",5)
WriteLine (9,"," + @DATE+"," + @TIME + "User Aborted Session $message"+@CRLF)
Close (9)
Quit
EndFunction



Now for my next question since this is my first attempt utilizing KiXform. How do I clear the form? Or should I start a new chain for this discussion?
_________________________
I haven't failed. I just found another way that did not work.

Top
#128091 - 2004-10-20 03:45 PM Re: KiXform Help
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Clear the form in which way ?

More precise please...
_________________________



Top
Page 1 of 2 12>


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

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

Generated in 0.08 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

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