Servoy Case Function

Hi

Filemaker user here. How do I deploy a CASE function in Servoy?

In Filemaker I use the CASE function in a tagwork calculation field (indexed) or tagwork script:

Case(

timesheet::process="javaw.exe"; "Work";
timesheet::process="FileMaker Developer.exe"; "Work";
timesheet::process="FileMaker Pro Advanced.exe"; "Work";
timesheet::process="notepad.exe"; "Work";


timesheet::process="firefox.exe"; "Browse";
timesheet::process="iexplore.exe"; "Browse";
timesheet::process="explorer.exe"; "Browse";


timesheet::process="uTorrent.exe"; "Personal";
timesheet::process="msnmsgr.exe"; "Personal";
timesheet::process="Skype.exe"; "Personal";
timesheet::process="YahooMessenger.exe"; "Personal";

"Untagged")

I have two questions:

  1. How do I do this in a Servoy calculation field?
  2. How do I loop this in a Servoy script?

Thanks in advance.

Nikos

ps I searched the web and found an answer to use switch or var. The switch funtion didn’t work as all the results were default (“untagged”) while the var function was confusing.

Hi Nikos,

I see this is your first post so welcome to the forum!

For the CASE function you do indeed need to use the SWITCH function.
Als for always getting the default, this means you didn’t use a ‘break on case’ in your code.
The following URL explains it.
http://www.developertutorials.com/learn … t-2599.php

As for loops you can use a FOR loop or a WHILE loop.
A VAR has nothing much to do with loops other than declaring a local variable to use in that loop.

Hope this helps.

Hi Roclasi,

Thanks for the welcome, and link!

Got the calculation field to work with:

function tagwork()
{
	x = process;
	switch (x)
	{
	case "javaw.exe":
		return "Work";
	break;
	case "iexplore.exe":
		return "Work";
	break;
	default:
		return "Untagged";
	}
}

Now lets see if I can get the script to work. Thanks.

FYI, if you’ve got multiple cases that should execute the same code, you can group them as fallthrough cases, like this:

function tagwork() 
{ 
   x = process; 
   switch (x) 
   { 
   case "javaw.exe": 
   case "iexplore.exe": 
      return "Work"; 
   break; 
   default: 
      return "Untagged"; 
   } 
}

g.