Share My Creation Device Basic language IDE

JesseW

Active Member
Licensed User
Longtime User
Andrew, would it be possible for Dim Type indexer variables to be local to the array to which they are dimensioned, like local vars are local to their respective subs? This would open the possibility for b4a constants like color, file and dialogresponse for example, to be arrays instead of b4a subs and accessed using the exact same syntax as b4a without encroaching on other like named vars. So for example

B4X:
dim type(black, white, orange, yellow) color
array(color, 0, -1, ..., ...)
# var white is different than indexer white
white = "white"
# indexer white still works with color
settextcolor("myview", color.white)

I was thinking about creating an include file with all the b4a system constants and realized in doing so was going to use up a bunch of common variable names.

Thanks
 

agraham

Expert
Licensed User
Longtime User
I'm afraid not. The architecture of the language dictates that indexer variables must be standard variables. The reason for this is that when a variable is encountered a method is called to get that variable. If that method finds the variable is terminated by a "." then it recursively calls itself to get the value of whatever follows the dot which therefore has to be a standard variable or a constant. Interestingly as a side effect of this "." indexers can actually be chained - if your brain can cope with it!
 

JesseW

Active Member
Licensed User
Longtime User
Chaining Indexers? sounds intriguing. Would you elaborate?

I have a situation where I build a grid from panels of labels on a scrollview and need to tear the whole thing down and redraw it again. Currently, I prompt the user to rotate the device to cause an activity_create, and that works, but can you think of a more elegant solution?
 

JesseW

Active Member
Licensed User
Longtime User
Yes, but they're generated dynamicly based on the view of the grid chosen by the user. I was considering the consequences of removing a panel, then trying to remove one of its child labels and it dawned on me there is still a reference in the viewmap. I will consider this option more thoroughly.

I have written a RemoveAllViews sub that removes the last indexed element until view map is empty. Ate there any pitfalls to watch out for?

thanks again
 

JesseW

Active Member
Licensed User
Longtime User
PS. I like the indexer chaining. That will save me code and reduce complexity in the future kudos!
 

JesseW

Active Member
Licensed User
Longtime User
it seems to have worked perfectly Thx for your indulgence and assistance
 

walterf25

Expert
Licensed User
Longtime User
Error while trying to run

Hi guys, i was trying to run this code but i got this error, does anybody have any idea what this means, or how to get around this error?

Compiling code. Error
Error compiling program.
Error description: Property: StackDepth is readonly.
Occurred on line: 67
Blib.StackDepth = 15
Word: =

this error is in the Script Module by the way, any tips will be greatly appreciated.

thanks,
Walter
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, if you can spare a moment please...

I came to realize that my Chain and Run statements using a third activity weren't working correctly with large scripts.

So I removed the third activity and rewrote parts of script.bas to do everything itself. In a nutshell, the Chain statement loads the new script into a string called ChainProgram and sets the Args() array, then calls Blib.Halt, which (I am assuming) shuts down the current script and calls Blib_Ended, which, if it finds anything in ChainProgram, starts a new timer called tmrChain for 1/10th of a second, just enough time for Blib_Ended to exit, instead of executing Activity.Finish. In tmrChain_Tick, ChainProgram is copied to Program and then set to "", the first run flag is set to true, and Blib.Run is executed.

This all seems to work very well using the same large script of 1000+ lines that the previous attempt did not work on. I'm running this by you before I go any further, in case I've done something wrong, or you have some suggestions for me.

Thank you very much
Jesse
 

Attachments

  • B4Script_test.zip
    76.6 KB · Views: 294

JesseW

Active Member
Licensed User
Longtime User

Andrew, I realize its asking a lot, but would you be willing to remove the dependencies to script.bas from the library, and code your original android statements via addsyscalls? This would give me great flexability in my b4script project, and relieve it from the burden of future updates because my script.bas is modified quite a bit.

thanks again for all your help
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I'll consider this in a few days time when the present spell of glorious weather ends and the rain returns so we can no longer get into the garden again. Everything is growing like crazy at the moment so we need to keep on top of the weeds otherwise things run away from us. In our garden (a bit less than 2 acres/0.75 hectares but mostly grass) if we let it get out of control it's a mammoth task to get it back again. "One years seed is seven years of weeds"
 

JesseW

Active Member
Licensed User
Longtime User
cool! thanks for the consideration and bravo on the garden!

and while I am thinking about it, have you checked out AIDE on the market? this is hot!!

jesse
 

JesseW

Active Member
Licensed User
Longtime User
hi Andrew. I trust the gardening is going, or went, well. my wife and I have spent a few weekends as well prettying up the place

while you are considering, or working on, pulling the strings of script.has out of the library, I wanted to share an idea I have. since you've graciously allowed the use of the _ char as the leading char in a var name, would it be much additional effort to hav those _variables be like process globals, and store their values in a b4a map, accessed by the varname? this would augment set/getsaveddata. I realize in basiclibide, there would be no use for them, but in my b4scripr project, they'd come in very, very handy. the b4s project I'm working on now is becoming quite complex, and it'd be so nice to be able to create certain vars once for all scripts to share without having to bundle and unbundle them along with any other passed/saved values in the saveddata commands.

on that note, I've been planning to add map accessibility for some time now. one approach, although not as clean and elegant as the method I described above, would be to create 3 new statements: setappvar(varname, value) to init/set a process global, isappvar(varname) to tell if one has been init'd, and appvar(varname) to retrieve a value. appvar values would be stored in a b4a map. alas, the preferred method would be the lib itself handling the _variables, but I could make this work if the preferred way isn't in the near future.

you're the man, Andrew. this wouldn't be possible without your kindness. thanks so much for it all :sign0188:
 

agraham

Expert
Licensed User
Longtime User
it'd be so nice to be able to create certain vars once for all scripts to share without having to bundle and unbundle them along with any other passed/saved values in the saveddata commands.
You could use ShareArray to do this and access the individual elements as named variables using the dot syntax.
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
HOT DAMN!!!!! ANDREW!!! I'm so excited!!!

I was able to get true system wide global (process global) vars and arrays working, that are declared once and then remember their values from script to script and through pausing and resuming. I have two new functions, GlobalVar(name) and GlobalArray(name) that setup two maps that contain the variable/array names as keys and their contents as values. And it works :sign0060: I'm not sure about the names, as the term 'global' actually refers to any variable accessed in the main code section. SysVar(name) and SysArray(name)??? Any ideas?

This project is really starting to shape up! I really need to get a donation your way, if it pleases you.

What would the chances be of creating two new events, Blib_SubStarting and Blib_SubEnding? Then I could use the same techniques to code truly static (as in vb6 static) local var's that retain their value from call to call...

Man, I'm on fire! I'm so glad to be a part of this :sign0188:
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…