Autor Beitrag
jcop
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Di 03.11.09 14:28 
Hello,

A small question. I want to read following file in 2 listviews.

ausblenden Quelltext
1:
AC#1000,N215US,1%,WEEK,IFR,1/13:29:18,@1/14:34:31,340,F,0310,MDPC,1/15:39:44,@1/16:43:43,340,F,0311,TJSJ,1/18:00:00,@1/19:01:31,340,F,0312,MDPC,1/20:09:12,@1/21:14:25,340,F,0313,TJSJ,2/13:28:57,@2/14:34:10,340,F,0310,MDPC,2/15:39:23,@2/16:43:22,340,F,0311,TJSJ,2/17:59:39,@2/19:04:52,340,F,0312,MDPC,2/20:08:51,@2/21:14:04,340,F,0313,TJSJ,3/13:28:36,@3/14:33:49,340,F,0310,MDPC,3/15:37:48,@3/16:41:47,340,F,0311,TJSJ,3/17:59:18,@3/19:04:31,340,F,0312,MDPC,3/20:09:44,@3/21:13:43,340,F,0313,TJSJ,4/13:28:15,@4/14:32:14,340,F,0310,MDPC,4/15:37:26,@4/16:41:26,340,F,0311,TJSJ,5/13:26:40,@5/14:31:53,340,F,0310,MDPC,5/15:37:05,@5/16:44:46,340,F,0311,TJSJ,5/17:58:36,@5/19:03:49,340,F,0312,MDPC,5/20:07:48,@5/21:11:47,340,F,0313,TJSJ,6/13:30:00,@6/14:31:31,340,F,0310,MDPC,6/15:39:12,@6/16:44:25,340,F,0311,TJSJ,6/17:58:15,@6/19:02:14,340,F,0312,MDPC,6/20:07:26,@6/21:11:26,340,F,0313,TJSJ,0/13:29:39,@0/14:34:52,340,F,0310,MDPC,0/15:38:51,@0/16:44:04,340,F,0311,TJSJ,0/17:56:40,@0/19:01:53,340,F,0312,MDPC,0/20:07:05,@0/21:14:46,340,F,0313,TJSJ					


The First 5 entries are loaded into 1 listview, AC#1000,N215US,1%,WEEK,IFR,.
So far so good, but now I want to count every 6 follwing items
1/13:29:18,@1/14:34:31,340,F,0310,MDPC, and place these in another listview,
so I get a result like this.
1/13:29:18,@1/14:34:31,340,F,0310,MDPC,
1/15:39:44,@1/16:43:43,340,F,0311,TJSJ,
1/18:00:00,@1/19:01:31,340,F,0312,MDPC,
etc...

Is there an easy method for this??

my code so far is.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
procedure TfrmBglReader.btnLoadFPClick(Sender: TObject);
Const
  Counter = 6;
var
  CSV, Line, Leg: TStringList;
  i, iLeg: Integer;
  ListItemAC: TListItem;
  ListItemFP: TListItem;
begin
  if OpenDialog1.Execute then begin
      CSV := TStringList.Create;
      Line := TStringList.Create;
      Leg:= TStringList.Create;
      try
        try
          CSV.LoadFromFile(OpenDialog1.FileName);
        except
          CSV.Clear;
          MessageDlg('Error in File!'#13+Exception(ExceptObject).Message,mtError,[mbCancel],0);
        end;

        for i := 0 to CSV.Count-1 do begin
          Line.CommaText := CSV.Strings[i];
          if (Line.Count >= 5) then begin
            ListItemAC := lv_AcFlight.Items.Add;
            ListItemAC.Caption := Line.Strings[0];
            ListItemAC.SubItems.Add(Line.Strings[1]);
            ListItemAC.SubItems.Add(Line.Strings[2]);
            ListItemAC.SubItems.Add(Line.Strings[3]);
            ListItemAC.SubItems.Add(Line.Strings[4]);
            end;
           end;

//        for I := 0 to CSV.Count - 1 do begin
//          showmessage(intToStr(CSV.Count-1));
//          Line.CommaText := CSV.Strings[i];
//          ileg := 6;
//          Leg.CommaText := CSV.Strings[iLeg];


//                if (Leg.Count >= 6) then begin
               // ListItemFP := lv_Flight.Items.Add;
//                ListItemFP.Caption := (Leg.Strings[0]);
//                ListItemFP.SubItems.Add(Leg.Strings[1]);
//                ListItemFP.SubItems.Add(Leg.Strings[2]);
//                ListItemFP.SubItems.Add(Leg.Strings[3]);
//                ListItemFP.SubItems.Add(Leg.Strings[4]);
//                ListItemFP.SubItems.Add(Leg.Strings[5]);
//            end;
      finally
        Line.Free;
        CSV.Free;
      end;
    end;
end;


I tried to start loading this list from item 5 but I always get index out of bounds errors.

thanks for the help.
Johan
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mi 04.11.09 11:24 
Found the solution.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
procedure TfrmBglReader.btnLoadFPClick(Sender: TObject);
var
  CSV, Line: TStringList;
  i, iLeg: Integer;
  ListItemAC: TListItem;
  ListItemFP: TListItem;

  TotalAcft: Integer;
  TotalLegs: Integer;

begin
  if OpenDialog1.Execute then begin
      CSV := TStringList.Create;
      Line := TStringList.Create;

      try
        try
          CSV.LoadFromFile(OpenDialog1.FileName);
        except
          CSV.Clear;
          MessageDlg('Error in File!'#13+Exception(ExceptObject).Message,mtError,[mbCancel],0);
        end;

      screen.Cursor := crHourGlass;
      TotalAcft := 0;
      TotalLegs := 0;

        for i := 0 to CSV.Count-1 do begin
          Line.CommaText := CSV.Strings[i];
          if (Line.Count >= 5) then begin
            ListItemAC := lv_AcFlight.Items.Add;
            ListItemAC.Caption := Line.Strings[0];
            ListItemAC.SubItems.Add(Line.Strings[1]);
            ListItemAC.SubItems.Add(Line.Strings[2]);
            ListItemAC.SubItems.Add(Line.Strings[3]);
            ListItemAC.SubItems.Add(Line.Strings[4]);
            inc(TotalAcft);

            ileg := 5;
            repeat

              ListItemFP := lv_Flight.Items.Add;
              ListItemFP.Caption := (Line.Strings[ileg]);
              inc(ileg);
              ListItemFP.SubItems.Add(Line.Strings[ileg]);
              inc(ileg);
              ListItemFP.SubItems.Add(Line.Strings[ileg]);
              inc(ileg);
              ListItemFP.SubItems.Add(Line.Strings[ileg]);
              inc(ileg);
              ListItemFP.SubItems.Add(Line.Strings[ileg]);
              inc(ileg);
              ListItemFP.SubItems.Add(Line.Strings[ileg]);
              inc(ileg);
              inc(TotalLegs);

              until (ileg = line.count);

              Label1.Caption := 'Total Acft used: '+ IntToStr(TotalAcft);
              Label2.Caption := 'Total Legs: '+ IntToStr(TotalLegs);
              Application.ProcessMessages;

            end;
           end;

      finally
        Line.Free;
        CSV.Free;
        screen.Cursor := crDefault;

      end;
    end;
end;