Page 1 of 1

I'm feeling lucky

Posted: Tue Oct 16, 2012 6:09 am
by hcandersen
A commandline option to Textpad that create a "search in files" and automaticly opens up the first match.


I have a flowchart of all my functions in another program and it's possible for me to execute a program from each of my squares in the flowchart.

By having a function like this I will be able to use my flowchart to navigate to my functions and subfunctions.

Posted: Thu Oct 18, 2012 9:38 am
by hcandersen
I made my self a workaround.

I saved the search result from a number of keyword searches to a file and then created a a VB script that takes a keyword as argument.

The script the searches the search-result-text-file and finds the file and row for my function/keyword and starts Textpad with them as argument.

I will need to update the search result file every now and then to get Textpad to find the exact starting position.

Posted: Thu Oct 18, 2012 9:54 am
by hcandersen
Here is the code if anyone else is interested.

Paste the text below in Notepad and save it as FindTextPadKeyword.vbs
Change the value for TargetFileLocation and TextPadExe
Do a Search in files from Textpad with the "In folder"-field set to same value as TargetFileLocation and save it as Search Results.txt in same place as the vbs-file (not on TargetFileLocation)

Good luck
Henrik Andersen
www.cadcraft.se

' ==== VB Script File - Start =====
Dim Wshshell: Set WSHShell = WScript.CreateObject( "WScript.Shell" )
Dim Fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim Scriptpath: Scriptpath = fso.GetParentFolderName(WScript.ScriptFullName)
Dim WshSysEnv : Set WshSysEnv = WshShell.Environment("PROCESS")


Dim NoInstallMode: NoInstallMode = "NO"

Dim objArgs : set objArgs = Wscript.Arguments

TargetFileLocation = "C:\CAD\Cad_Anpassningar\seKonfigurator_2013"
TextPadExe = WshSysEnv("ProgramFiles(x86)") & "\Helios\TextPad4\TextPad.exe"
TextPadExe = "C:\_Runware\Text_Util\TextPad4\TextPad.exe"


If objArgs.Count = 0 Then
msgbox "No Argumets Attached"
else

for i = 0 to objArgs.Count -1
CmdLineArgs = CmdLineArgs & objArgs(i) & " "
next


End if
IF CmdLineArgs = "" THEN
strKeyWordname = inputbox ("Enter KeyWord", "","(defun ")
ELSE
strKeyWordname = inputbox ("Enter KeyWord", "", CmdLineArgs)

END IF

sFile = scriptpath & "\Search Results.txt"
Set oFile = FSO.GetFile(sFile)
If oFile.Size > 0 Then
Set oReadFile = FSO.OpenTextFile(sFile, 1)
Do While Not oReadFile.AtEndOfStream and FoundMatch = False
sText = oReadFile.ReadLine
if instr(1,sText, strKeyWordName,1) > 0 then
'msgbox "Found KeyWord" & sText

If Trim(sText) <> "" Then
startbracket = instr(sText, "(")
if startbracket > 0 then
endbracket = instr(startbracket + 1, sText, ")")
if endbracket>0 then
strTargetFile = mid(sText, 1, Startbracket-1)

strTextPos = mid(sText, Startbracket+1, Endbracket-Startbracket-1)

FoundMatch = True
End if


end if
End if
End if

Loop
oReadFile.close
if strTargetFile <> "" then
wshshell.run chr(34) & TextpadExe & chr(34) & " " & chr(34) & TargetFileLocation & "\" & strTargetFile & "(" & strTextPos & ",0)" ,1,false
else
msgbox "Failed to find keyword:" & CmdLineArgs & vblf & "in Search Result.txt"
End if

End if

' ==== VB Script File - End =====