I will not say it's buggy or broken but actually Powerbasic (and a few other basic languages probably too) accepts negative values for Left$ or Right$ -
and i was certain thinbasic would work this way too.
Anyway i try to avoid LEFT$ and RIGHT$ the standard way, in thinbasic i prefer LENF, LEFTF$ and RIGHTF$. For module production i created myself some macros and macro-functions that will avoid the unnescessary creation of local strings and these work as powerbasic Left$ and Right$
MACRO StrLen(p1)=PEEK(DWORD, STRPTR(p1)-4)
MACRO StrLeft(p1,x)=IIF$(x=0, "", IIF$(StrLen(p1)<ABS(x), p1, PEEK$(STRPTR(p1), IIF(x > 0, x, StrLen(p1)+x))))
MACRO StrRight(p1,x)=IIF$(x=0, "", IIF$(StrLen(p1)<ABS(x), p1, PEEK$(STRPTR(p1)+ IIF(x > 0, StrLen(p1)-x, ABS(x)), IIF( x > 0, x, StrLen(p1)+x))))
MACRO FUNCTION InLimits(p1,p2,p3)=IIF((p1<p2) OR (p1>p3),0,-1)
' alike thinbasic- keyword between
When using StrRight(s, -1) it works is as Right$(S, Len(s) + (-1))
string s = "thinBasic"
MsgBox StrRIGHT(s, -5) & $CRLF & Strleft(s, -4)
output would be:
thin
Basic
Btw. Function
data = Choose and Choose$(Index, firstVal, secondVal, thirdVal,...,ELSE lastVal )
works in PB with an ELSE for a final choice that will be used if no matching element for index.
I would appreciate if thinbasic had it too.
I have some idea that could reduce Select Case-crimes & times and also provide a feeling of "i am in control".
Imagine to make use of Enum (and Bits if developed ) and apply a node where to store and to bring up some new kind of conditional selective code-block execution that will work using only such values that are present as clearly ordered enumerations or as bitwise flagged status-information. Constants that leave not the slightest doubt about the datatype to use or what kind of test is to perform. It were an approach that would change any kind of these for certain purposes created lists of entitled values ( not to name them "key-value-pairs" ) from their currently static apearance to become objects that allow the programmer to combine the value-lists with required functionalities that are -created once- reuseable within any project.
Enum Bits MyFlags As [Byte|Word|Dword]
flagging bits are keeping track of states, there is no signed type needed for it. Actually when logic ops are performed the presence of negative numbers is irritating while for enumerations it always makes sense to use a signed type even the values below 0 are not in valid range - we can use such values - where we instantly know when we see it: this does not belong here, so it has a special meaning.
To flag just bits - its more simple to use Byte-arrays as Len-Fixed string,When we just set bits by theirs names the bits values are relative. We dont need to know the arithmetic value when all bits have names and we can make the handling easier when we unify all bitflags to be adressed from bit 0 of byte 0 to bit 7 and continue with Byte 1.
Enum Bits MyFlags * <nBytes>
That will not limit bitwise flagging-enumeration to the sizes of the available datatypes. because It were not a real array and we wont use bytes but bits, it were great to have a few features built-in to enums. A few standard methods as
.toString or .List( %Enum_ListMembers | %Enum_ListValue | %Enum_ListFullDetail ) ,
.TypeOf , .SizeOf for Enums and for Bitflags something as enumName.Byte[<byteNumberHi> [To <byteNumberLo>]]. toBin$ | .toHex$
.toConfig/toIni/ (.json?)
.ExportToInclude(): uses the enumerations name for the filename, creates a tBasicI-file probably under App_Path & "thinair\Users\_shared\Inc\Enum"
writes the code to create the enum including all the elements names and values as ready to include-portion of code. thinair should have a few more tabs where codebrowser & explorer are, giving access to "Tools", a local code-archive (for snippets and even such ready-to-include-stuff) to manage the sample-scripts etc.
Many objects( not enums only ) as classes, udts, ... should have like an ExportToInclude-method implemented
And enums that are not bitflags could come with some methods.
Example here a built-in functionality to the enumerations that allows to exeute conditional branches of code by compairing any expression
Enum hungryPet As Long ' the type remains valid for all members and
Cat ' the name "hungryPet" should be recognized as a datatype when it is preceeded
Dog ' by keyword AS, should "hungryPet" alias Long cause a conflict because "hungryPet" is
Pony ' name of a module class i suggest to enforce a naming rule e.g. enum-type-names should be created
Horse ' always the same way. it can be just as placing the char t and an underscore in front of the enumname
GuineaPig ' to retrieve its type-name. such simple approach will bring up trouble soon. "tEnum_" could prevent from it
Elephant ' it would allow function-parameters, declarations and udt-elements to
Lizard ' explicit use a certain type and have an exact defined range of valid parameters.
End Enum
' this were the function/method, built in to all enumerations.
' a simple comparison test. subject to test: <expr>
hungryPet.Test <expr> expr is compared to...
anything the enumeration "knows about" means all its members and theirs values
we know for every member if it matches sExpr,
if member
hungryPet.Result( Cat )
hungryPet.Result( Dog )
hungryPet.Result( Elephant )
hungry.Pet.Result( PONY )
hungryPet.Result( HORSE )
hungryPet.Result( LIZARD )
hungryPet.Result( GUINEA-PIG )
hungryPet.Result( NOTHING )
hungryPet.EndTest
Enum myColorpalette As tRGB '?
Not really.
Bookmarks