Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value or character search

Status
Not open for further replies.

idehen

Technical User
Joined
Oct 26, 2004
Messages
92
Location
GB
Hope you all had a merry xmas and nice holiday.

I am using CR10 and want to search using a formula for a character as in the example.

Nos Name
12345 ABC
6788 DEF
69885 KLM

In this example, what i am trying to get is, where the 4th character or number is 4 name should be ABC and where 4th Character is 8 then DEF.

So last example above "KLM" is false. My problem is, how do i search for a character with data type "number" as "Like" only works for strings or text.

Is there a function for searching within data type numbers?

Thanks
 
If {table.Nos}[4] = 4 and {table.Name} like 'ABC' then 'True'
else
If {table.Nos}[4] = 8 and {table.Name} like 'DEF' then 'True'
else
'False'

Obviously you can expand on this to give more accurate feedback and alternatives:

//{@Checkmatch}

If {table.Nos}[4] = 4 and {table.Name} like 'ABC' then 'True #4 ABC' else
If {table.Nos}[4] = 4 and not({table.Name} like 'ABC') then 'False #4' else
If {table.Nos}[4] = 8 and {table.Name} like 'DEF' then 'True #8' else
If {table.Nos}[4] = 8 and not({table.Name} like 'DEF') then 'False #8' else
'False - no match'


You can simplify this formula a lot by declaring variables intially for the numeric and string values if need be:

//{@Neatercheck}

Numbervar x := {table.Nos}[4];
Stringvar y := {table.Name}

If x = 4 and y like 'ABC' then 'True #4 ABC' else
If x = 4 and not(y like 'ABC') then 'False #4' else
If x = 8 and y like 'DEF' then 'True #8' else
If x = 8 and not(y like 'DEF') then 'False #8' else
'False - no match'

Hope this helps to get you started.

'J

CR8.5 / CRXI - Discovering the impossible
 
Thanks CR85user.

I am getting a message: A string or an Array values is required here.

I have used the formula.

1) If {table.Nos}[4] = 4 and {table.Name} like 'ABC' then 'True'
else
If {table.Nos}[4] = 8 and {table.Name} like 'DEF' then 'True'
else
'False'


2)
Numbervar x := {table.Nos}[4];
Stringvar y := {table.Name}

If x = 4 and y like 'ABC' then 'True #4 ABC' else
If x = 4 and not(y like 'ABC') then 'False #4' else
If x = 8 and y like 'DEF' then 'True #8' else
If x = 8 and not(y like 'DEF') then 'False #8' else
'False - no match'


Both are coming back with same String or an Array values is required here.

Any advise please. Appreciate the quick response.

Thanks again.
 
Where is the cursor positioned when it shows that error?

'J

CR8.5 / CRXI - Discovering the impossible
 
The cursor is positioned on the "{table.Nos}".
 
Convert the number to a string first:

stringvar x := totext({table.nos},0,"");
if x[4] = 4 and
{table.Name} = 'ABC' then
true else
if x[4] = 8 and
{table.name} = 'DEF' then
true

-LB
 
Many thanks for your assistance guys.

The conversion did the trick and this works perfect.

Appreciate all the help!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top