#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0

    Question Delphi newbie here , please help


    Code:
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.BitBtn2Click(Sender: TObject);
    var
     sName , sYearOfBirth , sCurrentYear : string;
     iCurrent , iBirth , iAge, iKids, iJuniors, iBigKids, iTeens, iSeniors, iCurrentAge : integer;
    
    begin
    sName := Edit1.Text ;
    sYearOfBirth := Edit2.Text;
    sCurrentYear := Edit3.Text ;
    iBirth := StrToInt(sYearOfBirth);
    iCurrent := StrToInt(sCurrentYear) ;
    iCurrentAge := (iCurrent - iBirth);
    RichEdit1.Lines.Add( ' Name of entrant is:' + sName) ;
    RichEdit1.Lines.Add( ' Your age this year is ' + IntToStr(iCurrentAge) ) ;
    
    case iAge of
     3..5 : Inc(iKids);
     6..8 : Inc(iJuniors);
     9..10 : Inc(iBigKids);
     13..16 : Inc(iTeens);
     17..18 : Inc(iSeniors);
    
    if iAge = iCurrentAge
     then RichEdit1.Lines.Add(' You are eligble to enter this section ')
    
    end;
    end;
    end.
    So my problem is that it keeps on giving me 'constant expression exprected' error at the first 'end;' and I have no idea why , any help please

    My project is as follows I'm trying to create an application of that when the user clicks the Process button the program must calculate and display the age of the entrant . This must be checked to see if they are eligible to enter the selected age group category. The program must indicate whether the entrant is allowed to participate according to his/her age.

    Using the if , and case statement also Richedit , this is a school task . Any help would be appreciated
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    397
    Rep Power
    0
    even though the CASE statement has no "begin", it does still require an "end"

    Code:
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.BitBtn2Click(Sender: TObject);
    var
     sName , sYearOfBirth , sCurrentYear : string;
     iCurrent , iBirth , iAge, iKids, iJuniors, iBigKids, iTeens, iSeniors, iCurrentAge : integer;
    
    begin
      sName := Edit1.Text ;
      sYearOfBirth := Edit2.Text;
      sCurrentYear := Edit3.Text ;
      iBirth := StrToInt(sYearOfBirth);
      iCurrent := StrToInt(sCurrentYear) ;
      iCurrentAge := (iCurrent - iBirth);
      RichEdit1.Lines.Add( ' Name of entrant is:' + sName) ;
      RichEdit1.Lines.Add( ' Your age this year is ' + IntToStr(iCurrentAge) ) ;
    
      case iAge of
        3..5 : Inc(iKids);
        6..8 : Inc(iJuniors);
        9..10 : Inc(iBigKids);
        13..16 : Inc(iTeens);
        17..18 : Inc(iSeniors);
      end;  //moved end to here.
    
      if iAge = iCurrentAge then
        RichEdit1.Lines.Add(' You are eligible to enter this section ');
    
    end;
    
    end.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0
    Ah now I see , thank you so much !

IMN logo majestic logo threadwatch logo seochat tools logo