Liberty BASIC Community Forum
« Carl Gundel - New idecode$() Function »

Welcome Guest. Please Login or Register.
Nov 17th, 2017, 10:36pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Carl Gundel - New idecode$() Function  (Read 658 times)
Brandon Parker
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 1118
xx Carl Gundel - New idecode$() Function
« Thread started on: May 1st, 2017, 1:52pm »

Carl,
When you get a chance can you elaborate on the idecode$() function that you mentioned in this thread?

I'm very curious about how you have this implemented as I built a utility; my Import Architect as I like to call it which does something similar by looking for the LB IDE and then giving the user the option of which one to select from if many are open. Once a selection is made it goes through the code in that file and processes a new looking for a various "Non-LB" commands. This is how I was able to implement Dynamic Arrays, User Types, Macros, and Enumerations.

Just curious how the LB function works; maybe I will rewrite my utility.


{:0)

Brandon
« Last Edit: May 2nd, 2017, 9:41pm by Brandon Parker » User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
xx Re: Carl Gundel - New codeide$() Function
« Reply #1 on: May 1st, 2017, 2:16pm »

Yes, it is a very interesting function.
User IP Logged

cundo
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New codeide$() Function
« Reply #2 on: May 2nd, 2017, 08:12am »

The idea is that you can grab the code in the editor as a string. Then you do whatever you like with it such as format it, print it or parse it and generate something else from it. The intention is to use this to create utilities that you add to the external programs under the Run menu. See the Setup menu for the external programs feature.

You can't stick it back into the editor when you're done, but you can write it to a file or open it in another window if you like.

If you try to use the codeide$() function with runtime engine it will only give you an empty string because there is no IDE to grab code from when running a packaged application. ;-)

-Carl
« Last Edit: May 2nd, 2017, 08:14am by CarlGundel » User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Brandon Parker
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 1118
xx Re: Carl Gundel - New codeide$() Function
« Reply #3 on: May 2nd, 2017, 11:19am »

Ok.....

What if the user has more than one IDE open? Does the function return the code only associated with the IDE session that launched the program in which it resides?

I presume this is the type of utility that you had in mind that people might create....

Here are screenshots of my Import Architect in action.


Import Architect - IDE Selection
User Image

Import Architect - Build Events
User Image


{:0)

Brandon
User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New codeide$() Function
« Reply #4 on: May 2nd, 2017, 12:41pm »

on May 2nd, 2017, 11:19am, Brandon Parker wrote:
Ok.....

What if the user has more than one IDE open? Does the function return the code only associated with the IDE session that launched the program in which it resides?

I presume this is the type of utility that you had in mind that people might create....

It only gets the source code from the environment in which it is used.

Hmmm, I think that I will probably also need to add a function to get the filename from the IDE also.

The utilities are limited only by your imagination. ;-)

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 30
xx Re: Carl Gundel - New codeide$() Function
« Reply #5 on: May 2nd, 2017, 12:51pm »

Carl

Is this implemented in 4.5.1 beta 3? If so can you give some sample code, When I have tried to use it (guessing the syntax as a$= codeide$()) I just get syntax error.

Brian Matthews
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New codeide$() Function
« Reply #6 on: May 2nd, 2017, 12:58pm »

Oops. The function is called idecode$(). My bad.

-Carl

on May 2nd, 2017, 12:51pm, BrianM wrote:
Carl

Is this implemented in 4.5.1 beta 3? If so can you give some sample code, When I have tried to use it (guessing the syntax as a$= codeide$()) I just get syntax error.

Brian Matthews
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 30
xx Re: Carl Gundel - New idecode$() Function
« Reply #7 on: May 2nd, 2017, 1:05pm »

Carl
It is now working. Thanks.

Brian Matthews
User IP Logged

BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 30
xx Re: Carl Gundel - New idecode$() Function
« Reply #8 on: May 2nd, 2017, 6:28pm »

Carl

I have modified my code indenter to use the idecode$() function and it works well. The only problem is that the clipboard is limited in size so that a very large file (e.g. freeform) cannot be put back into the ide using cut and paste.

How about a function to return the full pathname of the file being edited in the IDE.

Brian
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New idecode$() Function
« Reply #9 on: May 3rd, 2017, 08:05am »

Hey Brian,

LOL. I already mentioned that idea in a prior post. ;-)

Done already in beta 4 (not ready for testing). idefilename$()

-Carl

on May 2nd, 2017, 6:28pm, BrianM wrote:
Carl

I have modified my code indenter to use the idecode$() function and it works well. The only problem is that the clipboard is limited in size so that a very large file (e.g. freeform) cannot be put back into the ide using cut and paste.

