News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Compile and Run PlayBASIC GUI Project

Started by kevin, July 18, 2024, 11:35:53 AM

Previous topic - Next topic

kevin

Compile and Run PlayBASIC GUI Project

  This example source code loads a PlayBASIC project file, parses the xml then loads the source code(s) and passes it to the PlayBASIC compiler. 


Welcome to today's PlayBasic tutorial! This video is perfect for beginner programmers who want to understand a simple yet powerful program written in PlayBasic. This program allows you to load, compile, and run other PlayBasic projects using the PlayBasic compiler.

Here's a quick rundown:

-  The program has a basic load option to pick a PlayBasic project file, compile it, and run it.
-  It handles potential issues like loading full-screen exclusive mode projects.
-  The process involves loading the project file, merging source files, creating a temporary compiler project, and handling any compilation errors.
-  The interface includes a simple menu to navigate and select different projects.
-  It uses Windows API calls to monitor and manage the compilation process.
-  Error handling is implemented to ensure smooth operation even when multiple instances are running.

By following this video, you'll gain insight into managing PlayBASIC projects and using the PlayBASIC  compiler effectively. Happy coding!


   



Related Source Code Links

  - PlayBASIC (CLASSIC) Project Loader / Source Merger Functions

  - Simple Text Menu

  - Syntax Highlight PlayBASIC source code as HTML



Download Source Code

    Attached bellow !

stevmjon

It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

stevmjon

i looked at this code, but the running of the compiler is a bit technical as your using the kernel32.dll which i am not familiar with using.

if i already have the compile.project & compile.source files, can i use the PB command ExeFile filename$, parameter$ to launch the compiler and pass the parameter path?

i have tried using ExeFile but can't get it to run, but i can get the edit shortcut trick to work no problems.

   thanks for any advice, stevmjon


 
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

  Exefile is really a simplified version of the above so is fussy.  But to call the compiler all you need the location of the compiler and locate of the project file.  Then the caller needs set the current path to that of the project that's about to run.  Since when that program starts it'll be looking for any files it needs in the projects folder. 

  See attachment for a working example.

PlayBASIC Code: [Select]
; PROJECT : Run Compiler From ExeFile In PlayBASIC
; AUTHOR : Kevin Picone - https://playbasic.com
; CREATED : 12/08/2024
; EDITED : 12/08/2024
; ---------------------------------------------------------------------


old_Path$=currentdir$()

// Get compiler location from running compiler
compiler$ =programdir$()+"PlayBASIC.exe"
if fileexist(Compiler$)

Path_of_Project$ = old_Path$+"Example\"

if folderexist(Path_of_Project$)

Parmeters$=Path_Of_Project$+"temp.project"

print Compiler$
print Path_Of_Project$
print Parmeters$

cd path_of_Project$
exefile compiler$,chr$(34)+Parmeters$+chr$(34)
endif

endif
cd old_path$

print "Press To Quit"
sync
waitkey







Download

  Full Example bellow

stevmjon

thanks for the demo kev.

for some reason the demo won't launch the ExeFile PlayBasic.exe (compiler) or open the temp.project?

not sure if it is settings on my computer or anti-virus. i am running win10. i am not getting any messages though.
but the edit shortcut trick works fine, and if i manually click PlayBasic.exe it opens asking for a file.
so i assume it is not blocked.

any idea's?

   thanks stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


Quotethe demo won't launch the ExeFile PlayBasic.exe (compiler) or open the temp.project?

   So the compiler opens ?  If not, the code above 'guesses' where PlayBASIC.exe is.  That's unlikely to work by cut'paste as the IDE will set a temp (unsaved project) to the windows temp folder.   Try the attachment   

   Ultimately, you'd a supply the absolute path of the file being started.

stevmjon

#6
i did some experimenting, it seems the compiler isn't opening.

i downloaded the attachment example file and ran it, but it just displays the file names, which are all correct, but it won't open the compiler itself.

> ExeFile compiler$,Chr$(34)+Parmeters$+Chr$(34)

> ExeFile compiler$,""

> ExeFile "C:\Program Files (x86)\PlayBASIC V165C2B\PlayBASIC.exe",""

> ExeFile "C:\Program Files (x86)\PlayBASIC V165C2B\PlayBASIC.exe" , "D:\PlayBasic\Projects\New\2024-08-12 - Run Compiler Using ExeFile Example\2024-08-12 - Run Compiler Using ExeFile Example\Example/temp.project"

none of these worked. so i assume that means the compiler is not opening. the second & third command line above should have at least opened the compiler and then asked for a file to choose to open.

it's funny how the attachment in post #1 works fine, it is just the ExeFile command attachment in post #3 that is struggling. but it opens notepad and loads a file into it no problems???

thinking about it, maybe because the IDE is running, and PlayBASIC.exe is already executed once, maybe this is why it won't let me open another instance of PlayBASIC.exe??? could there be an IDE setting maybe? i am just confused...
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

 
  Here's a version using the ShellExecute function from Win32, which fro memory is what ExeFile is using anyway.  This version returns an error code that you can google

stevmjon

#8
version V002 in post #7 above worked fine, and opened the demo with the particles.

Print hinstance = 42
Print ErrorFlag = 0

it seems just the command ExeFile is not working for me, but everything else is working, lol.

out of interest, how does PlayBASIC.exe know what the current path is? is it saved in a file somewhere as a setting?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

#9
Quote from: stevmjon on August 14, 2024, 06:23:52 PMout of interest, how does PlayBASIC.exe know what the current path is? is it saved in a file somewhere as a setting?

  PlayBASIC doesn't know it, the OS and ultimately the user sets the current path which would be remembered by the OS for each application that's running.    When PlayBASIC launches from PlayWRITE, the IDE sets the current path (CD), so that of the current projects folder so that's considered the local path and files can be found easily. 

  Ie.  LoadImage "Sprite.bmp", 100 

  If the IDE didn't CD the project folder, when the LoadImage function was executed it attempt to load the file from whatever the current path is set to. 

  In the ShellExecute example that function takes a execute path argument,  so it can just be set that way.  Saving  going Cd Path$ :  ShellExecute Program$,Parameters$