線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:770
推到 Plurk!
推到 Facebook!

More syntax problem

尚未結案
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-12 00:11:32 IP:217.36.xxx.xxx 未訂閱
How can i specify one record within one field? say under Field: House Number, Record 1: 17 what I am trying to do is compare a value in a edit with another value stored in a table. ideal syntax: begin if (Edit1.Text > {the missing statement}) then ShowMessage('Number is correct!');
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-12 00:32:26 IP:61.221.xxx.xxx 未訂閱
Use the dataset 'FieldByName' to get the value from column name:    
if (Edit1.Text > Query1.FieldByName('myCol').AsString) then
  ShowMessage('Number is correct!');
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-12 00:48:55 IP:217.36.xxx.xxx 未訂閱
That will only specify the field column, but that the specific record i need. say i have a field column called 'Grade A' and with the following record Maths : 78 Art : 75 Music : 70 and I want: begin if (Edit1.Text > {compare with Column Grade A/ Row Maths = 78}) then ShowMessage('Number is correct!'); Can i do that?
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-12 01:37:29 IP:61.221.xxx.xxx 未訂閱
I don't know if your data like :    
'NO'    'Grade A'       'xxx'
-------------------------------
'1'     'Maths : 78'    ....
'2'     'Art : 75'      ....
'3'     'Music : 70'    ....
'4'      .......        ....
If you want to get the data from column 'Grade A', you can use the Locate function the the Recode and get the grade with RightStr function (if all the grade data is 2 digits number)
procedure TForm1.Button3Click(Sender: TObject);
var
  FData: Integer;
begin
  if Table1.Locate('GradeA', 'Maths', [loPartialKey]) then
  begin
    FData := StrToInt(RightStr(Table1.FieldByName('GradeA').AsString,2));
  end;
end;
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-12 02:52:31 IP:217.35.xxx.xxx 未訂閱
procedure TForm1.Button3Click(Sender: TObject);var FData: Integer;begin if Table1.Locate('GradeA', 'Maths', [loPartialKey]) then begin FData := StrToInt(RightStr(Table1.FieldByName('GradeA').AsString,2)); end;end; I didn't understand what u did here. My table look like this: Subject Name/ Grade A/ Grade B// ___________________________________________________ Maths 78 68 Art 75 60 What I am trying to do is to work out the Exam grades automatically, by entering a mark, say I enter Subject: Maths and Marks: 80 but I don't know how to do is the syntax comparing the mark I entered with Maths (Row), Grade A (Column) please say so if I didn't explain it clearly this is really really hard to do i think, because different subject have different grade boundries, if they are all the same, i can just compare the mark with a number Plz help me
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-12 09:40:43 IP:211.76.xxx.xxx 未訂閱
Subject Name/    Grade A/    Grade B//
___________________________________________________
Maths               78          68
Art                 75          60
OK, let's see how to get the grade.
Function getDataFromSubjnGrade(Subj, Grade: String): Integer;
begin
  if Table1.Locate('Subject Name', Subj, []) then
  begin
    FData := Table1.FieldByName(Grade).AsInteger);
  end;
end;
But this is not a good table schema if you want to distinct student grade. The better way is:
Subject Name/pk    Grade/pk    upperBound/    lowerBound/
__________________________________________________________
Maths                A            100           78
Maths                B             77           68
Art                  A            100           75 
Art                  B             74           60
系統時間:2024-05-08 19:41:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!