Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"FOR" statements 1

Status
Not open for further replies.

guava65

Programmer
Jul 20, 2001
238
US
I am trying to write a routine that will take informtion from one data file and write consecutive records to another file based on dates and number of days.

For example:
1. The user will enter two dates
2. After posting the entry
The routine needs to write a seperate record
for each date from the first to the end date
that the user entered.



I've never really had to do a "FOR" statement and had no success with the following code. Can someone tell me how this actually works and what some simple rules are?
[tt]

screenshot.jpg



procedure TForm1.Button2Click(Sender: TObject);
var i, j : integer;
var n :string;
var d : TDateTimeField;

begin

tbNamesDays.Value := tbNamesOutDate.Value - tbNamesInDate.value;
n := tbNamesName.Value;
d := tbNamesInDate;
j := tbNamesDays.AsInteger;
tbNames.Post;


for i := 1 to 7 do
begin
tbBlock.Insert;
tbBlockName.Value := n;
tbBlockBlockDate.Value := d.Value;
tbBlock.Post;

d.AsFloat := d.AsFloat + 1;
end;

end;
[/tt]


Aloha,
cg
 
you are almost there with your code...just a couple of tweaks needed...(bear in mind I haven't tested this code as I simply don't have that much time :)

procedure TForm1.Button2Click(Sender: TObject);
var Count, DayCount : integer;
var UserName :string;
var StartDate : TDateTime;

begin

//presumably at this stage you have inserted the 'single block' record into the tbNames table....
tbNamesDays.AsInteger := trunc(tbNamesOutDate.Value - tbNamesInDate.value);
UserName := tbNamesName.AsString;
StartDate := tbNamesInDate.AsDateTime;
DayCount := tbNamesDays.AsInteger;
tbNames.Post;


for Count:=0 to DayCount-1 do
begin
tbBlock.Insert;
tbBlockName.AsString := UserName;
tbBlockBlockDate.AsDateTime := StartDate + Count;
tbBlock.Post;
end;

end;
 
Thank you BillDoorNZ!

Those few little changes made the difference. I appreciate your input. :)

Aloha,
cg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top