Newbie delphi problem - won't compile

bovril
bovril used Ask the Experts™
on
I get the error message

"mainrandom.pas(94): Declaration expected but 'FOR' found"

when I try and compile the code below.

Any ideas ?

begin

  // make sure we clear any existing numbers
  // from the board
  frmlottopicker.lblLottoNum.Caption := '';

  // Initialise the random seed generator
  randomize;

  // create a loop counter
  intElementNum := 1;

  // We need to generate 6 balls
  for intnumballs := 1 to 6 do
  begin                       //*

    if (intnumballs > 1) then
    begin                     //**
      // for each ball generated, we will check that
      // it does not match one generated before it.
      // This will ensure its uniqueness
      for intloop1 := 1 to intnumballs do
      begin                   //***
        repeat

          // generate a valid integer between 1 and 49
          // The random number will never generate
          // the highest number so in order to get between
          // 1 and 49 we use ...
          intlottoball := (random(49) + 1);

          // keep generating numbers until we get one
          //that hasnt been picked before
        until (intlottoball <> aryballs[intloop1]);
      end // for loop        //***
    end
    else                      //**
            // generate a valid integer between 1 and 49
            // The random number will never generate
            // the highest number so in order to get between
            // 1 and 49 we use ...
            intlottoball := (random(49) + 1);
    end; // if                //**

    // once we are sure that it is unique, we will push
    // it onto the array
    aryballs[intElementNum] := intlottoball;
  end; // for                 //*

  // START OF THE SORTING SEQUENCE
   // we should probably sort them
    for intnumballs := 1 to 6 do
      begin
      for intelementnum := 1 to 6 do
        begin
          if ((aryballs[intnumballs]) < (aryballs[intelementnum]))
          then
            begin
              // copy the second value into a temporary variable
              inttemp := aryballs[intnumballs];

              // swap the numbers around until they are in sequence
              aryballs[intnumballs] := aryballs[intelementnum];
              aryballs[intelementnum] := inttemp;
            end;
        end; // intelemntnum
      end; // intnumballs


    // clear the box
    frmlottopicker.lblLottoNum.Caption := '';

    // lets print them out on-screen now
    for intnumballs := 1 to 6 do
      begin
       frmlottopicker.lblLottoNum.Caption := frmlottopicker.lblLottoNum.Caption + ' ' + inttostr(aryballs[intnumballs]);
      end;

end;
end.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The error is an extra end before your for ... I reindented your code, and removed the comments, look what I got

// Begin
begin
  randomize;
  intElementNum := 1;
  for intnumballs := 1 to 6 do
  begin
    if (intnumballs > 1) then
    begin
      for intloop1 := 1 to intnumballs do
      begin
        repeat
          intlottoball := (random(49) + 1);
        until (intlottoball <> aryballs[intloop1]);
      end
    end
    else
  end;
  aryballs[intElementNum] := intlottoball;
  end; // <------------------------------------- This end closes the 1st begin .... This is the error
  for intnumballs := 1 to 6 do
  begin
    for intelementnum := 1 to 6 do
    begin
      if ((aryballs[intnumballs]) < (aryballs[intelementnum]))
      then
      begin
        inttemp := aryballs[intnumballs];
        aryballs[intnumballs] := aryballs[intelementnum];
        aryballs[intelementnum] := inttemp;
      end;
    end;
  end;
  frmlottopicker.lblLottoNum.Caption := '';
  for intnumballs := 1 to 6 do
  begin
    frmlottopicker.lblLottoNum.Caption := frmlottopicker.lblLottoNum.Caption + ' ' + inttostr(aryballs[intnumballs]);
  end;
  end;
end.
Notice the importance of a well commented and well indented code .... You couldn't notice the error because the code was barely indented and there was so many comments that the code became unreadable : )

Author

Commented:
I guess I was a little too enthusiastic with the commenting.

Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial