From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Named array element (Bug or Feature)?

Solved!
Go to solution

Hi

 

I have a named array of containers. I like to increase the arry if the name is not present in the

array. For doing this i am using the PropertyObject members.

 

This is working well if you are using strings without 2 or more "\" (Backslash).

Screen.JPG

 

So whats the reason. 

I have used. T4.5 and 4.2 

 

Regards

 

Juergen

 

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 1 of 10
(3,733 Views)

can you post a 4.2 example?

Regards
Ray Farmer
0 Kudos
Message 2 of 10
(3,730 Views)

Hi Ray,

 

Demo as 4.2

 

Regards

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 3 of 10
(3,728 Views)

Its probably because \T puts a tab in your string whereas \M does nothing.

If you do \\T then the Exists() is True and it doesn't add it again.

Regards
Ray Farmer
Message 4 of 10
(3,725 Views)

HI Ray,

 

Thanks for testesting "\\T". Have also tought about this.But not tested, because i am getting string from TS itself.

It is the path from DLL CodeModule apater. So my opinion is that TestStand should handle the "\" stuff internally.

 

My workaround was just replacing the "\" with a "/".

 

Regards

Juergen

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 5 of 10
(3,722 Views)
Solution
Accepted by j_dodek

The backslashes for escaping only apply to string literals in expressions. In all other cases they do not apply. If you take a string from somewhere else and try to convert it into a string literal for an expression you need to escape it (i.e. all backslashes should be escaped with another backslash and all quotes should be escaped with a backslashes, and potentially carriage returns and linefeeds and tabs should also be escaped). Also, there is a function in the engine that will do this for you, Engine.Utility.Escape().

 

Hope this helps clarify things,

-Doug

Message 6 of 10
(3,696 Views)

Hi Doug,

 

Thanks for pointing out.

Engine.Utility.Escape() is exactly what i need.

 

Just a note. I was getting the string from Engine.FindFile()

It would be nice to add a remark to function's help in future relase that founded string should be escaped.

 

Regards

 

Juergen

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 7 of 10
(3,687 Views)

The issue is, the string returned by FindFile doesn't necessarily need to be escaped. The escaping is only necessary when you are creating a string literal in an expression. It really doesn't have anything to do with FindFile because in all other cases there is no escaping so FindFile returning an unescaped string is no different than anything else returning a string. How exactly are you using the string? Maybe what should be documented or looked into is that the way in which you are using it requires escaping.

 

-Doug

0 Kudos
Message 8 of 10
(3,678 Views)

Hi Doug,

 

Upps, I told you something wrong!!!  Engine.Find() File is NOT the problem here.

Excuse me.

The problem is as mentioned in topic on named arrays:

Here is the way iam getting the string.

 

1. Statement

// Modul Name

Locals.strFileName = Locals.hModule.AsCommonCModule.ModulePath,

// Lookup String

Locals.strArrayName = Locals.strFileName,

// Workaround

SearchAndReplace(Locals.strArrayName ,"\\","/"),

Locals.strLookup ="[\""+Locals.strArrayName+"\"]"

 

If Expression:

!Locals.objModules.AsPropertyObject.Exists(Locals.strLookup ,0)

     2. Statement

     // Set Array Elements name

     Locals.pObj.AsPropertyObject.Name = Locals.strArrayName,

 

Regards

Juergen

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 9 of 10
(3,661 Views)

I see that it's lookup strings of the format:

 

MyarrayVar["elementName"]

 

where the escaped string is also expected. This is similar to the string literal in expressions case. Generally, if you are adding the quotes for a string, then the contents between the quotes likely needs escaping. I've logged a request to update the documentation for lookupstrings to mention this issue and explain about escaping strings.

 

-Doug

Message 10 of 10
(3,651 Views)