Setting up a HVar inside a program, IF it doesn't already exist. - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Setting up a HVar inside a program, IF it doesn't already exist. (/thread-18241.html) |
Setting up a HVar inside a program, IF it doesn't already exist. - matalog - 04-09-2022 06:51 PM I am using the following code to set up a list Variable inside a program, that the program will use if it already exists, and will create a list, if it doesn't already exist. Code:
This leaves a syntax error on the line CL(Z):=string(Z);. If I use HVars("CL"):={"1","2"} on the Home screen, it sets up the variable fine. Is there a way to do what I want to do, as it seems this is not the way? RE: Setting up a HVar inside a program, IF it doesn't already exist. - Tyann - 04-10-2022 06:47 AM Bonjour Vous ne pouvez pas utiliser une variable HVars par son nom tant que celle-ci n' a pas été créer. Donc si vous créez et utilisez cette variable dans le même programme, vous devez toujours utiliser la forme 'HVars("nom")' Pour une liste vous ne pouvez pas utiliser la syntaxe 'HVars("nom")(i)', il faut passer alors par une variable locale qui copie le contenu de HVars("nom") puis vous modifier la variable locale et enfin HVars("nom"):=variable locale. Espérant avoir aidé. REM Pour savoir si vôtre variable existe vous pouvez utilisez Code: POS(HVars,"nom") Hello You can't use an HVars variable by its name until it has been has not been created. So if you create and use this variable in the same program, you must always use the form 'HVars("name")'. For a list you cannot use the syntax 'HVars("name")(i)', you have to use through a local variable which copies the content of HVars("name") then you modify the local variable and finally HVars("name"):=local variable. Hoping to have helped. REM To find out if your variable exists you can use Code: POS(HVars, "name"). Translated with http://www.DeepL.com/Translator (free version) RE: Setting up a HVar inside a program, IF it doesn't already exist. - matalog - 04-14-2022 09:01 PM Thanks, that does work, but it doesn't allow me to update a non local List Variable, as it may not exist when the program is first Run. If I wanted to use this method, then I would start by loading the local list variable with the non local one, but that isn't possible as it is potentially not created yet. Is there a definite way to create a list variable within a program, that doesn't require the program being exited to have the List variable actually created and updatable. A solution to this would be to run a small prep program before use of the main program, but that isn't user friendly for a new user of the program. RE: Setting up a HVar inside a program, IF it doesn't already exist. - roadrunner - 04-14-2022 09:51 PM Does replacing this line: CL(Z):=string(Z); with: CAS(EXPR("CL(" + Z + "):=string(" + Z + ")")); do what you want? Code: EXPORT eraseme() RE: Setting up a HVar inside a program, IF it doesn't already exist. - Tyann - 04-15-2022 04:59 AM (04-14-2022 09:01 PM)matalog Wrote: Thanks, that does work, but it doesn't allow me to update a non local List Variable, as it may not exist when the program is first Run. Bonjour, Je ne comprends pas trop vôtre problème ? Etape 1: tester si la HVars existe si oui Etape 2 sinon la créer (ici une liste vide) Etape 2: Copier cette HVars dans une variable locale Etape 3: Modifier la variable locale Etape 4: Copier la variable locale dans la HVars. C'est la méthode que j'utilise tout le temps et qui fonctionne pour moi. Hello, I don't really understand your problem ? Step 1: test if the HVars exists if yes Step 2 if not create it (here an empty list) Step 2: Copy this HVars in a local variable Step 3: Modify the local variable Step 4: Copy the local variable into the HVars. This is the method I use all the time and it works for me. RE: Setting up a HVar inside a program, IF it doesn't already exist. - matalog - 04-15-2022 11:36 AM Yes, I follow now, thanks. The only thing is that this will require 2 copies of the List, at least when the program is running, and I expect this list to get very big. RE: Setting up a HVar inside a program, IF it doesn't already exist. - Tyann - 04-16-2022 11:25 AM (04-15-2022 11:36 AM)matalog Wrote: Yes, I follow now, thanks. The only thing is that this will require 2 copies of the List, at least when the program is running, and I expect this list to get very big. Bonjour matalog Dans les dernières versions du firware il y a 2 instuctions GET et PUT qui permettent lire un élément ou de modifier un élément d'une variable HVars de type liste. GET(HVars("name"),pos) --> renvoie l'élément de position 'pos' HVars("name"):=PUT(HVars("name"),value,pos) --> modifie l'élément de position 'pos' avec la valeur 'value' Vous pouvez également utiliser PUT(HVars("name"),value,pos)->HVars("name") (-> = sto>) Ca fonctionne sur ma G2 en version 2.1.14588 (2021 05 05) Hello matalog In the last versions of firware there are 2 instuctions GET and PUT which allow to read an element or to modify an element of a variable HVars of type list. GET(HVars("name"),pos) --> returns the element of position 'pos'. HVars("name"):=PUT(HVars("name"),value,pos) --> modifies the element of position 'pos' with the with the value 'value'. You can also use PUT(HVars("name"),value,pos)->HVars("name") (-> = sto>) It works on my G2 in version 2.1.14588 (2021 05 05) Translated with http://www.DeepL.com/Translator (free version) |