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 Gaev » Sat Dec 07, 2013 10:15 am

David Esperalta:
Do not work well, no matter if the ListBox variable contains "Item text" or "Item number".

See my Note: underneath the code which says that it may not work with Duplicate entries.

Note that "when you select multiple duplicate entries", the variable correctly reflects this ... only when you try to set this variable via script that "it does not render the subsequent duplicate entry/entries as selected" ... probably NeoBooks needs to look for "the next available unselected entry with the matching Text" ... instead of "the first entry with the matching Text"

Wrangler:

For some reason, Ctrl+Shift+End does NOT work (on my computer) ... but Ctrl+Shift+DownArrow works ... so it could be applied "as many times as there are entries"


However, one should ask ... "what is the purpose of duplicate entries in a ListBox" ? ... since you can check (via script) whether an entry exists or not, why not ...

- prevent duplicates

or

- add a suffix to the second/subsequent 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 Wrangler » Sat Dec 07, 2013 10:32 am

Gaev:

Try this with a populated listbox and put something like this in the button:

FocusObject "searchproductlistbox"
ListBoxGetItem "searchproductlistbox" "1" "[line1]"
SetVar "[searchproductlistbox]" "[line1]"
SendKeys "" "{CtrlDn}{ShiftDn}{End}{CtrlUp}{ShiftUp}"

Be sure to set the listbox to multiple selections. Works perfectly for me.
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

Re: Search and Replace text in a file

Postby Gaev » Sat Dec 07, 2013 10:57 am

Wrangler:

I tried to do the Ctrl+Shift+End combo manually (i.e. with fingers on keyboard) ... that was what did not work ... good to know that the scripted equivalent does work.
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 11:01 am

Hello,

I agree that in "normal uses" we avoid duplicate items or can take another way to deal with duplicate items. I only comment that to be care, in the sense that apparently is not possible to get a "universal solution". Maybe we think that the code work in all the scenarios and get into problems in the future. But the UltraVox ListBox do not contain duplicates (can't contain duplicates because the list is filled with file paths which are uniques) so the proposed code can work without problems. ;)
.
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 mishem » Sat Dec 07, 2013 1:14 pm

Do not work well, no matter if the ListBox variable contains "Item text" or "Item number".

"Item number"
All

Code: Select all
SetVar "[MyListBox]" ""
ListBoxSize "MyListBox" "[ItemsCount]"
Loop "1" "[ItemsCount]" "[I]"
.ListBoxGetItem "MyListBox" "[I]" "[Item]"
If "[I]" "=" "1"
SetVar "[MyListBox]" "[I]"
Else
SetVar "[MyListBox]" "[MyListBox][#13][I]"
EndIf

EndLoop

You can go the other way.
There is a plug FileUtils.
dgListCheckBox
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

Re: Search and Replace text in a file

Postby CN_Iceman » Sun Dec 08, 2013 2:54 am

Wrangler wrote:FocusObject "searchproductlistbox"
ListBoxGetItem "searchproductlistbox" "1" "[line1]"
SetVar "[searchproductlistbox]" "[line1]"
SendKeys "" "{CtrlDn}{ShiftDn}{End}{CtrlUp}{ShiftUp}"

Be sure to set the listbox to multiple selections. Works perfectly for me.


For me SendKeys is not working well. As Gaev, I tried to do the Ctrl+Shift+End combo manually and nothing happens. In my case, I must use Ctrl+Shift+Down, but is not working well in the program, so I made this small code that works perfect, because now get and select all the items:
Code: Select all
.Using [searchproductlistbox] and [line1] Wrangler's variables
.Be sure to set the listbox to multiple selections.
ListBoxSize "searchproductlistbox" "[ListBox_Size]"

Loop "1" "[ListBox_Size]" "[x]"
     ListBoxGetItem "searchproductlistbox" "[x]" "[line1]"
     SetVar "[searchproductlistbox]" "[searchproductlistbox][#13][line1]"
EndLoop

StrDel "[searchproductlistbox]" "1" "1" "[searchproductlistbox]"
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 Wrangler » Sun Dec 08, 2013 10:05 am

For me SendKeys is not working well. As Gaev, I tried to do the Ctrl+Shift+End combo manually and nothing happens.


You both say you tried it manually. Did anyone try the code I posted?
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

Re: Search and Replace text in a file

Postby CN_Iceman » Sun Dec 08, 2013 10:13 am

In my case, that is afirmative... with code and manually.
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 Wrangler » Sun Dec 08, 2013 4:32 pm

Hmmm. This is interesting. I originally tested my code in a project I'm currently working on. This project feeds the listbox out of an Access database using a loop. Still works every time. But when I try it loading the listbox manually or using a loop out of a text file, it doesn't work. With either the keyboard or the script. So, apparently, it only works when feeding the listbox out of a database. Probably something to do with line feeds.

Anyway, just something else to make note of.
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

Re: Search and Replace text in a file

Postby UltraVox » Mon Dec 09, 2013 3:05 am

Hello all,

I want to thank you all for the help you give me. It's great :)

Question for you :
Is it possible to copy all selected items in a list, to copy them to another list in another page of the publication ?

This copy must be from a button. This button is active only if there is 6 selected items in the start list (this problem is already solved).

List name start : ListConvertedImages (variable [ListConvertedImages])
List name destination : ListFilesToAssign (variable [ListFilesToAssign])

Thank you for your help.
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Mon Dec 09, 2013 5:24 am

This is good, I found.
Thank you anyway :)
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby UltraVox » Mon Dec 09, 2013 7:55 am

