Source language: Translate to:

Search and Replace text in a file

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Re: Search and Replace text in a file

Postby UltraVox » Fri Dec 06, 2013 10:11 am

Indeep it's complicated !

Because there is nothing in NeoBook that allows selection, outside of an actions game with the mouse.
I hope I do not need to play with the mouse...

If you have an idea, do not hesitate !

Cheers,
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby CN_Iceman » Fri Dec 06, 2013 2:45 pm

Well... You can get all the values in a ListBox, but I don't know how to mark them in the ListBox.

Hope this helps:
Code: Select all
. The Variable [Select_All] will contain all the items in the ListBox1, so first we need to clean up.
. This is because in case you use the button several times. If the variable is not cleared, the next times you use the routine, the variable will contain the same data several times.
ClearVariables "[Select_All]"

. Get the size of the ListBox (number of items)
ListBoxSize "ListBox1" "[ListBox_Size]"

. A loop to read the entire ListBox and separating each item with a comma for example (you can choose another character instead comma)
Loop "1" "[ListBox_Size]" "[x]"
     ListBoxGetItem "ListBox1" "[x]" "[Result]"
     SetVar "[Select_All]" "[Select_All],[Result]"
EndLoop

. Now we delete de first comma because is innecessary.
StrDel "[Select_All]" "1" "1" "[Select_All]"


Now, we need to mark the items in the ListBox... investigating...

Greetings.
Greetings/Saludos, Jose.
www.icemansoft.es
User avatar
CN_Iceman
 
Posts: 297
Joined: Tue Mar 01, 2011 11:04 am
Location: España

Re: Search and Replace text in a file

Postby Gaev » Fri Dec 06, 2013 4:29 pm

CN_Iceman:
Now, we need to mark the items in the ListBox... investigating...

Are you looking to select (via script) more than one item in the ListBox ? ... if so (from the Help File) ...
In addition, List Boxes include an extra check box under Variable Contains that you can use to specify if the object will Allow multiple selections. This can be useful in circumstances where you want to allow the reader to select more than one item. When this option is enabled, the variable assigned to the List Box may contain more than one item. Multiple items will be separated by carriage returns, so you will need to use an Action like StrParse to find out which items were selected. For example:

StrParse "[ListBox1]" "[#13]" "[SelectedItems]" "[ItemCount]"
AlertBox "Hello" "You selected [ItemCount] items."

Note: The [#13] code above is used by NeoBook to indicate a carriage return.

So, as long as you have checked the option labelled Allow Multiple Selections, you can control the selections by updating the Variable: (to store selected item) e.g. if ListBox5 (with Entries Apple, Banana and Cherry) has associated variable of [ListBox5] then ...
Code: Select all
SetVar "[ListBox5]" "Apple[#13]Cherry"
... will select the first and last entry.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby CN_Iceman » Sat Dec 07, 2013 1:59 am

That's the way.
Thank's Gaev.

Greetings.
Greetings/Saludos, Jose.
www.icemansoft.es
User avatar
CN_Iceman
 
Posts: 297
Joined: Tue Mar 01, 2011 11:04 am
Location: España

Re: Search and Replace text in a file

Postby dec » Sat Dec 07, 2013 4:38 am

Hello,

I try iterating the listbox and then use the same Gaev approach to select the listbox items. However, we enter in problems if the list contain duplicate items. Or may I forget something? ;)
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby UltraVox » Sat Dec 07, 2013 4:47 am

David and others,

We already do what is necessary about double in the list. Me it does not pose a problem with this script :

Code: Select all
ListBoxFindItem "SourceImagesListBox" "[FilePaths[I]]" "[Result]"
   If "[Result]" "=" "0"
      ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths[I]]"
   Else
   EndIf
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby Gaev » Sat Dec 07, 2013 6:14 am

David:
However, we enter in problems if the list contain duplicate items. Or may I forget something?

You can get around it by specifying the Variable Contains: option as Item Number (1,2,3..) ... then, in order to get the text associated with an entry ...
Code: Select all
ListBoxGetItem "ListBox1" "[ListBox1]" "[Result]"

... of course, if you are allowing multiple selections, you have to ...
Code: Select all
StrParse "[ListBox1]" "[#13]" "[Selection]" "[NumberOfSelections]"
Loop "1" "[NumberOfSelections]" "[thisSelection]"
   ListBoxGetItem "ListBox1" "[Selection[thisSelection]]" "[thisSelectionText]"
   SetVar "[Result[thisSelection]" "[thisSelectionText]"
EndLoop
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby UltraVox » Sat Dec 07, 2013 6:36 am

EDIT :

