Source language: Translate to:

Reading variable

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Reading variable

Postby stevec » Mon Feb 12, 2007 11:14 am

Just a quick question;

The code below stops the action script. If I use the "Else" command, it still hanges. Any ideas to look at the variable [TotalFragmentation] and if then move on.

If "[TotalFragmentation]" "<" "10"
SetVar "[A5]" "Defrag Recommended"
If "[TotalFragmentation]" ">" "10"
SetVar "[A5]" "Defrag Soon"
If "[TotalFragmentation]" ">" "15"
SetVar "[A5]" "Defrag Required"
If "[TotalFragmentation]" ">" "20"
SetVar "[A5]" "Defrag Critical"
If "[TotalFragmentation]" ">" "25"
SetVar "[A5]" "Defrag Mandatory"

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

Got it.

Postby stevec » Mon Feb 12, 2007 11:23 am

I created a subroutine;

:Defrag
If "[TotalFragmentation]" ">" "25"
SetVar "[A5]" "Defrag Mandatory"
Else
If "[TotalFragmentation]" ">" "20"
SetVar "[A5]" "Defrag Critical"
Else
If "[TotalFragmentation]" ">" "15"
SetVar "[A5]" "Defrag Required"
Else
If "[TotalFragmentation]" ">" "10"
SetVar "[A5]" "Defrag Soon"
Else
If "[TotalFragmentation]" "<" "10"
SetVar "[A5]" "Defrag Recommended"

And it appears to work.

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

Postby Sam Cox » Mon Feb 12, 2007 11:29 am

Hello Steve,

Before you posted your own solution, I wrote the following. But, there is a problem in your subroutine. Each and every "If" statement in your tree of "If/Else" statemets needs an "Endif" statement. See my first solution (below) for how it might look.

Two solutions.

The first will get you going immediately.
Code: Select all
If "[TotalFragmentation]" ">" "25"
  SetVar "[A5]" "Defrag Mandatory"
Else
If "[TotalFragmentation]" ">" "20"
  SetVar "[A5]" "Defrag Critical"
Else
If "[TotalFragmentation]" ">" "15"
  SetVar "[A5]" "Defrag Required"
Else
If "[TotalFragmentation]" ">" "10"
  SetVar "[A5]" "Defrag Soon"
Else
  SetVar "[A5]" "Defrag Recommended"
Endif
Endif
Endif
Endif

The second is more elegant, in my opinion, but requires that an external function—the 'case' function—be available. If you are interested in pursuing the case function approach, I can provide the function and details of its use:
Code: Select all
Call "Case" "[TotalFragmentation]" "0-9,10-14,15-19,20-24,25-99" "[Result]"
GotoLine "case[result]"
:case1
  SetVar "[A5]" "Defrag Recommended"
  Return
:case2
  SetVar "[A5]" "Defrag Soon"
  Return
:case3
  SetVar "[A5]" "Defrag Required"
  Return
:case4
  SetVar "[A5]" "Defrag Critical"
  Return
:case5
  SetVar "[A5]" "Defrag Mandatory"
  Return
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Thanks

Postby stevec » Mon Feb 12, 2007 11:58 am

Sam;
Thanks, I really appreciate the input and it makes me look at things abit differently.
I'll play with your examples and see what happens.
Many thanks again;

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

Case function

Postby stevec » Mon Feb 12, 2007 12:02 pm

Yes, Sam, please

"I can provide the function and details of its use"

Call "Case" "[TotalFragmentation]" "0-9,10-14,15-19,20-24,25-99" "[Result]"
GotoLine "case[result]"
:case1
SetVar "[A5]" "Defrag Recommended"
Return
:case2
SetVar "[A5]" "Defrag Soon"
Return
:case3
SetVar "[A5]" "Defrag Required"
Return
:case4
SetVar "[A5]" "Defrag Critical"
Return
:case5
SetVar "[A5]" "Defrag Mandatory"
Return


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

Postby Sam Cox » Mon Feb 12, 2007 12:18 pm

Hi Steve,

This article

http://www.software-zone.com/neosoft/in ... 53cb6ed5c2

in the NeoBook Archives talks about the "case" function. If the explanation provided there is not enough for you, let me know and I can provide at least one sample pub.

Here is the function itself:
Code: Select all
{NeoBook Function}
Version=5.02
Param=[%value]|Text|the value to be 'cased'
Param=[%cases]|Text|the cases
Param=[%result]|Variable|the return variable
{End}

.example illustrating parameter possibilities
.call "case" "[value]" "v1,v2a-v2b,v3a|v3b|v3c" "[result]"
.[%result] = 0 if [%value] = blank
.[%result] = 0 if [%cases] = blank
.[%result] = 1 if [%value] = v1
.[%result] = 2 if [%value] in range v2a-v2b
.[%result] = 3 if [%value] = v3a or v3b or val3c
.[%result] = 0 otherwise

setvar "[%result]" "0"
if "[%value]" "<>" ""
   strparse "[%cases]" "," "[:case]" "[:casecount]"
   if "[:casecount]" ">" "0"
       loop "1" "[:casecount]" "[:n]"

           searchstr "-" "[:case[:n]]" "[:pos]"
           if "[:pos]" ">" "0"
               strparse "[:case[:n]]" "-" "[:val]" "[:valcount]"
               ifex "([:val1] <= [%value]) and ([%value] <= [:val2])"
                   setvar "[%result]" "[:n]"
                   exitloop
               endif
               gotoline "case.nextloop"
            endif

            searchstr "|" "[:case[:n]]" "[:pos]"
            if "[:pos]" ">" "0"
                searchstr "|[%value]|" "|[:case[:n]]|" "[:pos]"
                if "[:pos]" ">" "0"
                    setvar "[%result]" "[:n]"
                    exitloop
                endif
                gotoline "case.nextloop"
            endif

            if "[%value]" "=" "[:case[:n]]"
                setvar "[%result]" "[:n]"
                exitloop
            endif

        :case.nextloop
        endloop
    endif
endif

For this to work, the function code must be copied to a text file named "case" (no extension) in the NeoBook 5\Functions directory. After creating the file, you can open it and edit in NeoBook itself. To do so, use the Options > Function Library menu (or press F11) and double-click "case" in the list of functions to invoke NeoBook's function editor. To use this function in Neobook, read the article mentioned above and use NeoBook's "call" statement wizard to 1) select the case function, and 2) fill in the parameter fields.

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

sample pub

Postby stevec » Mon Feb 12, 2007 2:56 pm

Yes a sample pub would help.
Thanks;
Steve Christensen
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Postby Sam Cox » Mon Feb 12, 2007 3:45 pm

I have a simple "case" function example for you along with the function itself. Send me a PM (private message) with an email address to which I can send it, or click my email button and send me a message that way.

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


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests