Board Logo
« Running JB from NotePad++ »

Welcome Guest. Please Login or Register.
Jan 18th, 2018, 3:39pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Problems installing JB? Read the Vista/Win7 Installation FAQ

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Running JB from NotePad++  (Read 201 times)
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Running JB from NotePad++
« Thread started on: Jun 23rd, 2017, 4:05pm »

Answering this question of tooanalytical
Quote:
Now I am curious. Could I find and install a programming editor, and then would I setup the editor so that Just BASIC will run in it? Then the editor will let me create a program and run a program written in JB, FROM THE EXTERNAL EDITOR?

(Setting Up External Programs , Reply#15)

So.
While JB has no command line switch to run program on load (it will load program passed as an argument, but that's all), we can nudge it with SendKeys.

Here setup for Notepad++, using VBSCRIPT.
I tested it on XP and Win7.

0. Make sure you have Reload File on Activate option set in JB
1. Get yourself Notepad++
2. Check if NppExec plugin is installed in Notepad++
(if not, install)
3. Create a file named "runJB.vbs " in Notepad++ folder (one with "plugins" subfolder).
Here's the code. Make sure you set BasicPath right!
Code:
'to be called with BAS file name (full path)
'set your JB path here
BasicPath="C:\progs\Just BASIC v1.01\jbasic.exe"
'get arg
dim args
Set args = WScript.Arguments
if args.count=0 then 
 	Wscript.Echo "Usage: cscript  runJB.vbs filename.BAS"
 	Wscript.Quit
End If
basFile = args.Item(0)
	'Wscript.Echo progTitle

'enumerate all processes, see if there is one 
'with command line containing "jbasic.exe" and file name pased
dim Processes
Set Processes = GetObject("winmgmts:").InstancesOf("Win32_Process")

procFound = 0
For Each Process In Processes
	if instr(Process.CommandLine, "jbasic.exe")<>0 and instr(Process.CommandLine, basFile)<>0 then	
		procFound=Process.ProcessId
		Wscript.Echo "found", procFound
		Exit For	' We found our process. No more iteration required...
	end if
next

dim sh
set sh = createobject("wscript.shell")
if procFound = 0 then	'run JB by ourselves
	'Wscript.Echo """"+BasicPath+""""+" "+""""+basFile+""""
	Set oExec=sh.Exec(""""+BasicPath+""""+" "+""""+basFile+"""")	
	procFound=oExec.ProcessId
	Wscript.Echo "created", procFound
	wscript.sleep 500	'wait a bit?
end if

'when activate it by ProcessId
 	if sh.appactivate(procFound) then
 		' Wait a little bit (may be optional)...
 		wscript.sleep 100
 		'close splash. If no splash, nothing bad happens
 		sh.sendkeys "{ESC}"
 		wscript.sleep 100
 		'run the program
 		'sh.sendkeys "+{F5}"	'Shift F5 - it doesn't worked for me
 		sh.sendkeys "%r"	'Alt-r
 		sh.sendkeys "~"		'Enter
 	end if			
'Wscript.Quit

set sh = nothing
Set Processes = nothing
Set args = nothing 

4. Load any BAS file in Notepad++ (btw, drag'n'drop works)
5. Select from menu
Prugins \ NppExec \ Execute
(or just press F6)
6. Enter these lines
Code:
npp_save
cscript runJB.vbs "$(FULL_CURRENT_PATH)" 

First line saves current file, second calls VBS file you just created passing it file name.
7. Press OK
(once set up, you can just press Ctrl-F6 to run these commands)

What it supposed to do:
* checks if you passed a parameter. It assumes it is file name.
* enumerate all processes, see if there is one
' with command line containing "jbasic.exe" and file name pased
* if not, starts JB passing to it file name
* makes JB window active with appactivate
* use SendKeys to pass it ESC (to close splash screen if any)
* use SendKeys to pass it Alt-R, Enter for Run menu
So if you have JB with your program open, it activates it and runs that program
If not - it starts new JB, closes splash screen and runs the program.

As I said I tested it on XP and Win7
Sometimes then JB window created, it does not close splash/run program. Probably timing issue (there is "wscript.sleep 500" for that). If you just switch to Notepad++ leaving JB open, it will not need to create new JB next time you press Ctrl-F6.

Just found. You know you can close visible JB IDE and still have process in memory? Program will try to activate this invisible program.
So if setup worked but suddenly stopped, that might be invisible JB hanging in background. You have to kill it (with Task Manager of something. I always have Process Explorer running).

Last thing.
I do not know/practice/use VBScript - it's all Googling and Trial-and-error.
But it works for me ;)
« Last Edit: Jun 23rd, 2017, 4:11pm by tsh73 » User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Re: Running JB from NotePad++
« Reply #1 on: Jun 30th, 2017, 09:56am »

Just set it up on my second machine
Had to write full path to script
(in my case,
Code:
npp_save
cscript C:\progs\Notepad++Portable\App\Notepad++\runJB.vbs "$(FULL_CURRENT_PATH)"  

)

And this version of plugin had not Ctrl-F6 shortcut - had to press Code:
F6 
Enter 

(not really big deal)
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls