Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-01

errors: Upper bound of case range is less than lower bound and duplicate case label

20 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Eric Kom

Good afternoon all,

Please after write the above procedure, I received the errors: Upper bound of case range is less than lower bound and duplicate case label

procedure DisplayGrade(Sender: TObject);
var
   grade    : String;
   tuitionFee: String;
   gradeSelected: String;
begin
    gradeSelected := cbbGradeList.Items[cbbGradeList.ItemIndex];
    case gradeSelected of
         '12'..'12': tuitionFee := '14500.00';
         '8'..'11' : tuitionFee := '13500.00';
         '1'..'7'  : tuitionFee := '8000.00';
    else
         tuitionFee := '850.00';
    end;
end;
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Sven Barth
to Eric Kom
Eric Kom wrote 14 lines
Good afternoon all, Please after write the above procedure, I received the errors: Upper bound of case range is less than lower bound and duplicate case label procedure DisplayGrade(Sender: TObject); var grade : String; tuitionFee: String; gradeSelected: String; begin gradeSelected := cbbGradeList.Items[cbbGradeList.ItemIndex]; case gradeSelected of '12'..'12': tuitionFee := '14500.00';

^ ^ This should be easy to spot...

Show quoted text 8 lines
'8'..'11' : tuitionFee := '13500.00'; '1'..'7' : tuitionFee := '8000.00'; else tuitionFee := '850.00'; end; end;

Regards,
Sven

Reply by email

Mattias Gaertner
to Sven Barth
Show quoted text 17 lines
On 20.01.2013 18:40, Eric Kom wrote: > Good afternoon all, > > Please after write the above procedure, I received the errors: Upper > bound of case range is less than lower bound and duplicate case label > > procedure DisplayGrade(Sender: TObject); > var > grade : String; > tuitionFee: String; > gradeSelected: String; > begin > gradeSelected := cbbGradeList.Items[cbbGradeList.ItemIndex]; > case gradeSelected of > '12'..'12': tuitionFee := '14500.00'; ^ ^ This should be easy to spot...

Maybe changing the message to "lower or equal" would help?

Mattias

Reply by email

Alexander Klenin
to Sven Barth: ^ ^ This should be easy to spot... Sven
Sven Barth wrote 5 lines
> case gradeSelected of > '12'..'12': tuitionFee := '14500.00'; ^ ^ This should be easy to spot...

No, the error is in the line below.

> '8'..'11' : tuitionFee := '13500.00';

Note that strings are not numbers, so '8' > '11'.
Also, '1' < '11' < '7' < '8', so case branch labels intersect, which is the reason for the second error.

Mattias Gaertner wrote
Maybe changing the message to "lower or equal" would help?

No, equal values are acceptable, although useless.

Eric: "case of string" is not suitable for your task, use the usual "case of integer" instead.

Reply by email

Eric Kom
to Mattias Gaertner: On Sun, 20 Jan 2013 18:43:44 +0100 Maybe changing the message to "lower or equal" would…
Mattias Gaertner wrote 20 lines
On Sun, 20 Jan 2013 18:43:44 +0100 Sven Barth wrote: > On 20.01.2013 18:40, Eric Kom wrote: >> Good afternoon all, >> >> Please after write the above procedure, I received the errors: Upper >> bound of case range is less than lower bound and duplicate case label >> >> procedure DisplayGrade(Sender: TObject); >> var >> grade : String; >> tuitionFee: String; >> gradeSelected: String; >> begin >> gradeSelected := cbbGradeList.Items[cbbGradeList.ItemIndex]; >> case gradeSelected of >> '12'..'12': tuitionFee := '14500.00'; > ^ ^ This should be easy to spot... Maybe changing the message to "lower or equal" would help?

I don't understand this error of lower bound and duplicate case label

Show quoted text 9 lines
Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Sven Barth
to Alexander Klenin: No, the error is in the line below. Note that strings are not numbers, so '8' > '11'.…
Alexander Klenin wrote 12 lines
On Mon, Jan 21, 2013 at 4:43 AM, Sven Barth wrote: >> case gradeSelected of >> '12'..'12': tuitionFee := '14500.00'; > > ^ ^ This should be easy to spot... No, the error is in the line below. >> '8'..'11' : tuitionFee := '13500.00'; Note that strings are not numbers, so '8' > '11'. Also, '1' < '11' < '7' < '8', so case branch labels intersect, which is the reason for the second error.

Right... I forgot that this is a case of string -.-

Regards,
Sven

Reply by email

Flávio Etrusco
to Sven Barth
Sven Barth wrote 23 lines
Am 21.01.2013 04:54, schrieb Alexander Klenin: > On Mon, Jan 21, 2013 at 4:43 AM, Sven Barth > wrote: >>> >>> case gradeSelected of >>> '12'..'12': tuitionFee := '14500.00'; >> >> >> ^ ^ This should be easy to spot... > > No, the error is in the line below. > >>> '8'..'11' : tuitionFee := '13500.00'; > > Note that strings are not numbers, so '8' > '11'. > Also, '1' < '11' < '7' < '8', so case branch labels intersect, which > is the reason for the second error. > Right... I forgot that this is a case of string -.- Regards, Sven

Should case of string really allow ranges?

Reply by email

Sven Barth
to Flávio Etrusco
Fl?vio Etrusco wrote 26 lines
On Mon, Jan 21, 2013 at 7:00 AM, Sven Barth wrote: > Am 21.01.2013 04:54, schrieb Alexander Klenin: > >> On Mon, Jan 21, 2013 at 4:43 AM, Sven Barth >> wrote: >>>> >>>> case gradeSelected of >>>> '12'..'12': tuitionFee := '14500.00'; >>> >>> >>> ^ ^ This should be easy to spot... >> >> No, the error is in the line below. >> >>>> '8'..'11' : tuitionFee := '13500.00'; >> >> Note that strings are not numbers, so '8' > '11'. >> Also, '1' < '11' < '7' < '8', so case branch labels intersect, which >> is the reason for the second error. >> > Right... I forgot that this is a case of string -.- > > Regards, > Sven Should case of string really allow ranges?

THAT is an interesting question.

Regards,
Sven

Reply by email

Bart
to Sven Barth
Sven Barth wrote
> Should case of string really allow ranges? THAT is an interesting question.

I think it should not.
Ranges for strings are (countably) infinite, and this is (by design) not the case in the case of other cases (pun intended).

Bart

Reply by email

Mattias Gaertner
to Bart
Show quoted text 7 lines
On 1/21/13, Sven Barth wrote: >> Should case of string really allow ranges? > > THAT is an interesting question. I think it should not.

The lower-than and greater-than operators are defined for strings. Do you want to remove them too?

Ranges for strings are (countably) infinite, and this is (by design) not the case in the case of other cases (pun intended).

Mattias

Reply by email

Mark Morgan Lloyd
to Bart: I think it should not. Ranges for strings are (countably) infinite, and this is (by…
Bart wrote 8 lines
On 1/21/13, Sven Barth wrote: >> Should case of string really allow ranges? > THAT is an interesting question. I think it should not. Ranges for strings are (countably) infinite, and this is (by design) not the case in the case of other cases (pun intended).

I can see that somebody thought is was a good idea, by analogy with (if not direct equivalence to) cardinals. But shouldn't embedded strings be subject to internationalisation? And what happens when

'Apples'..'Oranges': begin
                      end;

gets translated to French? :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Flávio Etrusco
to Mattias Gaertner: On Mon, 21 Jan 2013 22:19:58 +0100 The lower-than and greater-than operators are defined…
Mattias Gaertner wrote 14 lines
On Mon, 21 Jan 2013 22:19:58 +0100 Bart wrote: > On 1/21/13, Sven Barth wrote: > > >> Should case of string really allow ranges? > > > > THAT is an interesting question. > > I think it should not. The lower-than and greater-than operators are defined for strings. Do you want to remove them too?

I've actually wondered about it a few times ;-)
You have a point - and I don't feel strongly about either way -, but in perspective AFAIR I've never needed - nor have seem a piece of code which did - more than one greater or less than comparison on strings in the same condition, so I'd say it's an unusual notion/construction.

-Fl?vio

Reply by email

Avishai
to Flávio Etrusco

Sorry, I'm late coming into this conversation and I may not be understanding the question/answer. But if I am, then case sensitivity should be part of any sort/comparison, at least as an option. I have had many problems when it is not. aA-Bb-Cc-dD is a form of randomness. If the result of a sort can not be reliably reproduced after adding new data, the sort fails. Case sensitive sort is common. Take a look at almost any spreadsheet program and you will see that it is an option. It's also an option in TStringList. In my opinion Case Sensitive should be the default behavior of any Sort/Comparison.

Fl?vio Etrusco wrote 31 lines
On Mon, Jan 21, 2013 at 7:36 PM, Mattias Gaertner wrote: > On Mon, 21 Jan 2013 22:19:58 +0100 > Bart wrote: > >> On 1/21/13, Sven Barth wrote: >> >> >> Should case of string really allow ranges? >> > >> > THAT is an interesting question. >> >> I think it should not. > > The lower-than and greater-than operators are defined for > strings. Do you want to remove them too? > I've actually wondered about it a few times ;-) You have a point - and I don't feel strongly about either way -, but in perspective AFAIR I've never needed - nor have seem a piece of code which did - more than one greater or less than comparison on strings in the same condition, so I'd say it's an unusual notion/construction. -Fl?vio -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130122/a778e63a/attachment.html>

Reply by email

Hans-Peter Diettrich
to Avishai
Show quoted text 9 lines
Sorry, I'm late coming into this conversation and I may not be understanding the question/answer. But if I am, then case sensitivity should be part of any sort/comparison, at least as an option. I have had many problems when it is not. aA-Bb-Cc-dD is a form of randomness. If the result of a sort can not be reliably reproduced after adding new data, the sort fails. Case sensitive sort is common. Take a look at almost any spreadsheet program and you will see that it is an option. It's also an option in TStringList. In my opinion Case Sensitive should be the default behavior of any Sort/Comparison.

A case statement IMO should not rely on sort/compare options, unless there exists a syntax extension for such specifications. It also should be insensitive to string encodings (codepages).

If you want to be sure of the results, you replace the case statement by a chain of explicit comparisons, using the desired string comparison functions.

DoDi

Reply by email

Bart
to Mattias Gaertner: On Mon, 21 Jan 2013 22:19:58 +0100 The lower-than and greater-than operators are defined…
Mattias Gaertner wrote 6 lines
The lower-than and greater-than operators are defined for strings. Do you want to remove them too? > Ranges for strings are (countably) infinite, and this is (by design) > not the case in the case of other cases (pun intended).

No, you are missing the analogy I meant (or I did not make myself clear enough).

Case was originally meant for Ordinal values.
With Ordinal values ranges (1..100, 'a'..'z') are never infinite. Pascal has never had the concept of ranges (in this sense) that are infinite (countable or uncoutable).
You cannot define ranges for Floats (they would be uncoutable infinite), and by that analogy I would suggest you should not be able to define ranges for strings, as they are (coutbale) infinite.

The ability to have an infinite (countable or uncoutable) "range" between two values for a given type however, does not mean you should not have lesser than, or greater than operators. If this were the case we'ld have to remove them for floats as well, and that would be rather silly.

So my analogy was more with floats (but they have uncoutable infinite ranges, as opposed to coutable infinity for strings).

Bart

Reply by email

Mattias Gaertner
to Bart
Show quoted text 28 lines
On 1/21/13, Mattias Gaertner wrote: > The lower-than and greater-than operators are defined for > strings. Do you want to remove them too? > > >> Ranges for strings are (countably) infinite, and this is (by design) >> not the case in the case of other cases (pun intended). No, you are missing the analogy I meant (or I did not make myself clear enough). Case was originally meant for Ordinal values. With Ordinal values ranges (1..100, 'a'..'z') are never infinite. Pascal has never had the concept of ranges (in this sense) that are infinite (countable or uncoutable). You cannot define ranges for Floats (they would be uncoutable infinite), and by that analogy I would suggest you should not be able to define ranges for strings, as they are (coutbale) infinite. The ability to have an infinite (countable or uncoutable) "range" between two values for a given type however, does not mean you should not have lesser than, or greater than operators. If this were the case we'ld have to remove them for floats as well, and that would be rather silly. So my analogy was more with floats (but they have uncoutable infinite ranges, as opposed to coutable infinity for strings).

To implement a case LowerBound..UpperBound you only need a transitive compare operator. You don't need fixed size ranges. If you have small fixed size range then you can implement the case via jump tables. But that is only an implementation detail.

IMHO if you think that the string compare operator makes sense, then
strings in case makes sense too. They make exactly the same sense.

Mattias

Reply by email

Eric Kom
to Sven Barth: THAT is an interesting question. Sven
Sven Barth wrote 23 lines
On 21.01.2013 15:37, Fl?vio Etrusco wrote: > On Mon, Jan 21, 2013 at 7:00 AM, Sven Barth > wrote: >> Am 21.01.2013 04:54, schrieb Alexander Klenin: >> >>> On Mon, Jan 21, 2013 at 4:43 AM, Sven Barth >>> >>> wrote: >>>>> >>>>> case gradeSelected of >>>>> '12'..'12': tuitionFee := '14500.00'; >>>> >>>> >>>> ^ ^ This should be easy to spot... >>> >>> No, the error is in the line below. >>> >>>>> '8'..'11' : tuitionFee := '13500.00'; >>> >>> Note that strings are not numbers, so '8' > '11'. >>> Also, '1' < '11' < '7' < '8', so case branch labels intersect, which >>> is the reason for the second error. >>>

it works! after I have removed the single quote and converted gradeSelected from string to integer.

Thanks for your contributions.

Show quoted text 19 lines
>> Right... I forgot that this is a case of string -.- >> >> Regards, >> Sven > > Should case of string really allow ranges? THAT is an interesting question. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Alexander Klenin
to Bart: No, you are missing the analogy I meant (or I did not make myself clear enough). Case was…
Bart wrote
You cannot define ranges for Floats (they would be uncoutable infinite)

Huh? Actually, you can. Real number interval is a well-known mathematical concept (see
http://en.wikipedia.org/wiki/Interval_%28mathematics%29), so I would actually suggest that they should be added to "case" operator too. Also note that, contrarty to "true" real numbers, floats are a finite set.

Alexander S. Klenin

Reply by email

Bart
to Alexander Klenin
Alexander Klenin wrote 5 lines
On Tue, Jan 22, 2013 at 7:20 PM, Bart wrote: > You cannot define ranges for Floats (they would be uncoutable infinite) Huh? Actually, you can. Real number interval is a well-known mathematical concept (see

I did hope the context made it clear I meant range as in Ordinal.

Also note that, contrarty to "true" real numbers, floats are a finite set.

Of course.
Also, Strings (as defined in Pascal currently) are also not infinite, due to length limitation.

So, my argument was meant as some sort of philosophical perspective. I really don't care wether fpc implements it or not.

In the manner used by OP I would never use it, since it makes the code more diffcult to understand (just because of the ranges and the way < and > act on strings).
IMO Case should be used to make code more understandable.

Bart

Reply by email