Elseif

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
wbshrk
Posts: 2
Joined: 2013-12-14 00:15:35

Elseif

Post by wbshrk »

How does Else if work in the scripts?
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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
wbshrk
Posts: 2
Joined: 2013-12-14 00:15:35

Post 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;
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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)
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

Really interesting.
Use of if... then... else... was a little confusing but now... it's all clear!
Tnx.
:grinking:
Post Reply