In TI-BASIC, how do I display the Variable Name given only the variable? - ti-basic

I'm creating a function that displays a lot of variables with the format Variable + Variable Name.
Define LibPub out(list)=
Func
Local X
for x,1,dim(list)
list[x]->name // How can I get the variable name here?
Disp name+list[x]
EndFor
Return 1
EndFunc

Given a list value, there is no way to find its name.
Consider this example:
a:={1,2,3,4}
b:=a ; this stores {1,2,3,4} in b
out(b)
Line 1: First the value {1,2,3,4} is created. Then an variable with name a is created and its value is set to {1,2,3,4}.
Line 2: The expression a is evaluated; the result is {1,2,3,4}. A new variable with the name b is created and its value is set to `{1,2,3,4}.
Line 3: The expression b is evaluated. The variable reference looks up what value is stored in b. The result is {1,2,3,4}. This value is then passed to the function out.
The function out receives the value {1,2,3,4}. Given the value, there is no way of knowing whether the value happened to be stored in a variable. Here the value is stored in both a and b.
However we can also look at out({1,1,1,1}+{0,2,3,4}).
The system will evaluate {1,1,1,1}+{0,2,3,4} and get {1,2,3,4}. Then out is called. The value out received the result of an expression, but an equivalent value happens to be stored in a and b. This means that the values doesn't have a name.
In general: Variables have a name and a value. Values don't have names.
If you need to print a name, then look into strings.

This will be memory intensive, but you could keep a string of variable names, and separate each name by some number of characters and get a substring based on the index of the variable in the list that you want to get. For instance, say you want to access index zero, then you take a substring starting at (index of variable * length of variable name, indexofvariable *length + length+1).
The string will be like this: say you had the variables foo, bas, random, impetus
the string will be stored like so: "foo bas random impetus "

Related

Power Automate - Subtract two integer variables

I am trying to subtract two integer values as such:
But I get this error:
Unable to process template language expressions in action 'Negative_Index_of_Snabel-a' inputs at line '0' and column '0': 'The template language function 'sub' expects its first parameter to be an integer or a decimal number. The provided value is of type 'String'. Please see https://aka.ms/logicexpressions#sub for usage details.'.
I know that my variables in the sub() function is in quotes. But I cannot save it otherwise.
You're passing in literal string values, you need to specify that the values you want to evaluate are variables, like thus ...
sub(variables('VarMailInt'),variables('VarSnabelaIndex'))

How to pass contant string value for a column in SUMMARIZECOLUMN

I want to pass a constant string value i.e. Not Applicable for one of the column values that will be used in SUMMARIZECOLUMNS function. But I am not find any format in how to do the same.
SUMMARIZECOLUMNS( table_name[column_name], "Custom_Column_Name", "Not Applicable")

The code always outputs "not"

The following code always outputs "not":
print "input a number please. "
TestNumber = gets
if TestNumber % 2 == 0
print "The number is even"
else
print "The number is not even"
end
What is going wrong with my code?
The gets() method returns an object of type String.
When you call %() on a String object, the return value is a new String object (usually it changes the text. You can read more about string formatting here).
Since there are no String objects that == 0, the if/else will always take the same path.
If you want to use the return value of gets() like a number, you will need to transform it into one first. The simplest approach is probably to use the to_i() method on String objects, which returns a new 'Integer' object. If you're doing something where the user input will not always be an integer (e.g. 3.14 or 1.5), you might need to use a different approach.
One last thing: in your example the result of gets() is saved into a constant called TestNumber. Constants are different to normal variables, and they will probably cause problems if you're not using them intentionally. Normal variables don't start with capital letters. (You can read more about ruby variables here). In ruby you need to write you variable names like this: test_number.
I suspect your Testnumber variable might be interpreted as a string during the operation. make sure the testnum is converted to an integer first even if you put in say 100 it could be its being interpreted as the stirng "100" and not the integer 100.
A similar issue can be found here: Ruby Modulo Division
You have to convert TestNumber from string to integer, as your input has linefeed and/or other unwanted characters that do not match an integer.
Use TestNumber = gets.to_i to convert to integer before testing.

Get value of variable named in a string

Is there any way to get the value of a variable that has been named in a string.
For instance:
Dim number As Integer = 12
Dim numberCopy As Integer = Convert("number")
' numberCopy will now equal 12
' Convert is the function to convert the string to the variable
Something like that can be done only with Introspection, and only if the variable holding the value is a property of a class. Your example, where the variable is only temporarily known inside a function, cannot be made work as you like.
To learn more about Introspection, see the documentation and examples of the same name.
You can also use a Dictionary instead of straight properties and variables.
For instance
dim d as new dictionary
d.value("number") = 12
Then when you need the value, you can do
Dim numberCopy As Integer = d.value("number")
Nice thing about Dictionary is since keys as well as values are variant, you can throw at it pretty much anything, all variable types, as well as objects.
See Language Reference

Concatenating string from SSIS for loop task

I have an SSIS package which loops over an array of dates. On each iteration I would like to append the current date to a string to get a full string of all the dates iterated.
What I did was to make an expression where: dateconcatvariable + ", " +currentdatevariable
However, dateconcatvariable is resetting on every iteration of the for loop and so in the end I end up with the last date iterated over instead of all the dates.
the variable is a package level variable.
Any ideas on how to get a concatenation to happen on SSIS?
Thanks!
1. Create a string variable #User::var
2. Use an Expression component and set the expression to #User::var = #User::var + (WSTR, 15)#User::yourdatevar
This should give you the general idea.

Resources