I deleted my post because I wrote anything ... :oops:
Sorry.
Last edited by UltraVox on Sat Dec 07, 2013 7:07 am, edited 1 time in total.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dec » Sat Dec 07, 2013 6:59 am

Hello,

Maybe I enter into problems because I test with a ListBox which contain 1, 2, 3, 4, 5, 6... items. So even when we deal with "item numbers" we have some problems here. Of course the approach is valid for non repeated items listboxes and also for "normal" items and not 1, 2, 3, 4, 5, 6, etc. ;)
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby Gaev » Sat Dec 07, 2013 7:13 am

UltraVox:
Wow Gael is a specific script ?
It adds to the list items that are not there and do not let those already in it ?

Perhaps something got lost in translation ... but are you asking for a script that only adds entries that are not already in the ListBox ? ... if so ...
Code: Select all
.. say the entry requested to be added is in variable [AddThisEntry]
StrParse "[ListBox1]" "[#13]" "[Selection]" "[NumberOfSelections]"
SetVar "[MatchingEntryFound]" "No"
Loop "1" "[NumberOfSelections]" "[thisSelection]"
   ListBoxGetItem "ListBox1" "[Selection[thisSelection]]" "[thisSelectionText]"
      If "[thisSelectionText]" "=" "[AddThisEntry]"
         SetVar "[MatchingEntryFound]" "Yes"
         ExitLoop
      EndIf
EndLoop
If "[MatchingEntryFound]" "=" "No"
   ListBoxAddItem "ListBox1" "0" "[AddThisEntry]"
Else
   AlertBox "Sorry" "Entry with text of '[AddThisEntry]' already exists"
EndIf

Finally, you get to build something interesting with this button that selects the entire list ?

Are you asking for a script that will select every entry in a ListBox ?
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby UltraVox » Sat Dec 07, 2013 7:21 am

Gaev,

Thank you for this script to "filter" the entries in the listbox, very useful for me !!! :mrgreen:

And yes, we try to select all the items present in the list by clicking on a button... My list is "Multiple Selection" mode and "Text Item".

I feel that it is really hard to get...

Cheers,
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby dpayer » Sat Dec 07, 2013 7:45 am

dec wrote:Hello,

Maybe I enter into problems because I test with a ListBox which contain 1, 2, 3, 4, 5, 6... items. So even when we deal with "item numbers" we have some problems here. Of course the approach is valid for non repeated items listboxes and also for "normal" items and not 1, 2, 3, 4, 5, 6, etc. ;)



If the goal here is to deal with duplicates in a listbox, there is a function I made using NB actions only which will do that. It is part of the Advanced Listbox Functions.If interested, look here.

David P.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Search and Replace text in a file

Postby Gaev » Sat Dec 07, 2013 7:51 am

David:
So even when we deal with "item numbers" we have some problems here.

Can you elaborate ? ... perhaps with some example Entries ... and what you are trying to accomplish with them ?

UltraVox:
And yes, we try to select all the items present in the list by clicking on a button... My list is "Multiple Selection" mode and "Text Item".

Try this ...
Code: Select all
SetVar "[AllSelections]" ""
ListBoxSize "Listbox1" "[NumberOfEntries]"
If "[NumberOfEntries]" ">" "0"
   Loop "1" "[NumberOfEntries]" "[ThisEntry]"
      ListBoxGetItem "ListBox1" "[ThisEntry]" "[ThisEntryText]"
      SetVar "[AllSelections]" "[AllSelections][#13][ThisEntryText]"
   EndLoop
   .. remove first separator
   StrLen "[AllSelections]" "[AllSelectionsSize]"
   SubStr "[AllSelections]" "2" "[AllSelectionsSize]-1" "[ListBox1]"
EndIf

Note: This may not work if you have duplicate ListBox entries.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Search and Replace text in a file

Postby dec » Sat Dec 07, 2013 7:55 am

Hello,

Supose a listbox with these items:

Code: Select all
1
2
3
3
4
2
3
2
3
4
5
6


Then try to select all the items: even with your approach we enter into problems.

This code:

Code: Select all
SetVar "[MyListBox]" ""
ListBoxSize "MyListBox" "[ItemsCount]"
Loop "1" "[ItemsCount]" "[I]"
  ListBoxGetItem "MyListBox" "[I]" "[Item]"
  SetVar "[MyListBox]" "[MyListBox][#13][Item]"
EndLoop


Do not work well, no matter if the ListBox variable contains "Item text" or "Item number".
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Search and Replace text in a file

Postby Wrangler » Sat Dec 07, 2013 8:46 am

Try select the first item, then sendkeys CTRL-SHIFT-END.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

PreviousNext

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron