Jump to content
Developer Wiki and Function Reference Links ×

Help using the Case function


Recommended Posts

Hey all,

Just had a query related to the Case function. It has worked well for me when I've needed to do something number related, eg:

Begin

Case NUM of

1: FIELD:='A';

2: FIELD:='B';

3: FIELD:='C';

End;

Where NUM is an integer and FIELD a string, I'm wondering if there is an equivalent where I can use a string as the case value.

Begin

Case FIELDA of

'AA': FIELDB:='A';

'BB': FIELDB:='B';

'SOMETHING: FIELDB:='OUTPUT';

End;

Where FIELDA and FIELDB are both strings. Does that make sense? There might be a function that I'm not finding in my help guide.

Cheers,

J

Link to comment

You can use single characters, but not strings, in a case statement.

CH :Char;

case CH of

???'a' : begin end;

???'b' : begin end;

???'c' :begin end;

???'d' :begin end;

???'e' :begin end;

???'f' :begin end;

???'g' :begin end;

???'h', 'i', 'j', 'k' :begin end;

???'l' .. 'p' :begin end;

???'q', 'r', 's' :begin end;

???'t', 'u', 'v' :begin end;

???'w' :begin end;

???'x', 'y', 'z' :begin end;

end;???{ case }

As a rule, case statements only work with enumerated types, that is, variables that have an integer value.

HTH,

Raymond

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...