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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Plz translate

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
0
0
SE
Can someone brighter than me plz translate this psuedo code into BCB?! (using bcb6e)

The general idea is to remove lines from Memo1 that contains words from memo2 (each word is seperated by cariage return)the user also has the options:
"Remove" remove line if word exists else keep
and
"keep", keep line if word exists else keep

for each line in memo1
store line in array
for each word in memo2
check if line contains word
if keep if exist word
if exists
remove line
stop.
stop.
else if remove if exist word
if exists
remove line
stop.
stop.
end.
end. My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Have you created a project with a form and 2 memos componets? Rod
 
Yes, that is true... my foremost problem is that when I run my own code...:
Code:
int LinesCount = txtPreview->Lines->Count; // lines in text document (memo1)
int FilterCount = txtFilter->Lines->Count; // No. words to filter (memo2)
int keeprem;
AnsiString RedeamLine; //check curr line to delete or not
for( int i = 0; i<LinesCount; i++ )
{
  for( int x = 0; x<FilterCount; x ++ )
  {
    keeprem = txtPreview->Lines->Strings[i].Pos(txtFilter->Lines->Strings[x]);
    // I chosed to use this for here I will know if the word exists or not
    // if exists it will return 1(first pos of char, second char 2 and so on)
    // and 0 if the word isn't contained anywhere in the line
    if( keeprem == 0 )
    {
      txtPreview->Lines->Delete(1);
    }
  }
}

My problem is that it doesn't work... I've drawn a schematic too, in vain, either I drew it wrongly, or I coded it wrongly. Can't see either!!

The code just should remove all lines if it doesn't find the word, but it won't!! It simply removes about half, and when I run again, half again and so on untill only one remains and it does crap to that one!! My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
NOTICE*
In my code only the first test is processed, the other is not vital for the functionality!! This one will remove lines that DOESN*T containt, the other (which is not present) will keep lines that doesn't have the word.... My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Hi,
the problem is, that everytime you call delete, a line is removed. So the numbers of lines is decreased to. So check if you delete a line, and if so, increase i.

bool LineRemoved;
for( int i = 0; i<LinesCount; )
{
LineRemoved = false;
for( int x = 0; x<FilterCount; x ++ )
{
keeprem = txtPreview->Lines->Strings.Pos(txtFilter->Lines->Strings[x]);
// I chosed to use this for here I will know if the word exists or not
// if exists it will return 1(first pos of char, second char 2 and so on)
// and 0 if the word isn't contained anywhere in the line
if( keeprem == 0 )
{
txtPreview->Lines->Delete(1);
LineRemoved = true;

}
}
if (!LineRemoved) i++;
}

CU Stummel
 
Thanks Stummel, now I see my problem...
though I did see a flaw or two(after a few minutes of testing)
This is the final code, which actualy works; even with multiple words(with cariage return as delimiter)!!
Code:
int fitLines = txtPreview->Lines->Count;
int fitFilter = txtFilter->Lines->Count;
bool remove = false;
for( int i=0; i<fitLines; i++ )
{
    remove = false;
    for( int x=0; x<fitFilter; x++ )
    {
        if( txtPreview->Lines->Strings[i].UpperCase().Pos( txtFilter->Lines->Strings[x].UpperCase())==0 )
        {
            remove = true;
            break;
        }
    }
    if( remove )
    {
        txtPreview->Lines->Delete(i);
        i--;
        fitLines--;
    }
}


Thanks again for opening my eyes heheh...[thumbsup2] My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Start from the bottom of the list you are deleting from and work up to the top
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top