Hello all,

I would like to tell you about a little technical problem I have with NeoBook, or with the own application.

I have a directory of images. It contains 5432 images (textures for video games). I test to list all the images in a list. Once they are all in the list, for whatever reason, the application stops responding. If I click anywhere in my application, a Windows sound is heard, but there is no error message. I have to press Ctrl+Alt+Del to exit my application. :cry:

I go to Project > Project Properties > Access... to modify "Cache size for images". But it does not change... 30 or 100, the problem is still there.

Have you an idea of the problem ?
I give you the code that I currently use to load all images in a directory, for all practical purposes !

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
:AddDir
. GESTION DES REPERTOIRES
. Ouvrir une fenêtre de sélection de répertoire
FolderBox "Select your images directory :" "[SelectedDir]"
. Test if the user really choose a directory
If "[SelectedDir]" "=" ""
   . Inform to the user or just "cancel" the task...
   AlertBox "[AppTitle]" "Please, choose a valid directory."
Else
    . Générer la liste des éléments du répertoire et sauver dans une variable
    FileList "[SelectedDir]\[InputMaskConvert]" "Files+Folders" "[FilesinFolder]"
    . Séparer la chaine en nombre
    StrParse "[FilesinFolder]" "[#13]" "[FilePaths]" "[FilesCount]"
    . Calculer le nombre d'items présents dans la liste
    ListBoxSize "SourceImagesListBox" "[ListNbr]"
    . Aditionner les items de la liste + le nombre de fichiers sélectionnés
    Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"
    Loop "1" "[FilesCount]" "[I]"
    . Extraire les noms de fichiers sélectionnés
    ExtractFileName "[FilePaths[I]]" "[FileName]"
    . Faire une recherche d'
existence dans la liste, et si la selection n'existe pas déjà, l'ajouter dans la liste
    ListBoxFindItem "SourceImagesListBox" "[SelectedDir]\[FilePaths[I]]" "[Result]"
       . S'il n'y a pas de double
       If "[Result]" "=" "0"
       . Ajouter les items dans la liste
       ListBoxAddItem "SourceImagesListBox" "0" "[SelectedDir]\[FilePaths[I]]"
       . Si non (s'il y a des doubles)
       Else
       . Soustraire de la somme totale d'
éléments le nombre de doublons
       Math "[ListNbr]+[FilesCount]-[FilesCount]" "-1" "[TotalNbrList]"
       EndIf
    EndLoop
    . S'il existe des doubles, créer une boite d'avertissement
    If "[Result]" "<>" "0"
      AlertBox "[AppTitle]" "You have selected [FilesCount] file(s) already in the list.|[AppTitle] will not add these files."
    EndIf
EndIf
Return
 
Parsed in 0.009 seconds, using GeSHi 1.0.8.10


Thanks for your help...
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby mishem » Mon Dec 09, 2013 8:09 am

Math "[ListNbr]+[FilesCount]-[FilesCount]" "-1" "[TotalNbrList]"
????????????

FileList "[SelectedDir]\[InputMaskConvert]" "Files+Folders" "[FilesinFolder]"
[InputMaskConvert] ?
+Folders ???

Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"
????

In short I personally do not understand many things in this code.
:)
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

Re: Search and Replace text in a file

Postby UltraVox » Mon Dec 09, 2013 8:23 am

The script works perfectly with a directory containing eg 100 images. So it should work with 5000 images...

About that :
Code: Select all
Math "[ListNbr]+[FilesCount]-[FilesCount]" "-1" "[TotalNbrList]"


If I write :
Code: Select all
Math "[ListNbr]-[FilesCount]" "-1" "[TotalNbrList]"

The result is false...

[InputMaskConvert] = Mask custom file, for use with the npImgs plugin :
Code: Select all
SetVar "[InputMaskConvert]" "All image files supported|*.BMP;*.JPG;*.PNG;*.MNG;*.JNG;*.GIF;*.DDS;*.TGA;*.JP2;*.PSD;*.PCX;*.BSI;*.CIF;*.IMG;*.DAGTEXTURE;*.DAGSKY;*.PBM;*.PGM;*.PPM;*.PAM;*.PFM;*.TIF;*.XPM|BMP - Windows Bitmap|*.BMP|BSI - Bethesda Image|*.BSI|CIF - Daggerfall MultiImage|*.CIF|DAGSKY - Daggerfall Sky Image|*.DAGSKY|DAGTEXTURE - Daggerfall Texture|*.DAGTEXTURE|DDS - DirectDraw Surface|*.DDS|GIF - Graphics Interchange Format|*.GIF|IMG - Daggerfall Image|*.IMG|JNG - JPEG Network Graphics|*.JNG|JPG - Joint Photographic Experts Group|*.JPG|JP2 - JPEG 2000|*.JP2|MNG - Multiple Network Graphics|*.MNG|PAM - Portable Arbitrary Map|*.PAM|PBM - Portable Bit Map|*.PBM|PCX - ZSoft Paintbrush|*.PCX|PFM - Portable Float Map|*.PFM|PGM - Portable Gray Map|*.PGM|PNG - Portable Network Graphics|*.PNG|PPM - Portable Pixel Map|*.PPM|PSD - Photoshop Data|*.PSD|TGA - Truevision Targa|*.TGA|TIF - Tagged Image File|*.TIF|XPM - X Pixmap|*.XPM"


... and ...
Code: Select all
Math "[ListNbr]+[FilesCount]" "-1" "[TotalNbrList]"

What is the problem ?
UltraVox
 
Posts: 419
Joined: Sat Jul 28, 2007 11:14 am
Location: France

Re: Search and Replace text in a file

Postby mishem » Mon Dec 09, 2013 8:23 am

Requires plug-in zmFunctions.
That's how it should work.
Only I did not check. Try it.

Code: Select all
:AddDir
FolderBox "Select your images directory :" "[SelectedDir]"

If "[SelectedDir]" "=" ""
   AlertBox "[AppTitle]" "Please, choose a valid directory."
   Return
Else
............Mask - a mask file names (without paths) or file extensions.

............For example: NeoBook.exe or *. Txt.

............You can search on several names or file extensions, in this case, file names or extensions separated by semicolons.

............To find all types of files, this argument can be left blank.

zmFindFiles "[InputMaskConvert]" "[SelectedDir]" "SubFolders" "" "[FilesinFolder]"
    StrParse "[FilesinFolder]" "[#13]" "[FilePaths]" "[FilesCount]"
    Loop "1" "[FilesCount]" "[I]"
    ListBoxFindItem "SourceImagesListBox" "[FilePaths[I]]" "[Result]"
       If "[Result]" "=" "0"
         ListBoxAddItem "SourceImagesListBox" "0" "[FilePaths[I]]"
       EndIf
    EndLoop
EndIf
Return
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

PreviousNext

Return to NeoBook Action Commands

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest