|
Post by xxgeek on Sept 29, 2023 12:18:00 GMT
idecode$() - This function returns the code in the Just BASIC editor as a single string. Once you have this you can read the code and parse it, generate other code from it, format it, print it, etc.
idefilename$() - This function returns the full path and filename of the file that is being edited in the Just BASIC editor.
Neither of these functions work in JB as stated in the help file.(ONLY work in LB) I'd like to use idefilename$() with one of my JB programs. So how would one go about getting the file name of the file in the IDE?
Any ideas? Has it already been posted?
|
|
|
Post by tsh73 on Sept 29, 2023 14:00:59 GMT
I think I have code somewhere that reads from justbasic2.ini It has recent file list If you saved file, it got written there
|
|
|
Post by xxgeek on Sept 29, 2023 15:00:51 GMT
Thanks for the quick reply Anatoly.
I've been working that angle and came up with code to retrieve it, but can I be certain that everyone who tries the code will get the same result? It will depend on how many files have been saved previous to running this code, would it not?
Will the line I need always be line # 35 (I doubt it) maybe for me since my file list will always be full to max # of entries, but another users list may not be up to max.
Is there a way to guarantee I get the correct filename/path somehow?
Does the code below give YOU the correct file/path of the current file in YOUR IDE. (assuming you have saved the file, and you have provided YOUR path to the ini file)
global upath$ call getUserPath x =1 open upath$;"\AppData\Roaming\Just Basic v2.0\justbasic2.ini" for input as #1 while x < 36 line input #1, code$ if x = 35 then print code$ x =x+1 wend close #1 end
sub getUserPath run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE do scan loop until fileExists(DefaultDir$, "UserHomePath.txt") open "UserHomePath.txt" for input as #1 upath$ = input$(#1, lof(#1)) close #1 if upath$ = "" then notice "Sorry, can't find user path " : end 'kill DefaultDir$;"\UserHomePath.txt" upath$=trim$(upath$) end sub
'function for checking file existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by tsh73 on Sept 29, 2023 19:54:02 GMT
Wow wow. So much questions.
It's a programming. You do your best, but you cannot guarantee
Not really a problem - there is a number, see?
7 recent files
It depends on external programs in INI file I quite often (have no idea why) get my INI rewritten anew - no external programs at all!
You can at least check if file exist
No, because as of now I had 2 external programs (and yesterday I had none)
|
|
|
Post by tsh73 on Sept 29, 2023 20:01:47 GMT
Now Actually I had that sorted for a while (but with hardcoded paths and under JB 1.01)
Here I update it to JB 2.0 still hardcoded paths, you can put yours/improve and use getUserPath I tested and it works for me. (actually quite surprised it worked in JB 2.0 just as it did in JB 1.01. I had bad experience with JB command line.) (but here I am under WinXP 32 bit, use your paths)
So I update justbasic2.ini file, add external programs !! Do backup it first. I managed to mess it up, (it put last files inside my program list, likes from INI went to menu Recent files) So I had to delete it, so JB created fresh one !! Also, this must be done with JB NOT RUNNING
2 externals runLast Notepad++ "C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Program Files\Just BASIC v2.0\runLast.tkn" "C:\Program Files\Notepad++\notepad++.exe" runLast "C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Program Files\Just BASIC v2.0\runLast.tkn"
I compile this program to "runLast.tkn"
'compile to TKN 'run from RUN menu with path-to-exe '2 externals 'runLast Notepad++ '"C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Program Files\Just BASIC v2.0\runLast.tkn" "C:\Program Files\Notepad++\notepad++.exe" 'runLast '"C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Program Files\Just BASIC v2.0\runLast.tkn" ' '1) get LastFileName$ nomainwin open "justbasic2.ini" for input as #1 while not(eof(#1)) line input #1, aLine$ if word$(aLine$, 2) = "recent" and word$(aLine$, 3) = "files" then nFiles = val(word$(aLine$, 1) ) exit while end if wend if not(nFiles) then close #1 notice "ERROR: (Recent files) block Not found" end end if for i = 1 to nFiles line input #1, aLine$ next print "Last file is" print aLine$ LastFileName$=aLine$ close #1 '2) get command line qq$=chr$(34) if CommandLine$<>"" then 'notice "cmd line"+chr$(13)+CommandLine$ run CommandLine$+" "+qq$+LastFileName$+qq$ else prompt "Last file name is ";LastFileName$ end if
end
Now it has 2 external programs runLast runLast Notepad++
Running first one shows last line in "recent files" section Running first one opens this file in Notepad++
Now program itself DOES NOT HAS ANY PATHS at all all paths are in justbasic2.ini itself.
|
|
|
Post by tsh73 on Sept 29, 2023 20:58:33 GMT
Just checked it under more modern Windows Part from INI files for setting external programs is here
runLast "C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Users\Anatoly\AppData\Roaming\Just BASIC v2.0\runLast.tkn" runLast Notepad++ "C:\Program Files\Just BASIC v2.0\jbrun2.exe" "C:\Users\Anatoly\AppData\Roaming\Just BASIC v2.0\runLast.tkn" "C:\Program Files\Notepad++\notepad++.exe"
(I swear it changes order of external programs. I put these two near, but it moves "Error log" in between)
code is unchanged, works for me
Just for a record, default lines for externaml programs
FreeForm GUI editor $USERDATAfformj261006.tkn Error log notepad.exe $USERDATAerror.log Obviously $USERDATA expands to
C:\Users\Anatoly\AppData\Roaming\Just BASIC v2.0\ , but I was not able to use it for runLast lines.
|
|
|
Post by xxgeek on Sept 29, 2023 21:48:00 GMT
Good stuff Anatoly. Thanks for going above and beyond to work this out. I forgot about the recent files using a number we could use to get the correct line in the ini file.
Here, when I used CommandLine$ it returned: files (x86) blah blah without the first word and space (Program ) so I reworked the code but with new ideas.
It returns the correct file path and name. Maybe not a guarantee, but a lot better than using line #35 lol I'm just using this to do some experiments.
Thanks again, you rock.
'Get FileName of Current Just Basic IDE Code 'nomainwin q$=chr$(34) call getUserPath uAppData$ = upath$;"\Application Data\Just Basic v2.0" JBini$ = "justbasic2.ini" open uAppData$;"\";JBini$ for input as #1 while not(eof(#1)) line input #1, aLine$ if word$(aLine$, 2) = "recent" and word$(aLine$, 3) = "files" then nFiles = val(word$(aLine$, 1) ) exit while end if wend if not(nFiles) then close #1 notice "ERROR: ";chr$(13);"No Current IDE Code Reference Exists";chr$(13);chr$(13);"Save your code and try again" end end if for i = 1 to nFiles line input #1, aLine$ next print "Full Path of Last Saved File is " print aLine$ LastFileName$=aLine$ close #1 end
sub getUserPath global upath$ run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE do scan loop until fileExists(DefaultDir$, "UserHomePath.txt") open "UserHomePath.txt" for input as #1 upath$ = input$(#1, lof(#1)) close #1 if upath$ = "" then notice "Sorry, can't find user path " : end kill DefaultDir$;"\UserHomePath.txt" upath$=trim$(upath$) end sub
'function for checking file existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|