Archive: NSIS Search function question


NSIS Search function question
Hi there,
I'm wondering if it's possible to create an EXE-file, which can search through a TXT-file for unique numbers?

And when a number is found, to return the result containing the description of that number, and the price.


There's lots of text file manipulation files on the Wiki:
http://nsis.sourceforge.net/Category...tion_Functions

-Stu


Hi Stu!
Thanks for the quick reply.

I think you misunderstand the question.

I have a txt file which contains part numbers in the following way:

Part Number (TAB) Description of Part Number (TAB) Price of the Part

I would like to make an exe-file, which allows the users of this file to search for a specific part number. Every part number is a unique number.

When the script finds the number, it has to return the result, as described above:
Part number
with description
and the price of the part

Later on, the idea would be that the result of the search can be added (by e.g. a button) in some sort of order form, which can be printed and faxed, or e-mailed to a specific address.

It's hard for me to explain, but if there are any questions, I'll do my best to answer.


Have a look at the functions in the NSIS help, Appendix E. I think the 'LineFind' function should be just what what you are looking for. It would allow you to search for the line in the file. Once you find what you are looking for, you can create a callback function to read the line and parse the results for displaying to the user.

(If you don't find Appendix E in the help files, you'll need to get the latest build of NSIS.)


The problem is, that the users only have to be able to search for the part number. They don't know which part number is on which line.


Sorry... I misread the original post...

What I'd probably do is use a FileRead to read the parts file line by line. If you consider each line a 'row' of a database, then you can multiple WordFind functions (also in the appendix of the NSIS help) to break each row into a list of 'fields'. Field #1 would be your part number. (Use $/t as your delimiter.)

If you wanted to store the results in a variable, you could use WordReplace to replace the tabs ($\t) with carriage returns ($\r$\n). Then, just display the results in a message box. (Or in a custom page. but, in a custom page, you'd need to use \r\n instead)

If you needed to store multiple results, you may need to use the stack or write the output to a file for retrieval later.

(Hope this makes sense.)


Name "Output"
OutFile "Output.exe"

!include "TextFunc.nsh"
!insertmacro LineFind
!insertmacro TrimNewLines

!include "WordFunc.nsh"
!insertmacro WordFind

Var FINDIT_PARTNUMBER
Var PARTNUMBER
Var DESCRIPTION
Var PRICE

Section
StrCpy $FINDIT_PARTNUMBER '123456'

${LineFind} "C:\a.log" "/NUL" "1:-1" "LineFindCallback"

IfErrors 0 +2
MessageBox MB_OK "Error"
MessageBox MB_OK '$$PARTNUMBER={$PARTNUMBER}$\n$$DESCRIPTION={$DESCRIPTION}$\n$$PRICE={$PRICE}'
SectionEnd

Function LineFindCallback
${TrimNewLines} '$R9' $R9
${WordFind} '$R9' '$\t' "+1" $1
StrCmp $1 $FINDIT_PARTNUMBER 0 end

StrCpy $PARTNUMBER $1
${WordFind} '$R9' '$\t' "+2" $DESCRIPTION
${WordFind} '$R9' '$\t' "+3" $PRICE
StrCpy $0 StopLineFind

end:
Push $0
FunctionEnd