Source language: Translate to:

subroutine question

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

subroutine question

Postby stevec » Wed Mar 11, 2015 5:52 pm

I was wondering if the following was possible:

Action command to run a subroutine;

GoSub Message

SubRoutine: Message
:Message
If "[Message]" "<>" "checked"
GoSub "Buzzer"
Else
If "[Message]" "=" "checked"
StickyNote "-1" "-1" "Bye!" "2000"
Return

Question: How to exit the subroutine back to the Action command to run another subroutine?


second subroutine

:Buzzer
If "[Buzzer]" "<>" "checked"
.GotoLine "Return"
GoSub "Alert"
Else
If "[Buzzer]" "=" "checked"
SoundBuzzer
SoundBuzzer
SoundBuzzer
SoundBuzzer
Return

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

Re: subroutine question

Postby Gaev » Wed Mar 11, 2015 10:25 pm

Steve:

Code: Select all
GoSub "Message"
... upon return from GoSub, the following command will be serviced
AlertBox "Hello" "After GoSub"


In the SubRoutines section ...
Code: Select all
:Message
If "[Message]" "<>" "checked"
   GoSub "Buzzer"
   ... return to the line after the GoSub "Message"
   AlertBox "Hello" "Returning from Messageafter Buzzer"
   Return
Else
   ... this code block will be serviced if [Message] = "checked"
   StickyNote "-1" "-1" "Bye!" "2000"
   ... return to the line after the GoSub "Message after StickyNote"
   AlertBox "Hello" "Returning from Message"
   Return
EndIf


:Buzzer
If "[Buzzer]" "<>" "checked"
   GoSub "Alert"
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after Alert"
   Return
Else
   ... this code block will be serviced if [Buzzer] = "checked"
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after SoundBuzzer"
   Return
Endif


:Alert
... commands for SubRoutine Alert go here
Return


After you understand the path navigated by the code, you can remove the AlertBox commands.
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: subroutine question

Postby stevec » Thu Mar 12, 2015 7:33 am

Gaev;

Many thanks. In playing around and using the debugger, I noticed the removing the return I stopped getting an error.
Thanks, I am using your code and applying it to a flow chart to help with the process. :D :D :D :D
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: subroutine question

Postby Enigman » Sat Aug 22, 2015 2:34 pm

Just a note of protocol here ...

When "Return" is placed in both conditions of an IF block, then it is more efficient to place a single "Return" outside of the IF block. For example, ...

This:
Code: Select all
:Buzzer
If "[Buzzer]" "<>" "checked"
   GoSub "Alert"
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after Alert"
   Return
Else
   ... this code block will be serviced if [Buzzer] = "checked"
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after SoundBuzzer"
   Return
Endif


... is functionally equivalent to this:
Code: Select all
:Buzzer
If "[Buzzer]" "<>" "checked"
   GoSub "Alert"
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after Alert"
Else
   ... this code block will be serviced if [Buzzer] = "checked"
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   SoundBuzzer
   ... return to the line after the GoSub "Buzzer"
   AlertBox "Hello" "Returning from Buzzer after SoundBuzzer"
Endif
Return


... and more efficient. The same is true of any lines of code that are repeated at the end of both conditions.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: subroutine question

Postby stevec » Sat Aug 22, 2015 6:04 pm

Thanks; :) :) :) :)

This is what I am trying to accomplish. (I wish I could post an image of my current pub)
Set up a series of checkboxes that when told to execute, 'if checked' will install a set of software and if not checked will
continue on to the next software. Because each software install is different.

I tried (the coding experts here) might advise to turn the individual software sections into a subroutine. I tried one or two sections, but haven't been successful.

Example;
.......action script......

GotoLine "software1"

:software1
If "[software1]" "<>" "checked"
GotoLine "software2"
Else
If "[software1]" "=" "checked"
SOFTWARE INSTALL ROUTINE
GotoLine "software2"

:software2


I couldn't get a subroutine to work so I used the GoTOLine with the next 'software' listed.

I changed the code below, to omit the actual software and location and used a generic X to replace them with.


Here is what i have right now. I redid the code to the following
.................code begin....................

Delay "500"
GotoLine "software1"

:software1
If "[software1]" "<>" "checked"
GotoLine "software2"
Else
If "[software1]" "=" "checked"
SetVar "[Clipboard]" "xxxxx-xxxxx-XXXXXX"
Run "X\setup.exe" "" "RunOnce+Wait" "" ""
Delay "200"
Run "X\setup.exe" "" "RunOnce+Wait" "" ""
Delay "500"
ExtractFile "[Embedded]software1.reg" "C:\Temp\software1.reg"
Delay "150"
Run "regedit" "!C:\temp\software1.reg" "RunOnce+Wait" "" ""
Delay "500"
FolderExists "C:\Program Files (x86)\software1\Bin" "[x]"


If "[X?]" "=" "AMD64"
GotoLine "AMD64"
Else
If "[X?]" "=" "x86"
GotoLine "Intel"

:AMD64
CreateFolder "C:\Program Files\software1"
Delay "500"
ExtractFile "[Embedded]x.ini" "!C:\x\Bin\x.ini"
Delay "200"
FileErase "!C:\Temp\software1.reg"
GotoLine "software2"

:Intel
ExtractFile "[Embedded]x.ini" "!C:\x\Bin\x.ini"
Delay "200"
FileErase "!C:\Temp\software1.reg"
GotoLine "software2"

:software2
Delay "200"
If "[software2]" "<>" "checked"
GotoLine "software3"
Else
If "[software2]" "=" "checked"
Run "!x\software2\Installsoftware2.bat" "" "RunOnce+Wait" "" ""
Delay "200"
GotoLine "software3"

:software3
If "[software3]" "<>" "checked"
GotoLine "software4"
Else
If "[software3]" "=" "checked"
.Run "x\Setup.exe" "-qb x\_MST" "RunOnce+Wait" "" ""
Run "x\Setup.exe" "-qb x\COB.mst" "RunOnce+Wait" "" ""
Delay "200"
GotoLine "software4"

:software4
If "[software4]" "<>" "checked"
GotoLine "software5"
Else
If "[software4]" "=" "checked"
Run "C:\Program Files\Internet Explorer\iexplore.exe" "http://x/publish.htm" "Wait+LoadComplete" "" ""
GotoLine "software5"

:software5
If "[software5]" "<>" "checked"
GotoLine "software6"
Else
If "[software5]" "=" "checked"
DOSCommand "msiexec" " /i x\x.msi" "RunOnce+Wait"
GotoLine "software6"

:software6
If "[software6]" "<>" "checked"
GotoLine "software7"
Else
If "[software6]" "=" "checked"
Run "C:\Program Files\Internet Explorer\iexplore.exe" "http://index.html" "Wait+LoadComplete" "" ""
GotoLine "software7"

:software7
If "[software7]" "<>" "checked"
GotoLine "software8"
Else
If "[software7]" "=" "checked"
InternetLink "http://Setup.exe"
GotoLine "software8"

:software8
If "[software8]" "<>" "checked"
GotoLine "software9"
Else
If "[software8]" "=" "checked"
lgaDialogLogin "" "Enter your Password for XYZ Server"
Delay "200"
DOSCommand "net " "use N: \\x\install [PwdBoxPwd] /user:Z\[PwdBoxUser]" "RunOnce+Wait"
Delay "1000"
Run "\\x\Setup569.EXE" "" "RunOnce+Wait" "" ""
Delay "500"
Run "\\x.exe" "" "RunOnce+Wait" "" ""
Delay "500"
Run "\\x.exe" "" "RunOnce+Wait" "" ""
ExtractFile "[Embedded]x.reg" "!x.reg"
Delay "200"
AlertBox "" "Click 'YES' to install ODBC Connection"
Run "regedit" "!x.reg" "Normal" "" ""
GotoLine "software9"

:software9
If "[software9]" "<>" "checked"
GotoLine "software10"
Else
If "[software9]" "=" "checked"
Run "\\x.exe" "" "RunOnce+Wait" "" ""
GotoLine "software10"

:software10
If "[software10]" "<>" "checked"
GotoLine "software11"
Else
If "[software10]" "=" "checked"
Run "\x\Setup.exe" "" "RunOnce+Wait" "" ""
GotoLine "software11"


:software11
If "[software11]" "<>" "checked"
GotoLine "software12"
Else
If "[software11]" "=" "checked"
Run "x\5.exe" "" "RunOnce+Wait" "" ""
GotoLine "software12"

:software12
If "[software12]" "<>" "checked"
GotoLine "End"
Else
If "[software12]" "=" "checked"
Run "\\x.bat" "" "RunOnce+Wait" "" ""
GotoLine "End"


:End
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

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

Re: subroutine question

Postby Enigman » Sat Aug 22, 2015 6:51 pm

This is what I am trying to accomplish. (I wish I could post an image of my current pub)
Set up a series of checkboxes that when told to execute, 'if checked' will install a set of software and if not checked will
continue on to the next software. Because each software install is different.

I tried (the coding experts here) might advise to turn the individual software sections into a subroutine. I tried one or two sections, but haven't been successful.

Wow. Okay. Let's talk about software design.

A general coding rule is: Never use "Gotoline" if there is another way.

In your case with your app, you can grossly simplify your code by verifying if a checkbox is "checked" rather than verifying if it is NOT checked. For example:

Code: Select all
IfEx "[software1] = Checked"
     IfEx "[chipset] = AMD"
          ..... do this for AMD
     Else
          ..... do this for x86
     EndIf
Endif

IfEx "[software2] = Checked"
     IfEx "[chipset] = AMD"
          ..... do this for AMD
     Else
          ..... do this for x86
     EndIf
Endif

IfEx "[software3] = Checked"
     IfEx "[chipset] = AMD"
          ..... do this for AMD
     Else
          ..... do this for x86
     EndIf
Endif

..... and so on

Notice that there are no GotoLine commands and yet the program will only execute actions if one or more of the software checkboxes has been enabled. The program simply falls through until it has something to do. You can use subroutines to further organize the code if you wish. In that case it would look like this:

Code: Select all
IfEx "[software1] = Checked"
     IfEx "[chipset] = AMD"
          GoSub "Sw1_AMD"
     Else
          GoSub "Sw1_x86"
     EndIf
Endif

IfEx "[software2] = Checked"
     IfEx "[chipset] = AMD"
          GoSub "Sw2_AMD"
     Else
          GoSub "Sw2_x86"
     EndIf
Endif

IfEx "[software3] = Checked"
     IfEx "[chipset] = AMD"
          GoSub "Sw3_AMD"
     Else
          GoSub "Sw3_x86"
     EndIf
Endif

..... and so on

With the above simple design there is also no need to have each continuing software verification in the Else block of the previous IfEx block. If there is too much nesting of IfEx blocks you can quickly lose track of where you are, especially if there are Goto jumps all over the place.

I don't know if your code example is indicative of the real code, but it is also a good idea to physically indent the IfEx block contents to make it visually easier to follow.

I hope this helps.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: subroutine question

Postby stevec » Sat Aug 22, 2015 7:05 pm

Thanks for the reply. :D :D :D :D
I was playing around with the subroutine angle and was able to accomplish this;

Acrion script

Delay "500"
GoSub "software1"

GoSub "software2"

GoSub "software3"

Here is the subroutine list;

:software1
If "[software1]" "<>" "checked"
Return
Else
If "[software1]" "=" "checked"
Balloon "software1 installed" "250" "205" "2000"
Return

:software2
If "[software2]" "<>" "checked"
Return
Else
If "[software2]" "=" "checked"
StickyNote "-1" "-1" "it works" "6000"
Return

:software3
If "[software3]" "<>" "checked"
Return
Else
If "[software3]" "=" "checked"
PopUpImage "-1" "-1" "C:\Users\W7\Pictures\misc_tower-512.png" "3500" "None" "0"
Return

Again, its backwards with checking to see if the box is not checked first.

The reason I was/am trying the subroutines is that since the software installs can change (location and version) I was thinking it was and will be easier to edit the changes and updates when the install procedures are isolated withing a seperate routine.

Thanks, I'll work on the coding. the 'IfEx" I need to better understand
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: subroutine question

Postby stevec » Sat Aug 22, 2015 7:15 pm

WOW!

I got it.

action script

Delay "500"
GoSub "software1"

GoSub "software2"

GoSub "software3"

Here is the subroutine scripts;

:software1
IfEx "[software1]=Checked"
Balloon "software1 installed" "250" "205" "2000"
Return

:software2
IfEx "[software2]=checked"
StickyNote "-1" "-1" "it works" "6000"
Return

:software3
IfEx "[software3]=checked"
PopUpImage "-1" "-1" "C:\Users\W7\Pictures\misc_tower-512.png" "3500" "None" "0"
Return

you're right it is a lot cleaner

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

Re: subroutine question

Postby stevec » Sat Aug 22, 2015 7:46 pm

I cut the code from 160 lines down to 106.

I can't wait to try it out.

Thanks;
:mrgreen: :mrgreen: :mrgreen:
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