Open a generated text file in Notepad++

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Open a generated text file in Notepad++

Post by matalog »

Is it possible, after generating a text file in a program, to get Notepad++ to open the text file for reading?
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Open a generated text file in Notepad++

Post by Quin »

Sure, just use RunProgram() :wink:

Code: Select all

Define Filename$ = "Test.txt"
RunProgram("notepad++", Filename$, "", #PB_Program_Open)
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Open a generated text file in Notepad++

Post 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)
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Open a generated text file in Notepad++

Post 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.
Fips
User
User
Posts: 35
Joined: Sun Feb 20, 2022 1:03 pm

Re: Open a generated text file in Notepad++

Post 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)
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: Open a generated text file in Notepad++

Post 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$, "")
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Open a generated text file in Notepad++

Post 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.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Open a generated text file in Notepad++

Post 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?
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Open a generated text file in Notepad++

Post 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.
bye,
Daniel
Drone
New User
New User
Posts: 7
Joined: Fri May 03, 2019 10:21 pm

Re: Open a generated text file in Notepad++

Post 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
Post Reply