Page 1 of 1

Elseif

Posted: 2013-12-14 00:16:24
by wbshrk
How does Else if work in the scripts?

Posted: 2013-12-14 10:37:33
by antp
:??:
what do you mean?

You can write:

Code: Select all

if something then
begin
  some code
end
else if somethingelse then
begin
  some code
end;
and begin/end is optional if there is only one code instruction in the block

Posted: 2013-12-16 11:59:28
by wbshrk
I have tried that at the script error out at the first else if. See code below. if I just use plan if it works fine.

Code: Select all

  if Value <> '' then
  begin
      if RegExprSetExec('drama',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Drama');
      else if RegExprSetExec('comedy',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Comedy') ;
      else if RegExprSetExec('romance',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Romance') ;
      else if RegExprSetExec('animation',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Animation');
      else if RegExprSetExec('action.*adventure',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Action/Adventure') ;
      else if RegExprSetExec('anime',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Anime') ;
      else if RegExprSetExec('fantasy',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Fantasy');
      else if RegExprSetExec('science.*fiction',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Sci-Fi');
      else if RegExprSetExec('comic.*book',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Comic book');
      else if RegExprSetExec('family',AnsiLowerCase(Value)) = True then
      SetField(fieldCategory, 'Family');
   end;

Posted: 2013-12-16 14:45:41
by soulsnake
Hi,

Do not put ; before else :

Code: Select all

  if Value <> '' then
  begin
      if RegExprSetExec('drama',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Drama')
      else if RegExprSetExec('comedy',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Comedy')
      else if RegExprSetExec('romance',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Romance')
      else if RegExprSetExec('animation',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Animation')
      else if RegExprSetExec('action.*adventure',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Action/Adventure')
      else if RegExprSetExec('anime',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Anime')
      else if RegExprSetExec('fantasy',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Fantasy')
      else if RegExprSetExec('science.*fiction',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Sci-Fi')
      else if RegExprSetExec('comic.*book',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Comic book')
      else if RegExprSetExec('family',AnsiLowerCase(Value)) = True then
          SetField(fieldCategory, 'Family');
   end;
Soulsnake.

Posted: 2013-12-16 19:29:38
by antp
It is indeed one of the few particularity of the Pascal/Delphi, no ";" in front of else (and optional in front of "end" if I remember well)

Posted: 2013-12-20 17:50:27
by fulvio53s03
Really interesting.
Use of if... then... else... was a little confusing but now... it's all clear!
Tnx.
:grinking: