# Procedural Difficulties

I've (with the help of having 3 Delphi Questions answered excellently) managed to nearly finish my college project but I'm having some procedural difficulties with my program.

Where do I start? OK

1    How do I ensure that the value entered in Edit2.text is no greater than the value entered in Edit1.text?

2    When adding the value from Edit4.text to Edit3.text how do I ensure that the total will not exceed Edit1.text?

3    When subtracting the value of Edit5.text from Edit3.text how do I ensure that the value of Edit3.text will not be a negative amount? i.e. Edit5 can only be less than or equal to Edit3.text

4    If I want Edit2.text to be a maximum of a given percentage of Edit1.text by entering the percentage value in edit6.text how do I do this?

Many thanks

Nick
LVL 4
###### Who is Participating?

Commented:
uh-oh.

tedit.text is a string.
if you compare strings '3' _is_ greater than '20', because the comparison starts at the first character of both strings. and '3' is greater than '2'.
the length doesn't matter in this case.

what you really want to do is to compare the _values_ of edit1.text and edit2.text.

so you have to convert the string property text of tedit to an integer.

if StrToInt(Edit2.Text) > StrToInt(Edit1.Text) then
MessageDlg('blablabla', mtError, [mbOk], 0)
else
Edit3.Text := Edit1.Text;

ok?

BlackDeath.
0

Commented:
you

you can do all of this action using this function

function  StrToCurr( const  S:  string ):  Currency ;

Description

Call StrToCurr to convert a string that represents a floating-point value to the corresponding Currency value. The source string,  S, must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional 'E' or 'e' followed by  a signed integer. Leading and trailing blanks are ignored.

The DecimalSeparator global variable defines the character that is used as a decimal point. Thousand separators and currency  symbols are not allowed in the string. If the string doesn't contain a valid value, StrToCurr raises an EConvertError exception.

0

Author Commented:
f15iaf, Sorry but I don't understand.

What I was looking for was something like i.e.

1 If edit2.text > edit1.text Message box "value cannot be greater than *" else etc

2 If edit4.text > edit1.text - edit3.text then Messagebox "Maximum value permitted is (Edit1.text - edit3.text)" else etc

3 If edit5.text > edit3.text then Message Box "Maximum Value permitted is (edit3.text)" else etc

4 How do I express a percentage other than edit6.text / 100

Many thanks

Nick
0

Author Commented:
All values are numbers (integers?) not currency

Thanks

Nick
0

Commented:
1.strtocurr(edit2.text)>strtocurr(edit1.text)

2.strtocurr(edit4.text)>strtocurr(edit1.text-edit3.text)

3.strtocurr(edit5.text)>strtocurr(edit3.text)

if you numbers are integers use strtoint
function.

if you numbers have a floating point use strtocurr function.
0

Commented:
hi nickrackham,

guessing that your question is pointed to 'where do i check this'
and not 'how do i check this', one advice

use the OnExit-event of all your dbedits pointed to one event-procedure,
there make your checks. if one fails, then do a message and set the focus back (sender)

meikl

0

Commented:
hi nick -
if your numbers are integer you'll have a little problem by calculating a percentage value using

iPercentage: Integer;
....
iPercentage := StrToInt(Edit6.Text)/100

StrToInt(Edit6.Text) div 100

and if your number is a floating point value, you'll use

fPercentage: Float;
....
fPercentage := StrToFloat(Edit6.Text)/100

of course.

regards,

BlackDeath.
0

Commented:
uh gawd. hit me!

there's no Float type of course.
use

single,
double,
extended or what fits your needs best.

for floating point types, see
"floating-point (real) types"
in delphi help.

sorry,

BlackDeath.
0

Author Commented:
f15iaf, Let' start from the beginning - I'm just starting to learn Delphi. My question 1 I have resolved. Q2 and Q3 are similar in that what I need is an answer to correct this syntax

begin
if StrToCurr(AddOil.Text) > (( StrToInt(DECap.Text) - StrToInt(DECurrOil.Text))   then;
Begin
MessageDlg('OverFlow Warning! Please reduce to ( StrToInt(DECap.Text) - StrToInt(DECurrOil.Text) ) Tonnes',mtConfirmation, [mbOK], 0);
end;

Q4 BlackDeath has given me what I need to get the percentage. BlackDeath, I'll post a seperate question fro you in this topic area unless you can resolve the above aswell in which case you got the points.

Many thanks to all

Nick

PS Apologies for the delay in responding. Work and College don't leave much time for the necessities of life :o)

0

Commented:
if StrToCurr(AddOil.Text) > (StrToInt(DECap.Text) - StrToInt(DECurrOil.Text)) then
begin
MessageDlg('OverFlow Warning! Please reduce to ' +
IntToStr((StrToInt(DECap.Text) - StrToInt(DECurrOil.Text))) +
' Tonnes', mtConfirmation, [mbOK], 0);
end;

1. no semicolon behind then
2. there was a parenthesis too much in the condition check
3. in the message:
you have to convert the edit's text contents in order to subtract them, then you must convert the result (which is of type integer) back to string. then you want to insert a string type expression into an explicit string (i.e. a string in ''), so you have to insert it by + ... +

questions?

BlackDeath.
0

Commented:
ok, that's one pair of parenthesis too much ;-)

BlackDeath.
0

Author Commented:
Adjusted points from 50 to 100
0

Author Commented:
BlackDeath, Excellent, Many thanks. I have one small problem that has arisen. 3 is greater than 20. 2 is greater than 10. Is this because I'm using Integer instead of something else? I'm not sure what I've done wrong. The numbers I'm placing in the editboxes are whole numbers i.e. 350000 or 620000 etc.

Many thanks

Nick
0

Commented:
integer is in the range
-2147483648..2147483647

is really 3 greater 20?
or do you use numbers beyond the range above?

best'd be, you post your code that contains the comparison
or send your project to me and i'll have a look at it:

andreas.naguschewski@vt.siemens.de

ok?

so long,

BlackDeath.
0

Commented:
say - is 2 greater than 30 in your app?
and 1 greater 20?

or just 3 greater 20?
and 2 greater 10?

i'm asking just because i've got an idea...

;-)

BlackDeath.
0

Author Commented:
BlackDeath,

What I've got is, an if statement -

if edit2.text > edit1.text then
message box, reduce to edit1.text
else
edit3.text = edit1.text

OK I know the syntax isn't right but that's the idea. (Not at home looking at the project)

But if edit1 value is 30000 and edit2 is 4 then the message box appears. 4 is not greater than 30000 so where am I going wrong? Frustration is beginning to set in :o)

Nick
0

Author Commented:
BlackDeath

3 is greater than 20
4 is greater than 30
2 is less than 20
3 is less than 30

Does this help?

Nick
0

Author Commented:
OK, I'm with you now, I have to convert the string to an integer before making the comparison.

I'll try it when I get back home and post here later

Many thanks

Nick
0

Author Commented:
BlackDeath, Excellent, Many thanks. Nick
0

Commented:
no prob.
have a nice day,

BlackDeath.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.