retrieve from array for input parameter doesn't work - autohotkey

I want to do something like..
position := [100, 200]
Click, position[1], position[2]
but the above doesn't work, no error, but doesn't do click
Click, %position[1]%, %position[2]%
above gives error, variable name contains an invalid character
position := [100, 200]
p1 := position[1]
p2 := position[2]
Click, %p1%, %p2%
above works, but I don't want to assign dummy variables each time I need to click..
any help?
thanks!

This will do what you want:
click % position[1] . "," . position[2]
The % must be followed by a space or tab. It causes the command to use expression mode.
More information on "expression mode" can be found under Help > Variables and Expressions > Variables > Retrieving the contents of variables.

Related

How to store order of user input and update string

I am trying to make the field 'all names' display all of the selected 'names' (letters in this case) in the order they have been selected (assumed left-to-right). What I have written seems to only be functional if only the first transformation is applied and for the case A + E/F/G. All the rest do not work and I do not understand why.
The code for the first dropdown is this:
% Value changed function: DropDown
function DropDownValueChanged(app, event)
app.FirstName = app.DropDown.Value;
switch app.FirstName
case 'A'
app.FinalNameDrop.Value='A';
case 'B'
app.FinalNameDrop.Value='B';
case 'C'
app.FinalNameDrop.Value='C';
end
end
I was advised by an internet stranger that I can "define a property on the class itself!" and so I tried
properties (Access = private)
Property % Description
FirstName
SecondName
end
However, I am unsure how this can help me. How would I go about making this functional?
just put this in all callback methods:
app.dropDownFinal.Value = sprintf('%s + %s + %s',app.dropDown.Value app.dropDown2.Value app.dropDown3.Value);

All tables in the bracketed expression must have the same variable names

I have two editable numeric fields and a table in app designer; the user can enter the values in these editable fields and then push a button. Then, the values are added to a table. Also, I provide an option to attach an excel folder that should have two columns to reflect on the table.
Both of these work perfectly fine individually, but, if I added the values manually then attached an excel folder or vice versa, I get the following error: All tables in the bracketed expression must have the same variable names.
The function that handles the editable fields:
app.t = app.UITable.Data;
x = app.xvalueEditField.Value;
y = app.yvalueEditField.Value;
nr = table(x, y);
app.UITable.Data = [app.t; nr]; %% error happens here if I attach excel then add manually
app.t = app.UITable.Data;
The Function of the excel folder:
text = readtable([pathname filename], "Sheet",1, 'ReadVariableNames',false);
fl = cellfun(#isnumeric,table2cell(text(1,:)));
if (numel(fl(fl == false)) > 0)
flag = false;
else
flag = true;
end
if (flag)
A = [app.t; text]; %% error happens here if I add manually then attach
app.UITable.Data = A;
app.t = text;
end
Note: these are only the parts of the function, where I attempt to combine values
Can someone please help me?
Thank you
The error message is telling you that table only allows you to vertically concatenate tables when the 'VariableNames' properties match. This is documented here: https://www.mathworks.com/help/matlab/ref/vertcat.html#btxzag0-1 .
In your first code example, the table nr will have variable names x and y (derived from the names of the underlying variables you used to construct the table). You could fix that case by doing:
% force nr to have the same VariableNames as app.t:
nr = table(x, y, 'VariableNames', app.t.Properties.VariableNames);
and in the second case, you can force text to have the correct variable names like this:
text.Properties.VariableNames = app.t.Properties.VariableNames

LibreOffice Macro always show #NULL! after reopening the file

I wrote a macro in LibreOffice Calc and it is able to run correctly. But if I close the file and reopen, it always show #NULL! instead of the correct value. What am I missing here?
My macro code
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function Calculate(CalType As String) As Double
'
' Calculate Macro
'
Dim i As Integer
Calc = 0
i = 1
Do While Not IsEmpty(Cells(i, 2))
If (Cells(i, 3).Value = CalType And (Cells(i,2) = "A" Or Cells(i,2) = "B")) Then
Calculate = Calculate + Cells(i, 4).Value
ElseIf (Cells(i, 3).Value = CalType And Cells(i,2) = "C") Then
Calculate = Calculate - Cells(i, 4).Value
End If
i = i + 1
Loop
'
End Function
The calling function will be something like =Calculate(J6)
The file is saved as .ods format.
The Cells call did not work at all for me. It is from VBA, not LO Basic. However I do not think that is the main problem.
LibreOffice expects that user-defined functions will be simple, only accessing the cell that contains the formula. Since the spreadsheet has not been fully loaded yet when the function is called, it is not possible to read other cells.
The workaround is to ignore errors and wait until the document is fully loaded before running the function. Take the following code as an example:
Function ReadOtherCell(row, col)
On Error GoTo ErrorHandler
oSheet = ThisComponent.CurrentController.ActiveSheet()
oCell = oSheet.getCellByPosition(row, col)
ReadOtherCell = "value is '" & oCell.getString() & "'"
Exit Function
ErrorHandler:
Reset
End Function
Sub RecalculateAll
' This is for user-defined functions that need to read the spreadsheet.
' Assign it to the "View created" event,
' because before that, the spreadsheet is not fully loaded.
ThisComponent.calculateAll
End Sub
Enter foo in A1, and =ReadOtherCell(0,0) in A2. So far, this has the same problem -- It will fail when the document is first opened.
Now, go to Tools -> Customize. In the Events tab, highlight View created. Press Macro... and find the RecalculateAll function. Then press OK.
Now when the document is closed and reopened, cell A2 should show the result value is 'foo'.
This is derived from B. Marcelly's answer at http://ooo-forums.apache.org/en/forum/viewtopic.php?f=20&t=73090&sid=f92a89d676058ab597b4b4494833b2a0.
I had the same problem.
I noticed that in the module, i had an empty Sub Main
After i 've erased it, the functions started working again

Variable labels in SPSS Macro

I'm new to the SPSS macro syntax and had a hard time trying to label variables based on a simple loop counter. Here's what I tried to do:
define !make_indicatorvars()
!do !i = 1 !to 10.
!let !indicvar = !concat('indexvar_value_', !i, '_ind')
compute !indicvar = 0.
if(indexvar = !i) !indicvar = 1.
variable labels !indicvar 'Indexvar has value ' + !quote(!i).
value labels !indicvar 0 "No" 1 "Yes".
!doend
!enddefine.
However, when I run this, I get the following warnings:
Warning # 207 on line ... in column ... Text: ...
A '+' was found following a text string, indicating continuation, but the next non-blank character was not a quotation mark or an apostrophe.
Warning # 4465 in column ... Text: ...
An invalid symbol appears on the VAR LABELS command where a slash was
expected. All text through the next slash will be be ignored.
Indeed the label is then only 'Indexvar has value '.
Upon using "set mprint on printback on", the following code was printed:
variable labels indexvar_value_1_ind 'Indexvar has value ' '1'
So it appears that SPSS seems to somehow remove the "+" which is supposed to concatenate the two strings, but why?
The rest of the macro worked fine, it's only the variable labels command that's causing problems.
Try:
variable labels !indicvar !quote(!concat('Indexvar has value ',!i)).
Also note:
compute !indicvar = 0.
if(indexvar = !i) !indicvar = 1.
Can be simplified as:
compute !indicvar = (indexvar = !i).
Where the right hand side of the COMPUTE equation evaluates to equal TRUE a 1 (one) is assigned else if FALSE a 0 (zero) is assigned. Using just a single compute in this way not only reduce the lines of code, it will also make the transformations more efficient/quicker to run.
You might consider the SPSSINC CREATE DUMMIES extension command. It will automatically construct a set of dummies for a variable and label them with the values or value labels. It also creates a macro that lists all the variables. There is no need to enumerate the values. It creates dummies for all the values in the data.
It appears on the Transform menu as long as the Python Essentials are installed. Here is an example using the employee data.sav file shipped with Statistics.
SPSSINC CREATE DUMMIES VARIABLE=jobcat
ROOTNAME1=job
/OPTIONS ORDER=A USEVALUELABELS=YES USEML=YES OMITFIRST=NO
MACRONAME1="!jobcat".

Error, (in addList) invalid subscript selector

I have a list of numbers and I want to add them and then multiply them by a constant.
addList := proc(a::list,b::integer)::integer;
local x,i,s;
description "add a list of numbers and multiply by a constant";
x:=b;
s:=0;
for i in a do
s:=s+a[i];
end do;
s:=s*x;
end proc;
sumList := addList([2, 2, 3], 2) works fine but at the same time sumList := addList([20, 20, 30], 2) gives an error.
Can somebody point out the error ?
In the for loop you do s:=s+a[i] but i is set to one of the values in a already - not the index of a value. A first pass fix would be to just change the statement above to s:=s+i.
You could also write the function as
proc(a::list,b::integer)::integer;
convert(a,`+`)*b;
end;
Even shorter, there is
addList:= (a,b)-> `+`(a[])*b;