$b = "a00000"
Now due to a complicated application, i want to access $a00000.ID
The application stores a return object inside a variablename (which is a string value of another)
When i try "$b" it shows the value, but $"$b".ID is an error
${$b}.ID is also an error
$'"$b"'.ID is also an error
How do i access value of $a00000.ID given that previously $b=a00000 ?
(one variable name is assigned by a previous string value)
Give this a try:
(Get-Variable $b -ValueOnly).Id
Related
For example, I define a variable with an integer and if I try to check the variable in the console it says "undefined".
Assuming you are talking about JavaScript. The reason you see it's undefined because: "This usually occurs when a variable is declared. Here the variable is assigned a memory or space by the JavaScript engine. Because of this, once a variable is declared, it takes a value of undefined even before assignment."
When you assign a value (even null) to the created variable, it will no longer be undefined anymore
https://scotch.io/courses/10-need-to-know-javascript-concepts/declaring-javascript-variables-var-let-and-const
Try assigning the value to variable when you define it.
Eg: int a=1;
in your console type let a = 5;
then type a.
your output will be 5. Why? because you instantiated the variable but never call it afterwards.
So I have the following CMake code:
function(get_sources output_var)
set(${output_var} "a" PARENT_SCOPE)
message(${output_var}) # prints "SOURCES" (as expected)
message(${${output_var}}) # throws an error - why?
...
endfunction(get_sources)
get_sources(SOURCES)
message(${SOURCES}) # prints "a" - ok, so the above function created a var
The get_sources function is supposed to create a variable with given name in parent scope and fill it with some content.
It seems like get_sources(SOURCES) creates the variable as expected - message(${SOURCES}) outside function prints "a", but there's a problem with the line message(${${output_var}}). It should evaluate to message(a) and print "a", but instead it throws an error:
CMake Error at CMakeLists.txt:41 (message):
message called with incorrect number of arguments
I am confused. Is it supposed to be like that? Should I make a function scoped variable, fill it in and then at the end copy its contents to a parent scope variable? I checked it - it works, but I wanted it to be without any additional variables.
EDIT:
I enclosed a ${${output_var}} in quotation marks and now it doesn't throw an error, but it prints nothing.
PARENT_SCOPE sets variable only for parent scope, not for the current one. This is explicitely stated in CMake documentation about 'set' command:
If the PARENT_SCOPE option is given the variable will be set in the scope above the current scope. Each new directory or function creates a new scope. This command will set the value of a variable into the parent directory or calling function (whichever is applicable to the case at hand). The previous state of the variable’s value stays the same in the current scope (e.g., if it was undefined before, it is still undefined and if it had a value, it is still that value).
This is a proper way for handle PARENT_SCOPE variables:
Should I make a function scoped variable, fill it in and then at the end copy its contents to a parent scope variable?
I am debugging an application that runs on a server and users will access the application on another server. The application uses encryption and as part of the key, I am using the String.Reverse property.
Dim Mystring As String = "123abc"
Dim reverse = String.Format("{0},{1}", Mystring.Reverse)
The string reverse is different when I run it from one machine (RDP/Citrix Environment ASP.NET 4.6.1). The value is:
System.Linq.Enumerable+<ReverseIterator>d__a2`1[System.Char]
The same string, but ran from another machine (RPD non-Citrix Environment ASP.NET 4.5.2). The value of reverse is:
System.Linq.Enumerable+<ReverseIterator>d__73`1[System.Char]
Why are the values different in the different environments?
Look at this line first:
Dim reverse = String.Format("{0},{1}", Mystring.Reverse)
Specifically, this expression:
Mystring.Reverse
Reverse is a function, not a property, but it's missing the parentheses (). The trick here is the String.Format() method accepts the base Object type as an argument, and compiler is able to treat the MyString.Reverse expression as a delegate type that is convertible to object. The values you see in your output are the result of calling .ToString() on that function delegate. It's the type name for the function, rather than anything to do with the value of your MyString object. Since that type is dynamically and randomly generated at runtime, you'll see different values not only on different platforms, but different runs on the same computer.
In the VB6 era, it was normal to call methods without the parentheses. In the .Net world, always use parentheses when you call a method.
What you want is this:
Dim reverse As String = String.Format("{0},{1}", Mystring.Reverse())
Even here, you're missing the second argument to match the format string. I doubt you'll get the result you expect.
Finally, reversing a string as the key seems very wrong when it comes to encryption. You are using a real cyrptogrpahic algorithm from the System.Security.Cryptography library, right? Right!?
You are not outputting the value of the reversed String but the name of the type used to perform the reversal. That type is dynamically created and randomly named. The "d" in those two names means "dynamic" and the "a2" and "73" parts are random.
Basically, what you perceive to be an issue is not an issue. The problem is that you're not actually creating a String from the reversed output. You say "String.Reverse property but that is NOT a property. It is a method and it is not a member of the String class but rather an extension method on the IEnumerable(Of T) interface. You are treating your String as an enumerable list of Char values and reversing that. If you want a String from that then you need to create one, i.e.
MyReversedString = New String(Mystring.Reverse().ToArray())
That will push the contents of your iterator into an array and then create a new String object from that array.
I'm using Entity Framework to send a query to the database using ExecuteStoreQuery
If (DBEntity.ExecuteStoreQuery(Of Integer)("SELECT COUNT(ReceiptUID) FROM qryRptSrc_Cust_GoodsReceipt_Issues WHERE ReceiptUID = #Recpt", ReceiptUID)(0) > 0) Then ....
Which gives me the error message that my scalar variable #Recpt hasn't been declared. I know what that error message means, but I'm wondering why it's being thrown in this case. ReceiptUID is a Guid with the correct value. The parameters that are passed don't have to be DbParameter objects, they can just be values and it should work fine. I've done it that was in the past before without issue, and even MSDN states
The parameters value can be an array of DbParameter objects or an array of parameter values. If only values are supplied, an array of DbParameter objects are created based on the order of the values in the array.
I could create a DbParameter object instead, but I'd like to know why this case isn't working.
Token answer:
Try #p0 instead of #Recpt
In an SSIS package I have a For..Each container that enumerates all (.) the files in a folder.
In that For..Each container I have a component-level variable 'fileComments' of DataType 'String'.
In that For..Each container I have a script task. With a ReadWrite entry for 'filecomments' (amongst others)
In that script task, I have some code :-
Dim Comments As String = Dts.Variables("User::fileComments").ToString
which allows me to read the value of that variable, but if I try to allocate a value back to that variable, I get a Property 'Item' is 'ReadOnly' blue squiggly underline.
How do I change the vlaue of that variable (or get the value out of the script task so I can use it later in the flow) ?
Thanks in advance.
your problem is a common trap check this article out:
http://www.programmersedge.com/?p=1350
you basically need to use the Dts.VariableDispenser object to lock or declare the variable as read / write in the script task.