Source language: Translate to:

Subroutines

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Subroutines

Postby stevec » Wed Mar 07, 2007 9:24 pm

Is it possible to run two subroutines at the same time?
If so, how to do it.

Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby HPW » Thu Mar 08, 2007 12:27 am

Your question is not clear.

One subroutine called inside another one (nested)?

Or 2 parallel running subroutines?
Most things in neobook are sequentiel one after another.
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

thanks

Postby stevec » Thu Mar 08, 2007 2:12 am

thanks for the reply.
I beleieve I would mean parallel. or seperately at the same time.

Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby Sam Cox » Thu Mar 08, 2007 5:41 am

Hello Steve,

Can you tell something about what you'd like to accomplish running two subroutines at once? Neobook and most other programming languages do not provide for this, but Neobook does have Timer objects that might serve your purpose. A Timer can be set to "fire" periodically and thereby give the impression of executing a separate and parallel code stream.

-- Sam
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

subroutines

Postby stevec » Thu Mar 08, 2007 8:51 am

I have a pub that does the following;

*******************

:Memory
ClearVariables "[MemFree],[MemTot],[Mem5],[Mem6],[Mem7]"
rtMemoryTotal
SetVar "[MemTot]" "[rtResult2]"
rtMemoryFree
SetVar "[MemFree]" "[rtResult2][MemFree]"
Math "[MemTot]/10" "0" "[Mem5]"
Math "[MemFree]/10" "0" "[Mem6]"
Math "[Mem5]-[Mem6]" "0" "[Mem7]"
Delay "2000"
If "[PF2]" "=" "Change"
tmCoolProgBarSetValue "R9" "0"
Else
EndIf
tmCoolProgBarCreate "R1"
tmCoolProgBarType "R1" "1"
tmCoolProgBarLook "R1" "1"
tmCoolProgBarBGColor "R1" "0" "128" "255"
tmCoolProgBarBlockSpaceSize "R1" "22" "1"
tmCoolProgBarShowInactive "R1" "1"
tmCoolProgBarSetValue "R1" "[Mem7]"
tmCoolProgBarMax "R1" "100"
tmCoolProgBarStartcolor "R1" "0" "255" "0"
tmCoolProgBarFinalcolor "R1" "255" "0" "0"
If "[CB1]" "=" "checked"
tmCoolProgBarShowCaptionPercent "R1" "1"
tmCoolProgBarShowCaption "R1" "1"
Else
EndIf
If "[Mem7]" ">=" "61"
SetVar "[A1]" "Free Resources"
SetObjectFont "A1" "Red" "Arial" "10" "Normal" "DEFAULT_CHARSET"
Else
If "[Mem7]" "<=" "60"
ClearVariables "[A1]"
SetVar "[A1]" "OK"
SetObjectFont "A1" "Aqua" "Arial" "10" "Normal" "DEFAULT_CHARSET"
EndIf
EndIf
SetVar "[Mem7]" "0"
If "[PF2]" "=" "Change"
tmCoolProgBarSetValue "R9" "3200"
Else
EndIf
GotoLine "2"

**************************************

I have added the dec_sys plugin to capture the CPU usage


Processor Usage [dec_ProcessorUsage]

I have included this into the above subroutine, also to craete a bar graph using Cool Progressbar. It works to the point that on shutdown of the pub I get the following error:

Code: 0xc0000005
Flags: 0x0000000

If I disable the CPU usage part, it closes fine. I think that if the
CPU usage is in a seperate sub/timer routine, I could eliminate the error message.
I have tried to clear the variable with a delay, before the app exits and I still get the error message.

Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby Neosoft Support » Thu Mar 08, 2007 12:50 pm

It looks like you have the subroutine running in a loop which ironically uses a lot of system resources and is probably what's causing the problem. Instead, try moving this part of the subroutine to a Timer object:

