Page 1 of 1

Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 1:32 am
by matalog
Is it possible, after generating a text file in a program, to get Notepad++ to open the text file for reading?

Re: Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 2:07 am
by Quin
Sure, just use RunProgram() :wink:

Code: Select all

Define Filename$ = "Test.txt"
RunProgram("notepad++", Filename$, "", #PB_Program_Open)

Re: Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 10:18 am
by Marc56us
Don't forget to enter the full path (classic mistake, if Notepad++ is not in the path)

Code: Select all

Define Filename$ = "Test.txt"
RunProgram("C:\Program Files\Notepad++\notepad++.exe", Filename$, "", #PB_Program_Open)
And if Notepad++ is the default text editor associated with .txt, then the document name is sufficient.

Code: Select all

Define Filename$ = "Test.txt"
RunProgram(Filename$, "", "", #PB_Program_Open)

Re: Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 5:55 pm
by matalog
That's brilliant. Thanks. Strangely

Code: Select all

f$=fol+"File Explorer - "+fil+".txt"
Debug f$
RunProgram("C:\Program Files\Notepad++\notepad++.exe",f$,fol,#PB_Program_Open)

tries to open the 4 parts of the string, and not the file address that the entire string points to...

If I use the

Code: Select all

f$=fol+"File Explorer - "+fil+".txt"
Debug f$
RunProgram(f$, "", "", #PB_Program_Open)
method, it opens as default fine.

Re: Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 8:58 pm
by Fips
Might be the space characters
Try

Code: Select all

f$=Chr(34) + fol+"File Explorer - "+fil+".txt" + Chr(34)
Debug f$
RunProgram("C:\Program Files\Notepad++\notepad++.exe",f$,fol,#PB_Program_Open)

Re: Open a generated text file in Notepad++

Posted: Sat Mar 15, 2025 10:06 pm
by AZJIO

Code: Select all

EnableExplicit
#ASSOCSTR_EXECUTABLE = 2
#ASSOCF_VERIFY = $40

Procedure.s AssocExe(Ext$, *Act)
    Protected Size, OutRes.s
    AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, 0, @Size)
    OutRes = Space(Size)
    If AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, @OutRes, @Size)
        OutRes = ""
    EndIf
    ProcedureReturn OutRes
EndProcedure

Define editor$
editor$ = "C:\Program Files\Notepad++\notepad++.exe"

If Not Asc(editor$) Or FileSize(editor$) < 0
	editor$ = AssocExe(".txt", 0)
	If Not Asc(editor$)
		editor$ = "notepad.exe"
	EndIf
EndIf

RunProgram(editor$, #DQUOTE$ + #PB_Compiler_File + #DQUOTE$, "")

Re: Open a generated text file in Notepad++

Posted: Sun Mar 16, 2025 1:32 am
by matalog
Fips wrote: Sat Mar 15, 2025 8:58 pm Might be the space characters
Try

Code: Select all

f$=Chr(34) + fol+"File Explorer - "+fil+".txt" + Chr(34)
Debug f$
RunProgram("C:\Program Files\Notepad++\notepad++.exe",f$,fol,#PB_Program_Open)
Yes, that works, thanks.

Re: Open a generated text file in Notepad++

Posted: Sun Mar 16, 2025 1:35 am
by matalog
AZJIO wrote: Sat Mar 15, 2025 10:06 pm

Code: Select all

EnableExplicit
#ASSOCSTR_EXECUTABLE = 2
#ASSOCF_VERIFY = $40

Procedure.s AssocExe(Ext$, *Act)
    Protected Size, OutRes.s
    AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, 0, @Size)
    OutRes = Space(Size)
    If AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, @OutRes, @Size)
        OutRes = ""
    EndIf
    ProcedureReturn OutRes
EndProcedure

Define editor$
editor$ = "C:\Program Files\Notepad++\notepad++.exe"

If Not Asc(editor$) Or FileSize(editor$) < 0
	editor$ = AssocExe(".txt", 0)
	If Not Asc(editor$)
		editor$ = "notepad.exe"
	EndIf
EndIf

RunProgram(editor$, #DQUOTE$ + #PB_Compiler_File + #DQUOTE$, "")
I'm not sure I understand any of this, but why wouldn't I like a Quine?!

This a Quine isn't it?

Re: Open a generated text file in Notepad++

Posted: Sun Mar 16, 2025 7:57 am
by DarkDragon
matalog wrote: Sun Mar 16, 2025 1:35 am
AZJIO wrote: Sat Mar 15, 2025 10:06 pm

Code: Select all

EnableExplicit
#ASSOCSTR_EXECUTABLE = 2
#ASSOCF_VERIFY = $40

Procedure.s AssocExe(Ext$, *Act)
    Protected Size, OutRes.s
    AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, 0, @Size)
    OutRes = Space(Size)
    If AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, @OutRes, @Size)
        OutRes = ""
    EndIf
    ProcedureReturn OutRes
EndProcedure

Define editor$
editor$ = "C:\Program Files\Notepad++\notepad++.exe"

If Not Asc(editor$) Or FileSize(editor$) < 0
	editor$ = AssocExe(".txt", 0)
	If Not Asc(editor$)
		editor$ = "notepad.exe"
	EndIf
EndIf

RunProgram(editor$, #DQUOTE$ + #PB_Compiler_File + #DQUOTE$, "")
I'm not sure I understand any of this, but why wouldn't I like a Quine?!

This a Quine isn't it?
He had no text file ready, so he used the code itself. Just replace #PB_Compiler_File with your text file.

He checks whether notepad++ exists in it's default installation path, if not he tries to get the user's default text editor and if that doesn't work he uses Microsoft notepad.

Re: Open a generated text file in Notepad++

Posted: Sun Mar 16, 2025 4:44 pm
by Drone
AZJIO wrote: Sat Mar 15, 2025 10:06 pm

Code: Select all

EnableExplicit
#ASSOCSTR_EXECUTABLE = 2
#ASSOCF_VERIFY = $40

Procedure.s AssocExe(Ext$, *Act)
    Protected Size, OutRes.s
    AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, 0, @Size)
    OutRes = Space(Size)
    If AssocQueryString_(#ASSOCF_VERIFY, #ASSOCSTR_EXECUTABLE, @Ext$, *Act, @OutRes, @Size)
        OutRes = ""
    EndIf
    ProcedureReturn OutRes
EndProcedure

Define editor$
editor$ = "C:\Program Files\Notepad++\notepad++.exe"

If Not Asc(editor$) Or FileSize(editor$) < 0
	editor$ = AssocExe(".txt", 0)
	If Not Asc(editor$)
		editor$ = "notepad.exe"
	EndIf
EndIf

RunProgram(editor$, #DQUOTE$ + #PB_Compiler_File + #DQUOTE$, "")
Hi.
Thank you AZJIO for the AssocExe Procedure. I needed to find the default browser... and you made it easy for me. :D
Drone