DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace text values

Solved!
Go to solution

Hello.

 

I have problem with replacing values in text channels and I can't find solution.

I have couple of channels filled with only 2 values: OK and NOK. How can I replace these values with for example 1 for OK and 0 for NOK ?

This replacement is needed for a chart drawing. With current values I can't draw the chart because Diadem don't accept text values as a scale.

 

Thanks in advance 🙂

 

 

0 Kudos
Message 1 of 7
(5,619 Views)

Hello,

 

For programming, Diadem uses Visual Basic Scripting, therefore in the script window you can create two new channels, parse the ones you currently have and change the text values to numeric. There are plenty of examples and tutorials on VBS on the web, surely you could find also text parser.

 

You could get a clue here:

 

http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/725001647731

 

http://www.computing.net/answers/programming/vbscript-help-parsing-a-text-file/14327.html

 

Diadem Help is useful on presenting how to create new channel

 

Regards

Emil

0 Kudos
Message 2 of 7
(5,599 Views)

Hi

 

What do You mean "parse the ones you currently have and change the text values to numeric" ?  When I import my data as a numbers all results are "NoValue".  Imported data must be marked as a text value.

 

I looked in Diadem VBS Help but I didn't find simple "find & replace" function that works. Under Excel VBA is quite easy to do but under Diadem it is much more complicated for me 🙂

 

 

 

0 Kudos
Message 3 of 7
(5,595 Views)

Hello,

 

I mean that you should programatically, using VBS, go element with element through the text values, read them, compare them with OK, NOK and then programatically create new numeric channel and replaceOK with 1 and NOK with 0.

I know it is not so easy using VBS, but for example you can use the programming languages you are familiar with to open your file, parse it and replace the OK, NOK with numeric values, and then further you can generate reports in Diadem.

 

Emil

0 Kudos
Message 4 of 7
(5,585 Views)
Solution
Accepted by Domin

Hello Domin,

 

replacing a substring in a text with another text can be done with the VBS function "Replace".

Executing a function on a whole channel can be done by using ChnCalculate.

 

Combine the two and you get :

  

ChnCalculate("ch(""Statistics text"") = Replace(ch(""Statistics text""),""value"",""LLL"")")

 

This refers to a channel from the DIAdem example data set. The above command executes the "Replace" command for each value of the text channel "statistics text" . It replaces each occurance of "value" with "LLL".

 

Hope this helps

 

Andreas

Message 5 of 7
(5,569 Views)

Hello Domin,

 

Here is another easy way to solve this.

 

  1. Open the Calculator in DIAdem (either in VIEW, ANALYSIS or SCRIPT) - it's in the toolbar.
  2. Type the following line into the calculator:

    Ch("New Test") = -(Ch("[1]/Test")="ok")

    In this line of code, I am creating a new data channel called "New Test," and I am referencing the channel "Test" in group one in the Data Portal. Make sure to subsitute your chanel group and name. Please note that this is also case sensitive, so use "OK" instead of "ok" depending on how this is written in the data channel
  3. A new data channel will be created that contains "0" (for any line that's not "OK") and "1" (for the lines that contain "OK").

You can turn this into a Script by adding a call to the calculator:

Call Calculate("Ch(""New Test"") = -(Ch(""[1]/Test"")=""ok"")",NULL,NULL,"")

 

I hope that helps, it doen't really get much easier than that. And this is very fast as well, if you have long channels.

 

Let me know if I can be of further assistance,

 

      Otmar

 

Otmar D. Foehner
Message 6 of 7
(5,561 Views)

Hello

 

 

The solution that Andreas suggested worked for me perfectly.

 

 

Thank You 🙂

 

 

 

 

0 Kudos
Message 7 of 7
(5,512 Views)