Jump to content

Getting the middle values of a string


---
 Share

Recommended Posts

So what I am trying to do is have PiWeb populate in new text boxes Bubble Number, Drawing Dimension, and Sheet/Zone using the characteristic name.

Example Characteristic Name: 01 85.0 S1 E3

BUBBLE NUMBER (Populates the text box with 01)
${String.Left(Qdb.Characteristic(2002),2)}

SHEET/ZONE (Populates the text box with S1 E3)
${String.Right(Qdb.Characteristic(2002),5)}

DRAWING DIMENSION (want to populate it with 85.0)

I need some statement that that removes the Left first 3 characters and the Right last 6 characters.

I am guessing something like: ${String.Right(${String.Left(${Qdb.Characteristic(2002)),6)},3)} but it is not working 🙁
I am missing something.

Anyone have any clue.
Link to comment
Share on other sites

Hello Ted,

Assuming your string separator is always a blank space you could always take the second index of the split string separated by a blank space:

${List.IndexOrNull(${String.Split(${Qdb.Characteristic(2002)}, " ")}, 1)}

With your example: ${List.IndexOrNull(${String.Split("01 85.0 S1 E3", " ")}, 1)} will produce 85.0.

In general it is a good idea to avoid hard counts of numbers like trimming the first 3 or last 6 characters as it will put you in a tight spot if your naming convention ever changes. Here you see that if for some reason you had a bubble number above 100 (assuming that is your first place holder) then this formula will still work.

This would similarly work if you used split string function together with the index function to figure out where your blank spaces are then extract your value that way.

Josh Smokovitz
Product Manager – ZEISS PiWeb
ZEISS Industrial Quality Solutions
Link to comment
Share on other sites

Thanks...

I will give this a try. I am using the hard number counts to control the naming convention and for the characteristics on purpose. It would change if the bubble number is greater than 99 which is fine. The print zone will always be the sheet then zone (possibly modifying it for one page prints when it is only zone). The goal is to be able to have the same characteristic name called out on multiple dimension like, Position, since it is bubbled I only want to see "Position" as the description of the bubble number.

As long as I can get the values in between I am happy.
Link to comment
Share on other sites

Josh,

Please sign in to view this quote.

Can you please explain how that string works please?

Also how would I use it to get the bubble number and the zone?

What I found is that if I use Position of a pattern my method fails because it adds "^1" to the end of the characteristic name. So I might have to change the naming convention to 01 S1 E3 85.0 (Bubble Number, Zone, Description) so understanding the string will help. To fix it for the moment by added a condition that if the text has "^" in it, make the font transparent and it that is what you see in the modified example in the previous post.
Link to comment
Share on other sites

After reviewing my results there is a problem with the formula when the name changes. It stops at the space.

If the name is 03 Radius 6.4 S1 D4 the name is only Radius not Radius 6.4. I am guessing that if I use an underscore (Radius_6.4) it would work and that would be OK but I would rather leave the space. I am thinking the hard number way to get the result will be best and I am going to use the format Bubble Number, Description, Sheet / Zone (BN DESCRIPTION SN ZO)

So first 2 (right, 2) for Bubble Number (for prints with less than 100)

Last 5 (Left, 5) for Sheet/Zone

between first 3 and last 6 for Description

something like..... String.Right(String.Left ??Qdb.Characteristic(2002) ,6),3)
Link to comment
Share on other sites

The underscore did get me the full name as needed but looks terrible. I will see if I use 01_Radius 6.4_S1_D4 and see how that looks but I don't like the underscore in the name. Change the string to "_" instead of " ".
Link to comment
Share on other sites

By switching the name convention to:

03_Radius 6.4_S1-D4

and the modifying formula to "_" instead of " " I get try 2

This is doable I think, I thought the Print Zone looked cooler in the first try but this should work no "_" anywhere to be found and I have the result I want. Now the test is what will the customer want to use.

This was 500% easier than making characteristic variable and typing everything in per characteristic just change the naming convention and everything self populates.

UPDATE:

After playing with this a little I can use a naming format of 03_Radius 6.4_S1 D4 the "_" separates the description to populate the field and I get the cool looking Sheet/Zone on the Report.

Modified for BN and SZ try 2.pdf

Link to comment
Share on other sites

 Share

×
×
  • Create New...