Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Listing items in listbox without certain extensions

Posted on 2004-10-19
4
Medium Priority
?
285 Views
Last Modified: 2010-04-05
I have a list of items in a listbox.  I now want to list these same items in a second listbox but without files with extensions of ".gif" and ".jpg". I have tried the following code but it doesn't work.  Why?  I am using Delphi 6.  Many thanks for your help.

i := 0;
repeat
begin

if (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') or (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg) then
ListBox2.Items.Add(ListBox1.Items.Strings[i];

end;
inc(i);
until i = ListBox1.Items.Count;    
0
Comment
Question by:rincewind666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 1000 total points
ID: 12350069
(ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') or (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg)

This evaluates to true all the time... :-)

(ExtractFileExt(ListBox1.Items.Strings[i]) <> '.gif') AND (ExtractFileExt(ListBox1.Items.Strings[i]) <> '.jpg)

AND
AND
AND
AND
AND

But better:
not (AnsiCompareText(ListBox1.Items.Strings[i], '.gif') or AnsiCompareText(ListBox1.Items.Strings[i], '.jpg'))

Add the if-then yourself, please...
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12350081
Oh, and in my last code, it must be OR, not AND...
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 1000 total points
ID: 12350140
You may be able to speed the process up a little bit, and make it more reable with something  like:

var
  E:string;

i := 0;
repeat
  begin
    E:=lowercase(ExtractFileExt(ListBox1.Items.Strings[I]);
    if (E<>'.gif') and (E<>'.jpg')    //easy to add more tests here...
    then
      ListBox2.Items.Add(ListBox1.Items.Strings[i];
  end;
  inc(i);
until i = ListBox1.Items.Count;    
0
 

Author Comment

by:rincewind666
ID: 12350648
Many thanks for your help. Greatly appreciated.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question