PDA

View Full Version : enVar - simple module for handling of environment variables



Petr Schreiber
22-08-2015, 12:49
In case you need to work with environment variables, you might be interested in module named enVar.

It is provided with full source code, unit tests and binaries here:
https://github.com/petrSchreiber/thinBasic_enVar

How to use
Get the DLL from latest release (https://github.com/petrSchreiber/thinBasic_enVar/releases/latest).

(https://github.com/petrSchreiber/thinBasic_enVar/releases/tag/1.9.16.0Copy)Copy the DLL to your thinBasic/Mod directory, you should be able to reference it then like:


Uses "EnVar"


Example of the syntax:



' -- Sets value of MyVariable to MyValue
enVar_Set "MyVariable", "MyValue"

' -- Retrieves the value of given variable
String s = enVar_Get "MyVariable"

' -- Returns comma separated list of environment variables
String s = enVar_List

' -- Returns list of environment variables, separated by user specified string
String s = enVar_List(";")

' -- Erases the specified variable
enVar_Remove "MyVariable"

' -- Returns non-zero value in case the variable does exist
enVar_Exists "MyVariable"

' -- Set a variable with comma separated values
envVar_Set "MyCars", "Tesla Model S,Ferrari 512GT"

Long nCars = envVar_GetItemCount "MyCars" ' -- Presumes comma, returns 2
nCars = envVar_GetItemCount "MyCars", "," ' -- Separator specified explicitly, returns 2

String firstCar = envVar_GetItem "MyCars", ",", 1 ' -- Returns "Tesla Model S"
String secondCar = envVar_GetItem "MyCars", ",", 2 ' -- Returns "Ferrari 512GT"


Let me know if you need anything to be added.


Petr

Petr Schreiber
22-08-2015, 16:57
Updated the gitHub page with first release - it allows you to download just the module or even the sources, if you want.
Link updated in the first post of this thread.


Petr

ReneMiner
23-08-2015, 17:46
Think the EnVar(iables) could be of more use if there was an Index possible (array of certain variables)

as



EnVar_SetArray "Player", 1, "Petr"
EnVar_SetArray "Player", 2, "Eros"
'...
Long lCurrent = 1
String currentPlayerName = Envar_Get "player", lCurrent
String allPlayersNames = Envar_ListArray "player", $CRLF

Petr Schreiber
23-08-2015, 18:06
Hi Rene,

nice idea. System environment variables do not support arrays, but maybe the module could provide some kind of abstraction over it.
I think the best would be via user defined item separator, what do you think?


Petr

Petr Schreiber
12-03-2016, 20:09
New version of this library is available, download the module here:
https://github.com/petrSchreiber/thinBasic_enVar/releases/tag/1.9.16.1

I added support for storing and retrieving comma (but even other character) separated values.


Petr

ReneMiner
12-03-2016, 20:20
hey thats great, unfortunately my life is not allowing me to get deeper into this. I wish i would have the time :tears: and the opportunity to concentrate more on TB- but you know- life is not always playing the cards as one wants it. Currently my place to live is burning but give me two or three months and i will be back in old strength

Petr Schreiber
12-03-2016, 20:36
Hi Rene,

I wish you that all becomes resolved quickly and how you want it to be. You are our hero, we are looking forward impatiently to have you back!


Petr