Source language: Translate to:

Emulating a Case/Select Command

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Re: Emulating a Case/Select Command

Postby dpayer » Tue Jan 21, 2014 8:33 am

mishem wrote:And if 100 values​​? Also if?

Something like this.

Code: Select all
SetVar "[Venue]" "All Resonant Energies,Amazon,eBay - Resonant Energies,eBay - Enigma Treasures,Web - Resonant Energies,All Venues"
SetVar "[value]" "59,207,59|255,166,27|0,162,160|64,64,255|196,46,198|255,255,255"

StrParse "[Venue]" "," "[Venue]" ""
StrParse "[value]" "|" "[value]" ""

Loop "1" "6" "[i]"
    IfEx "[db.Inventory.Venue] = [#34][Venue[i]][#34]"
         SetObjectFill "invVenue" "[value[i]]" "Solid" "False"

DeleteArray "[Venue]" "All"
DeleteArray "[value]" "All"

I like this approach. I have found that 'compound variables (such as [value[I]] ) above are extremely powerful and compact.

David P.
David Payer
Des Moines, Iowa
User avatar
Posts: 1391
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Emulating a Case/Select Command

Postby Enigman » Tue Jan 21, 2014 9:12 am

Yeah, I've gotta say that it is highly adaptable to a reusable subroutine based on the SetObjectFill command. It would take just a bit of tweaking to add a global "else" action when the input field doesn't contain anything in the list. Maybe like this:

Code: Select all
.......... Script Action Code
    SetVar "[IfCase]" "All Resonant Energies|Amazon|eBay - Resonant Energies|eBay - Enigma Treasures|Web - Resonant Energies|All Venues"
    SetVar "[ThenDo]" "59,207,59|255,166,27|0,162,160|64,64,255|196,46,198|255,255,255"
    SetVar "[Else]" "255,255,255"
    GoSub "SelectVenueFill"

.......... Subroutine Code

    StrParse "[IfCase]" "|" "[case]" ""
    StrParse "[ThenDo]" "|" "[do]" ""
    SetVar "[foundflag]" "False"

    Loop "1" "6" "[i]"
        IfEx "[db.Inventory.Venue] = [#34][case[i]][#34]"
             SetObjectFill "invVenue" "[do[i]]" "Solid" "False"
             SetVar "[foundflag]" "True"
    IfEx "[foundflag] = False"
             SetObjectFill "invVenue" "[Else]" "Solid" "False"

    DeleteArray "[case]" "All"
    DeleteArray "[do]" "All"
    SetVar "[Else]" ""


If you wanted you could also add a check in the subroutine that both arrays are the same length. And you could also add parameters for the database and screen field names.
User avatar
Posts: 316
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests