Solved

which fieldtype to choose when storing a floating point value

Posted on 2002-03-11
20
241 Views
Last Modified: 2010-04-05
hi folks,
i have a paradox table with some numerical values. in my app there is a calculation which often has a result like 4,75. which type of field (BCD, numerical, date/time ....)do i have to choose for this field in the database. later on i will use this floating point value in a dbchart. thx
0
Comment
Question by:ugross
  • 8
  • 7
  • 4
  • +1
20 Comments
 
LVL 4

Expert Comment

by:YodaMage
ID: 6855653
Float is type Number in Paradox.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6855657
In Paradox, the Number type will be fine. If you ever use MS Access, my advice is not to use the Single type (this goes for the Single type in Delphi as well in my opinion), use the Double type.

J.
0
 

Author Comment

by:ugross
ID: 6855682
hi,
thats what i thought, i now set the database field to type numeric, i now get the error that "" is not a valid integer value, i think my problem lies in these rows of code:
query1.fieldvalues['Grade'] := strtofloat(dbedit1.text);
  where the field grade is the value which will be like 4.75
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6855705
Because FieldValues always uses Variants, it may be a somewhat slower method of accessing data, than using a field’s native format (i.e., using a field’s AsXXX property), especially in applications that process large amounts of data.

query1.fieldbyname('Grade').AsFloat := strtofloat(dbedit1.text);
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6855723
You also have abug if dbeidt1.text is blank. You need something like

if (dbedit1.text = '') then dbedit1.text:= '0.00';
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6855730
Yes, what you're getting is an error in the conversion of a blank edit box to a Float.
0
 

Author Comment

by:ugross
ID: 6856206
hi,
sorry for keepin' u waiting
i tried:
query1.fieldbyname('Grade').AsFloat := strtofloat(dbedit1.text);

but now im getting operator or semikoölon missing, thx
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6856213
If you have typed it in Delphi as you have typed it in here, then the line above should cause no problems.

J.
0
 

Author Comment

by:ugross
ID: 6856263
hi, sorry entered the if..then code but error msg appears again and again (tried different positions already), thx
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6856296
The Query component is called Query1 and the Edit box is called DBEdit1, right? Can you give us the form code?

J.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ugross
ID: 6856363
hi, here it is

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
try
       edit1.text := intToStr(StrToInt(dbcombobox3.text) + StrToInt(dbcombobox4.text));
edit1.text := floattostr(strtofloat(edit1.text) / strtofloat(edit2.text));
dbedit1.Text := floattostr(strtofloat(edit1.text));
query1.fieldbyname('Grade')AsFloat:= strtofloat(dbedit1.text);

except
       on econverterror do messagedlg('Please check the values',mtinformation, [mbok],0);
       end;
end;
end.

let the code for the if..then statement out of the code for the moment
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6856401
OK. If your DBComboBoxes have their Style property set to csDropDownList, or anything other than csDropDown, then you cannot use the Text property of them. The Text property will return blank, which would explain why you are getting

'' is not a valid integer value

Either change the Style property to csDropDown or instead of reading the Text property, do the following:

Edit1.Text := IntToStr(StrToInt(DBComboBox3.Items[DBComboBox3.ItemIndex]) + StrToInt(DBComboBox4.Items[DBComboBox4.ItemIndex]));

J.
0
 

Author Comment

by:ugross
ID: 6856538
sorry,
first checked how the combos r set, they r all csdropdown, then replaced my code by yours for the edit1....statement but th eprob reminas im still getting the error operator or semikolon missing
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6856544
When you get the error, it gives you a line number, what is the code for that line?
0
 

Author Comment

by:ugross
ID: 6856561
the line is


query1.fieldbyname('Grade')asfloat:= strtofloat(dbedit1.text);
0
 
LVL 4

Accepted Solution

by:
jsweby earned 50 total points
ID: 6856569
GOT IT!

I finally spotted it, there's no point between the fieldname and the AsString property:

query1.fieldbyname('Grade')AsFloat:= strtofloat(dbedit1.text);

should be

query1.fieldbyname('Grade').AsFloat:= strtofloat(dbedit1.text);

Note the extra point between ('Grade') and AsFloat

J.
0
 

Author Comment

by:ugross
ID: 6856580
aaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhh

thank u very much
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6856593
I gave that answer about 12 comments ago.
0
 
LVL 3

Expert Comment

by:Rem
ID: 6856842
Yodamage should have had the points for this one.

When participating, play by the rules.
0
 

Author Comment

by:ugross
ID: 6856852
ok, thx
hi yodamage i wiull put in a question fo ru with a similiar name, same points pls grab it
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
When I am typing into a TEdit last word repeats 7 117
How to debug For loops? 3 46
Firemonkey webbrowser scrollbars ? 1 29
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

21 Experts available now in Live!

Get 1:1 Help Now