Validation- Yes/No - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Validation- Yes/No

[code]procedure TForm4.ComboBox1Exit(Sender: TObject);
var ok:boolean;
begin

ok:=false;
if upcase(combobox1.text) = 'YES' then ok:=true;

if upcase(combobox1.text) = 'NO' then ok:=true;

if ok=false then combobox1.Color:= clLime
{if any of the above in incorrect then make the colour lime green to show error}
else if length(combobox1.Text)=0 then combobox1.Color:=clred
{if there is nothing there, the box goes red}
else combobox1.color:=clWhite;
{otherwise it remains white}
end;

end.[/code]

it will accept YES and NO but not yes or no. And upcase doesn't work, it says:

"[Error] Unit4.pas(495): Incompatible types: 'Char' and 'TCaption'"

HELP!!

Comments

  • zibadianzibadian Posts: 6,349Member
    : [code]procedure TForm4.ComboBox1Exit(Sender: TObject);
    : var ok:boolean;
    : begin
    :
    : ok:=false;
    : if upcase(combobox1.text) = 'YES' then ok:=true;
    :
    : if upcase(combobox1.text) = 'NO' then ok:=true;
    :
    : if ok=false then combobox1.Color:= clLime
    : {if any of the above in incorrect then make the colour lime green to show error}
    : else if length(combobox1.Text)=0 then combobox1.Color:=clred
    : {if there is nothing there, the box goes red}
    : else combobox1.color:=clWhite;
    : {otherwise it remains white}
    : end;
    :
    : end.[/code]
    :
    : it will accept YES and NO but not yes or no. And upcase doesn't work, it says:
    :
    : "[Error] Unit4.pas(495): Incompatible types: 'Char' and 'TCaption'"
    :
    : HELP!!
    :
    If you want to upcase a string use the UpperCase() function.
Sign In or Register to comment.