Solved

Procedural Difficulties

Posted on 2000-04-23
20
439 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:NickRackham
  • 9
  • 8
  • 2
  • +1
20 Comments
 
LVL 3

Expert Comment

by:f15iaf
ID: 2741555
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2741647
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2741649
All values are numbers (integers?) not currency

Thanks

Nick
0
 
LVL 3

Expert Comment

by:f15iaf
ID: 2741715
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2741749
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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2746836
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

instead you gotta use

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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2746851
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2749393
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);
   AddOil.SetFocus;
   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.

f15iaf please don't keep posting as an answer. Post as a comment and if it does answer my question I can accept your comment as an answer.

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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2750602
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);
   AddOil.SetFocus;
 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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2750603
ok, that's one pair of parenthesis too much ;-)

BlackDeath.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 4

Author Comment

by:NickRackham
ID: 2752674
Adjusted points from 50 to 100
0
 
LVL 4

Author Comment

by:NickRackham
ID: 2752675
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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2754540
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
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2754544
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2754567
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
 
LVL 1

Accepted Solution

by:
BlackDeath earned 100 total points
ID: 2754598
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2754600
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2754604
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
 
LVL 4

Author Comment

by:NickRackham
ID: 2756098
BlackDeath, Excellent, Many thanks. Nick
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2758535
no prob.
have a nice day,

BlackDeath.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now