Code: Select all
rtMemoryTotal
SetVar "[MemTot]" "[rtResult2]"
rtMemoryFree
SetVar "[MemFree]" "[rtResult2][MemFree]"
Math "[MemTot]/10" "0" "[Mem5]"
Math "[MemFree]/10" "0" "[Mem6]"
Math "[Mem5]-[Mem6]" "0" "[Mem7]"
Delay "2000"
If "[PF2]" "=" "Change"
tmCoolProgBarSetValue "R9" "0"
Else
EndIf
tmCoolProgBarCreate "R1"
tmCoolProgBarType "R1" "1"
tmCoolProgBarLook "R1" "1"
tmCoolProgBarBGColor "R1" "0" "128" "255"
tmCoolProgBarBlockSpaceSize "R1" "22" "1"
tmCoolProgBarShowInactive "R1" "1"
tmCoolProgBarSetValue "R1" "[Mem7]"
tmCoolProgBarMax "R1" "100"
tmCoolProgBarStartcolor "R1" "0" "255" "0"
tmCoolProgBarFinalcolor "R1" "255" "0" "0"
If "[CB1]" "=" "checked"
tmCoolProgBarShowCaptionPercent "R1" "1"
tmCoolProgBarShowCaption "R1" "1"
Else
EndIf
If "[Mem7]" ">=" "61"
SetVar "[A1]" "Free Resources"
SetObjectFont "A1" "Red" "Arial" "10" "Normal" "DEFAULT_CHARSET"
Else
If "[Mem7]" "<=" "60"
ClearVariables "[A1]"
SetVar "[A1]" "OK"
SetObjectFont "A1" "Aqua" "Arial" "10" "Normal" "DEFAULT_CHARSET"
EndIf
EndIf
SetVar "[Mem7]" "0"
If "[PF2]" "=" "Change"
tmCoolProgBarSetValue "R9" "3200"
Else
EndIf


Set the Timer object's interval to 200 or 500 milliseconds then delete the subroutine.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5605
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Thanks

Postby stevec » Thu Mar 08, 2007 3:00 pm

thanks for the reply.
I made the changes and it appears to correct it half the time.
I think whenyou close the application, if it hits the timer while the
variable is being run, that's when it gives the error message.
I have tried to use the TimerStop to correct this, but it still comes up
about half the time.
Any other ideas would be appreciated.

Thanks again;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

coolprogressbar

Postby stevec » Thu Mar 08, 2007 3:54 pm

Yes I tried that. I have several bars and none of them have the
reaction. Only if I use the CPU-usage.

Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby Gaev » Thu Mar 08, 2007 5:43 pm

stevec:

a) I do not have any of the plugins you are deploying in your pub ... so I can not replicate your situation ... perhaps you can confirm if running a pub with JUST the dec_sys plugin command to capture the CPU usage ...

Processor Usage [dec_ProcessorUsage]

... also results in errors at exit time.

And if it does, you might invoke it just once ... then display a message ... so you can manually close the program ... see if that concludes without errors.
Any other ideas would be appreciated.

Perhaps you can provide details of ...

i) where in the pub you start the Timer

ii) how the program is terminated ... Exit Button ? ... Windows Close Button ?

iii) is this all the program does ?

iv) does the Timer run from start to finish of the program ?


One solution would be to delay the exiting of the program until (any) dec_sys plugin command is completed ... this could be accomplished via a variable (say [ExitRequested]) ... when a shutdown is requested by user, this variable would be set (to TRUE) ... the TimerInterval routine would check this variable just before doing the dec_sys plugin commands ... if true, it would initiate an exit from the program ... otherwise invoke the commands
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Thanks Gaev

Postby stevec » Thu Mar 08, 2007 5:55 pm

The dec_sys plugin command works well on it's own.
I'm using the Processor Usage [dec_ProcessorUsage] to feed a
progress bar. The variable [dec_ProcessorUsage] is called thru the memory subroutine to update at intervals. Its a hit or miss when you'll get the error message, I'd say about 50% of the time, when your closing out the app. Thats why I believe that when the variable is being called that's when it causes Windows to generate the error message.

If I use the [dec_ProcessorUsage], and just let it stay static [non-changing] there are no error messages.

I suppose a kill process or variable would work, but stopping the subroutine is another thought, but I haven't figured that out.

Here is a link of the app that I have.

http://shadocontrol.bravehost.com/PCHelp.htm

Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

I think I got it

Postby stevec » Fri Mar 09, 2007 11:26 am

Gaev,Sam, and all

Thanks for the EXCELLENT advise, I think I have a work around for the error message.

I created the following sub-routine

:Exit
SetVar "[dec_ProcessorUsage]" "0"
Delay "1000"
Exit "" ""


Sets the variable to 0, delays and then exits.

Many Many Thanks for the help.
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby Sam Cox » Fri Mar 09, 2007 12:34 pm

Hi Steve,

I'm glad you found a solution. Instead of using a subroutine, may I suggest putting your shutdown code in the Book Properties > Actions > Shutdown code section? All code in that section executes when the program terminates for any reason. It executes when you issue the Exit "" "" command; it executes when you click the pub's close-program button (upper right corner of window); and it even executes when you terminate the program via Task Manager. It has the added advantage of not having to be explicitly called.

-- Sam
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Sam Thanks

Postby stevec » Fri Mar 09, 2007 12:51 pm

Sam;
Thanks. Great advise and help as usual.

Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest