Solved

Procedural Difficulties

Posted on 2000-04-23
20
449 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 116
Convert GUI app into console app for Win32 Env 5 100
How to debug For loops? 3 49
Multi-layered image in FireMonkey 9 34
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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