Variable - Run-time variable assignment ======================================= File: BLib.Variable - Update: 1.01 Author: J.G.Harston - Date: 03-Feb-2009 The Variable library provides a function to allow a program to create variables at run-time. The Variable library only works with BASIC V or later or equivalent. Usually a program knows what variable it uses - they are written into the program code itself. Sometimes, though, a program only knows a variable's name when the program itself is run. The most common usage is to creating variables from messages files. Assign a value to a variable ============================ DEFPROCVar_Assign(name$,value$) On entry: name$ =name of variable to assign value$=value to assign to the variable The variable whose name is in name$ is assigned the value in value$. All variable types can be created. Arrays cannot be created with this method. Examples ======== PROCVar_Assign("name$","Jonathan") is equivalent to name$="Jonathan" PROCVar_Assign("size%","200") is equivalent to size%=200 PROCVar_Assign("golden","1.6") is equivalent to golden=1.6 Using with a messages file ========================== The commonest use of run-time variable assignment is to create program messages with with territory-specific Messages files. Using the following code: in%=OPENIN("Choices:"+AppName$+".Messages") IF in%=0:in%=OPENIN(AppDir$+".Resources."+Territory$+".Messages") IF in%=0:ERROR 214,"No messages file!" REPEAT A$=GET$#in%:IF LEFT$(A$,1)="#":A$="" A%=INSTR(A$,":"):IF A% THEN A%=A%-1:REPEAT:A%=A%+1:UNTIL MID$(A$,A%,1)<>" " PROCVar_Assign("m"+LEFT$(A$,A%-1)+"$",""""+MID$(A$,A%+1)+"""") ENDIF UNTIL EOF#in%:CLOSE#in%:in%=0 With the following Messages file: Info:Inquo File:Fiche Stop:Arret would set up the following variables: mInfo$="Inquo" mFile$="Fiche" mStop$="Arret" Then, instead of a program using: PRINT "Stop" it would use: PRINT mStop$ This allows messages files to be created for whatever language you want the program to communicate with the user with. Version History =============== 1.00 15-Mar-1991 First version written. 1.01 03-Feb-2009 Added '#' and '&' variables, added BBFW crunch directives.