input.text_area - want to use variable for defval - pine-script-v5

I am trying to assign a variable for defval but it says that it needs to be a constant.
string pair = syminfo.ticker + " long entry"
i_alert_txt_entry_long = input.text_area(defval = pair, title = "Long Entry Message", group = "Alerts")
Is it possible to do in pine script currently?
I have tried other options such as str.tostring to no avail.

For input.text_area, defval must be a const string.
And there is no way in Pinescript (<=v5) to get a constant string from a string.
As stated in the pinescript manual :
Values of “const” form must be known at compile time, before your script has access to any information related to the symbol/timeframe information it is running on. Compilation occurs when you save a script in the Pine Script™ Editor, which doesn’t even require it to already be running on your chart. “const” variables cannot change during the execution of a script.

Related

Matlab - using a function mulitple times in the same workspace, to add values and fields to a structure

I have a structure such as:
specimen.trial1 = 1
I now want to add another trial to the specimen, so that
specimen.trial1 = 1
specimen.trial2 = 2
I can do this without a problem within the workspace and command window. But, if I'm using a function to calculate the numbers for each trial (with dynamic fields), the new field and value erases the previous one. Eg:
function [specimen] = dummy(trial,value)
specimen.(trial) = value
end
run the function:
[specimen] = dummy('trial1',1)
then run the function again with different inputs, but keeping the structure intact in the workspace
[specimen] = dummy('trial2',2)
Instead of getting a structure with 2 fields, I get just one with Trial2 being the only field. Does that make any sense? What would like is to use the outputs of a function to progressively add to a structure.
Thank you,
Chris
Yes it makes sense, because you're creating a new struct specimen within your function.
Solution: pass the the previous specimen to the function as well.
function [specimen] = dummy(specimen,trial,value)
specimen.(trial) = value
end
and call:
[specimen] = dummy(specimen,'trial1',1)
or alternativly leave out the assignment at all and use the following
function [output] = dummy(value)
output = value
end
and call:
[specimen.trail1] = dummy(1)
which really depends on what you actually want to do. Put passing a name to a function which uses this name to define a struct is a little pointless unless you "use" that name otherwise. Also if you want to have input-dependent dynamic names you'd also go with the first alternative

Excel VBA: using R1C1 format, "Application defined or object defined error"

I am trying to create a formula that references other cells, but I keep getting this "Application defined or object defined error". I use R1C1 convention instead of Offset.
My Code:
Note: This code could be anywhere, I just need it to work. Also, I don't use the code like this. It is used in a reporting tool, but this is just similar code (to what I actually use) sufficient enough to show my problem
Cells(1, 1).Value = "5/1/2014 6:30"
soiDate = "$A$1"
Cells(10, 6).Value = "6/5/2014 14:12"
Cells(10, 10).Formula = "=(R[0]C[-4]-" & soiDate & ")*24" 'Error Occurs Here
UPDATE:
The following does not work either:
Cells(10, 10).FormulaR1C1 = "=(R[0]C[-4]-" & soiDate & ")*24"
Try this:
Cells(10, 10).FormulaR1C1 = _
"=(R[0]C[-4]-" & Range(soiDate).Address(, , xlR1C1) & ")*24"
It errors out since you kinda mixed up R1C1 reference to A1.
Just be consistent, you can use Range Object address property to convert reference. HTH.

Error with the Excel.Find function in VBScript

I am trying to create a VB script that searches through a column of dates and returns the address of the cell with todays date.
For some reason I keep getting an "Object required: 'FoundCell'" error.
Could someone have a look at my code and correct me?
I can read out the date using WScript.Echo, but once I use it in the find function it immediately gives me the error.
Set oExcel = CreateObject("Excel.Application")
Set wshShell = CreateObject("Wscript.Shell")
File_Path = "D:\Work\Personal Timemanagement\test.xlsx"
Set oData = oExcel.Workbooks.Open(File_Path)
WHAT_TO_FIND = Date()
WScript.Echo WHAT_TO_FIND
Set FoundCell = oData.Worksheets("tst2").Range("A1:A40").Find(WHAT_TO_FIND)
oExcel.Cells(4,4) = FoundCell.Address
oExcel.ActiveWorkbook.SaveAs "D:\Work\Personal Timemanagement\test2.xlsx"
oExcel.ActiveWorkbook.Close
oExcel.Application.Quit
WScript.Quit
Thanks for the help!
WHAT_TO_FIND1 returns value like #14/10/2014#.So replace the # with nothing using WHAT_TO_FIND1=Replace(WHAT_TO_FIND,"#","Nothing").
Once replaced the above code will work
I tried your script, works perfect for me.
For testing purposes I suggest you add the following line to the script
oExcel.Visible = True
Also make sure all the privies instances of Excel are closed so your script could get write access. (open task manager and end all Excel process - unless you have other excel files open)
Now make sure the Worksheet is spelled correct "tst2" also ensure that the range is correct "A1:A40"
Keep us posted.
Find() returns Nothing when the given value isn't found in the given range. Make sure that the Range A1:A40 on sheet tst2 in the workbook D:\Work\Personal Timemanagement\test.xlsx actually contains a cell with the current date, and that the cell is also formatted as a date. Find() won't return a match if for instance you're looking for a date 7/11/2013 and the range contains a cell (formatted as text) with the string 7/11/2013. Modify your statement like this for finding "text" cells:
Set FoundCell = oData.Worksheets("tst2").Range("A1:A40").Find(CStr(WHAT_TO_FIND))