How about a function to return the full pathname of the file being edited in the IDE.

Brian
« Last Edit: May 3rd, 2017, 08:06am by CarlGundel » User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Brandon Parker
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 1118
xx Re: Carl Gundel - New idecode$() Function
« Reply #10 on: May 3rd, 2017, 08:30am »

Carl,
In the event that someone called either of these functions can you invoke the IDE "Save" routine prior to returning to the user. That way what they get from the IDE is what is actually at the file location. Wouldn't want to miss a change made two seconds prior to calling the new functions.

{:0)

Brandon
User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New idecode$() Function
« Reply #11 on: May 3rd, 2017, 08:38am »

Hmm. The functions only return values. They make no promises about what it saved in the file system, and I'm not sure they should.

Get the contents of the IDE code editor.
Transform those contents by reformatting them or by creating a report or other.
Use the idefilename$() function to save the new formatted contents either on top of the original or a new file name such as myprog-formatted.bas

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
alincon2001
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 494
xx Re: Carl Gundel - New idecode$() Function
« Reply #12 on: May 3rd, 2017, 10:09am »

Do I have it correct that idecode$() returns one long string, or is it like a text file that can be read line by line?
It would be handy if the later (or both) was true.

r.m.
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Carl Gundel - New idecode$() Function
« Reply #13 on: May 3rd, 2017, 10:18am »

on May 3rd, 2017, 10:09am, alincon2001 wrote:
Do I have it correct that idecode$() returns one long string, or is it like a text file that can be read line by line?
It would be handy if the later (or both) was true.
r.m.

You make a good point. It's a string. If you want it as a file it's easy to write the string to a temp file and then open it and read it as a file. ;-)

-Carl
« Last Edit: May 3rd, 2017, 10:18am by CarlGundel » User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Carl Gundel - New idecode$() Function
« Reply #14 on: May 5th, 2017, 02:57am »

One of our JB coders found a use for idecode$() cool,

Code:
'Donut with Sprinkles.txt for JB [B+=MGA]
'translated from SmallBASIC 2017-05-04
'++++++++++++++++++++++++++++++++++++++++++
global H$, XMAX, YMAX, pi
H$ = "#gr"
XMAX = 780
YMAX = 740
pi = acs(-1)
nomainwin

WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200 - XMAX) / 2
UpperLeftY = (700 - YMAX) / 2

open "Donut with Sprinkles of Colored Code" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "font dejavu_sans_mono 7 15"
#gr "down"
#gr "fill black"

cx = XMAX/2
cy = YMAX/2
tw = 7
th = 15


f$=idecode$()
lenF = len(f$)
tArea = tw * th * lenF / 1.8
r = sqr(9/4 * tArea/pi)
#gr "size 16"
for y = 0 to YMAX step 8
scan
  for x = 0 to XMAX step 8
  scan
    d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
    if r/3 < d  and d  < r then
      call midInk 180, 90, 55, 50, 25, 12, 1 - abs(2/3*r - d)/(.335*r), 0
      #gr "set ";x;" ";y-3
    end if
  next
next
idx = 0
for y = 0 to YMAX step th
  for x = 0 to XMAX step tw
    d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
    if r/3 + 10 < d and d < r- 10 then
      idx = idx + 1
      call midInk 180, 90, 55, 50, 25, 12, abs(2/3*r - d)/(.335*r), 1
      if idx <= lenF then
        call at x, y, mid$(f$, idx, 1)
      else
        if idx mod 2 then call at x, y, "O" else call at x, y, "X"
      end if
    end if
  next
next
#gr "flush"
wait
'++++++++++++++++++++++++++++++++
function rand(lo, hi)
    rand = int((hi - lo + 1) * rnd(0)) + lo
end function

sub midInk r1, g1, b1, r2, g2, b2, frac, tf
    if tf then
        #H$ "color ";rand(60, 255);" ";rand(60, 255);" ";rand(60, 255)
    else
        dr = (r2 - r1) * (1-frac) : dg = (g2 - g1) * (1-frac) : db = (b2 - b1) * (1-frac)
        #H$ "color ";r1 + dr;" ";g1 + dg;" ";b1 + db
    end if
    dr = (r2 - r1) * frac : dg = (g2 - g1) * frac : db = (b2 - b1) * frac
    #H$ "backcolor ";r1 + dr;" ";g1 + dg;" ";b1 + db
end sub

sub at xPix, yPix, char$ 
    #gr "place ";xPix;" ";yPix
    #gr "|";char$ 
end sub

sub quit H$
    close #H$
    end
end sub
'===================



 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

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