Forum > Beginners

Change of Delimited Text Order in Text File

(1/5) > >>

Boleeman:
Hi Folks.

Made a small program using 2 listboxes and a command button to change the order of 10 delimited string values (separated by semicolons). Wanted the last word of each line in the text file to be first.

If I change the value of i in    T := RowArray[i].Split(';');      for a specific line it works for that line

Almost like the looping is not working.

I applied the steps:
1.  Load text file in listbox1
2. Make a RowArray for each listbox row.
3  Split each listbox1 row
4. Make a new order of the strings.
5. Loop through the listbox1 by count and add to listbox2.

Here is my code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit delimited; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    bn_doIt: TButton;    ListBox1: TListBox;    ListBox2: TListBox;    procedure bn_doItClick(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.bn_doItClick(Sender: TObject);var  T, RowArray: array of string;  i : Integer; begin  ListBox1.Items.LoadFromFile('Test.txt');   i := 0;  T:= Nil;  RowArray := Nil;  RowArray:= ListBox1.Items.ToStringArray;        begin            for i := 0 to ListBox1.Items.Count - 1 do                T := RowArray[i].Split(';');                ListBox2.Items.Add(T[10] + ';' + T[0] + ';' + T[1] + ';' + T[2] + ';' + T[3]             + ';' + T[4] + ';' + T[5] + ';' + T[6] + ';' + T[7] + ';' + T[8] + ';' + T[9]);        end;end;  end.

alpine:
Don't you think the

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---RowArray := Nil;RowArray:= ListBox1.Items.ToStringArray;should be before/outside the for loop?

Boleeman:
Yes I made some changes before and forgot to change that. Still not working (only get the last line).


This part does not increment for i = 0, 1, 2


for i := 0 to ListBox1.Items.Count - 1 do
 
 
      T := RowArray.Split(';');
      ListBox2.Items.Add(T[10] + ';' + T[0] + ';' + T[1] + ';' + T[2] + ';' + T[3]
   + ';' + T[4] + ';' + T[5] + ';' + T[6] + ';' + T[7] + ';' + T[8] + ';' + T[9]);

alpine:

--- Quote from: Boleeman on January 22, 2023, 11:24:32 am ---Yes I made some changes before and forgot to change that. Still not working (only get the last line).

--- End quote ---

You don't have begin ... end after the for. Only indentation.

Boleeman:
Tried with


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.bn_doItClick(Sender: TObject);var  T, RowArray: array of string;  i : Integer; begin  ListBox1.Items.LoadFromFile('Test.txt');   i := 0;  T:= Nil;  RowArray := Nil;  RowArray:= ListBox1.Items.ToStringArray;        begin            for i := 0 to ListBox1.Items.Count - 1 do                T := RowArray[i].Split(';');                ListBox2.Items.Add(T[10] + ';' + T[0] + ';' + T[1] + ';' + T[2] + ';' + T[3]             + ';' + T[4] + ';' + T[5] + ';' + T[6] + ';' + T[7] + ';' + T[8] + ';' + T[9]);        end;end;  end.

Navigation

[0] Message Index

[#] Next page

Go to full version