iReport - Concatenating two variables with different evaluation time

I have two variables
$V{from} has evaluation value set to Now and
$V{to} has evaluation value set to Group.
Both seems to be working fine.
Now I need to append them. Currently I have $V{fromTo} which has expression $V{from} + "-" + $V{to}. Its evaluation time value is Group. What I want is just to simply append the current values of the two first mentioned variables. The current expression gives me the result (e.g. from = 1, to = 45)
45-45
Seems like the expression is taking the value of $V{from} evaluated during group execution time also. Any idea how to do this?
(Note, requirement does not allow me to just simply drag the two fields, i badly needed to store it in one variable)
I had the same problem. I solved setting Evaluation Time to Auto in my Text Field.

Text input through SSRS parameter including a Field name

I have a SSRS "statement" type report that has general layout of text boxes and tables. For the main text box I want to let the user supply the value as a parameter so the text can be customized, i.e.
Parameters!MainText.Value = "Dear Mr.Doe, Here is your statement."
then I can set the text box value to be the value of the parameter:
=Parameters!MainText.Value
However, I need to be able to allow the incoming parameter value to include a dataset field, like so:
Parameters!MainText.Value = "Dear Mr.Doe, Here is your [Fields!RunDate.Value] statement"
so that my report output would look like:
"Dear Mr.Doe, Here is your November statement."
I know that you can define it to do this in the text box by supplying the static text and the field request, but I need SSRS to recognize that inside the parameter string there is a field request that needs to be escaped and bound.
Does anyone have any ideas for this? I am using SSRS 2008R2
Have you tried concatenating?
Parameters!MainText.Value = "Dear Mr.Doe, Here is your" & [Fields!RunDate.Value] & "statement"
There are a few dramatically different approaches. To know which is best for you will require more information:
Embedded code in the report. Probably the quickest to
implement would be embedded code in the report that returned the
parameter, but called String.Replace() appropriately to substitute
in dynamic values. You'll need to establish some code for the user for which strings will be replaced. Embedded code will get you access to many objects in the report. For example:
Public Function TestGlobals(ByVal s As String) As String
Return Report.Globals.ExecutionTime.ToString
End Function
will return the execution time. Other methods of accessing parameters for the report are shown here.
1.5 If this function is getting very large, look at using a custom assembly. Then you can have a better authoring experience with Visual Studio
Modify the XML. Depending on where you use
this, you could directly modify the .rdl/.rdlc XML.
Consider other tools, such as ReportBuilder. IF you need to give the user
more flexibility over report authoring, there are many tools built
specifically for this purpose, such as SSRS's Report Builder.
Here's another approach: Display the parameter string with the dataset value already filled in.
To do so: create a parameter named RunDate for example and set Default value to "get values from a query" and select the first dataset and value field (RunDate). Now the parameter will hold the RunDate field and you can use it elsewhere. Make this parameter hidden or internal and set the correct data type. e.g. Date/Time so you can format its value later.
Now create the second parameter which will hold the default text you want:
Parameters!MainText.Value = "Dear Mr.Doe, Here is your [Parameters!RunDate.Value] statement"
Not sure if this syntax works but you get the idea. You can also do formatting here e.g. only the month of a Datetime:
="Dear Mr.Doe, Here is your " & Format(Parameters!RunDate.Value, "MMMM") & " statement"
This approach uses only built-in methods and avoids the need for a parser so the user doesn't have to learn the syntax for it.
There is of course one drawback: the user has complete control over the parameter contents and can supply a value that doesn't match the report content - but that is also the case with the String Replace method.
And just for the sake of completeness there's also the simplistic option: append multiple parameters: create 2 parameters named MainTextBeforeRunDate and MainTextAfterRunDate.
The Textbox value expression becomes:
=Parameters!MainTextBeforeRunDate.Value & Fields!RunDate.Value & Parameters!MainTextAfterRunDate.Value.
This should explain itself. The simplest solution is often the best, but in this case I have my doubts. At least this makes sure your RunDate ends up in the final report text.