May 08, 2024, 01:24:09 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Listview searching

Started by Brian, October 11, 2015, 12:04:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

Has anyone any idea about how to search a listview? I need to search for a particular piece of text and, if it is found,
count back three lines in the file, save those lines, and then save the line I first searched for

Then I would need to remove those four lines, and start the search again for the next sequence of four lines

Any ideas?

Brian

LarryMc

from the help file
Quoteposition = CONTROLCMD( window | dialog, ID, @LVFINDITEM, text$)

Searches for an item. Returns the zero-based index of the item or -1 if the item could not be found.

text$ is the case sensitive string to search for.

since that is such an easy answer I'm betting you are not giving us all the info we need to know to properly answer your question

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

I saw that command, and misinterpreted what "position" meant. I now realise
it is the position of the line in which the text searched for is

Thanks for jogging the brain cells!

Brian

Brian

Right, I've been messing about long enough here - still don't get any sense (but that's not unusual)

OK, within each line of the listview (and there could be hundreds of lines), there is one cell that contains
either the text AA500, AA501, AA502 or AA503

If there is an AA503, there will be three lines above it (AA502, AA501 and AA500)
If there is an AA502 (there will be two lines above it (AA501 and AA500)
If there is an AA501, there will be just the one above, AA500
An AA500 on its own, without any of the other three, makes it a single entry

I need to strip out the four AAs first, and save them to a file
Then the three AAs, save them
Then the two AAs, save them
Finally, the AAs on their own

The only way I can see to do it is to find the four AAs, save them, and then remove them. Removing
just the AA503 would leave the previous three as another "block"

The combinations of four, three, two and one lines can be anywhere in the file. The idea is to save
the whole again with fours first, then the threes, twos and finally single entries

I can't post the data, as I would be shot at dawn!

Any working code would be gratefully received,

Brian


billhsln

If sample data was:

AA500
AA501
AA502
AA503
AB500
AB501
AC500
AD500
AD501
AD502
AD503

What would your output file look like?  Just trying to see what matching criteria is.

Bill
When all else fails, get a bigger hammer.

Andy

Hi Brian,

I've had an initial go for you, see attached.

Simply compile, run and then close the window to end the program.

You should have four text files in the same directory as the program called:
Block1.txt
Block2.txt
Block3.txt
Block4.txt

Think this is a starting point for you - if it helps.

What I did was to locate each AA500's position in the listbox, from there you can work out the "gap" between each of them and so you can tell if it belongs to a block of 4 or 3 etc..

Hope this helps...
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

And this one puts them all into a single file called BlockSorted.txt.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Thanks for your efforts - I can't look at the moment; it will have to wait until I get home

I noticed you are using a Listbox, and I am using a Listview. But no matter - there
is no earthly reason why I can't use a Listbox instead. It will probably be easier to
read and write the data using a Listbox, anyway

Thanks a lot,

Brian

Andy

Hi Brian,

My mistake, I saw "list" and jumped to listboxes! - typical me!!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Just in case you do decide to use listboxes, I've added this amended code that has two listboxes.

In this program, listbox 1 has the AA500's your looking for (searched).
Listbox 2 has some corresponding data you may want to output for each entry in listbox 1.

You can change which listbox you search on, but amend the code accordingly.

It also shows how you can have multiple listboxes which will "stick" to the corresponding searched listbox (1 here).

Hope this gives you ideas Brian!

I'm sure this could be optimised, and maybe someone can adapt it to listviews?

I would probably use listboxes myself, don't forget you can always "hide" the other listboxes from the window if needed.

See attached.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Getting there, Andy! Have to go out now to pick up my grandson from table tennis practice

The joys of being a Granddad!

Brian

Andy

Hi Brian,

Done another version of the program for you.

This time, compile, run and notice the entries are listed as read in (i.e. not in block order).

Then:
Click "Sort and Export".

The entries will not only be saved to file in block order, but re-listed in block order starting with the block of 4's, then 3's etc...

Does this help you Brian?

Thanks,
Andy.
:)

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

I like the idea of this one - gives you a chance to check before committing to the sort.

As before, it will have to wait until I get home...

Brian

LarryMc

Brian
In your early comments you said
OK, within each line of the listview (and there could be hundreds of lines), there is one cell that contains
either the text AA500, AA501, AA502 or AA503

That lead me to believe you were using a LISTVIEW so you could put the incoming data in CELLS like you would data from a database or a spreadsheet.

One of the things I was going to tell you about searching in a Listview using
position = CONTROLCMD( window | dialog, ID, @LVFINDITEM, text$) is that it only searches in the first cell or the "item" and not the rest of the cells.

If you are going to use List boxes there is only one "cell".  So you can't make it look like a spreadsheet.  It's just one long string.  So, other than your original comment we don't know what the input you're dealing  with really looks like and which control you should use and if really should be using a listview whether or not you have it set up right.  That's why I made the offer I did.  With the work Andy has done I hope you are using one long string and really needed a Listbox in the first place.  ;)
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Hi Brian,

Right, I've converted the program for your listview!

See attached.

Same as before, compile, run, see the unsorted blocks in the list.

Click "Sort and Export".

The listview will hopefully now be sorted into blocks of 4, 3, 2, and 1.

The program also produces the txt files Block1,2,3,4, and BlockSorted.txt.

Does this help any?

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

October 15, 2015, 12:16:34 AM #15 Last Edit: October 15, 2015, 06:23:37 AM by andy1966
Found an error for block 1's.

This is now corrected with this update of the listview block sort attached, please try this one.

Final note - I should have said "listview" instead of "listboxes" in the comment lines of the program.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

I WILL get to it later. Family seems to be getting in the way at the moment. My daughter
has just had an op on a big toe today. They had to break it to insert a pin, as the joint was
breaking up badly. She's home tonight, and feeling a bit sorry for herself!

A bit of TLC is in order...

Brian

Andy

October 15, 2015, 10:21:03 PM #17 Last Edit: October 16, 2015, 12:04:43 AM by andy1966
No problem Brian,

I just had a bit of time to have a look at it for you.

Family and health comes first.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.