The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 String Comparisons in LabTalk
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

a_user

USA
0 Posts

Posted - 08/20/1998 :  7:14:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm trying to allow a user to enter a list of columns, and then the script
makes an adjacent column and fills it with error data...

here's the relevant code
[ %n = name of a column from the users list ]

/* find the column name in the list */
j=1;
colnum = -1;
for (j=1; j <= wks.nCols ; j+=1) {
wks.col = j;
%g=wks.col.name$;
type %n %g $(j);
if(%n==%g) {
colnum = j;
type (^^);
};

When I run this on worksheet with cols A B C D, i see:
(When %n="B")
B A 1
B B 2
^^
B C 3
B D 4
B E 5

(then the script adds column B2 and tries to find column C)
C A 1
C B 2
C B2 3
C C 4
^^
C D 5
C E 6
^^

(So the script adds a column C2 where it made the last match, ie at the end
then tries to find column D)

D A 1
^^
D B 2
D B2 3
^^
D C 4
D D 5
^^
D E 6
D C2 7
^^
So the comparison %n==%g is generating false positives. I've "typed" the
variables it looks at, so I don't understand what's going on...
I'd appreciate any help...

a_user

USA
0 Posts

Posted - 08/20/1998 :  7:17:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Response:String Comparison

When you are comparing strings, you must use double quotes on the right-hand
side of the condition.

For example:

if(%N=="%G") type "same";

if(%N=="Navy") type "The color is navy.";

Go to Top of Page

Jose

Netherlands
93 Posts

Posted - 04/04/2002 :  1:40:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
How do I compare strings that contain one quotation mark? The following doesn't work...

%a=result';
%b=result;

if ("%a"=="%b'") type yes;




Jose Via, Origin WebRing member
Go to Top of Page

CStorey

Canada
137 Posts

Posted - 04/04/2002 :  4:41:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The following works for me. I just removed the quotes and tested to make sure it caught the spaces properly.

%a=no result';
%b=result;

if (%a==no %b') { ;
type -b YES;
}
else {
type -b No;
};

Alternately you could use another variable to compare them, like %c="%b'"; %a==%c.... but that uses up one of a precious few LabTalk string variables.

Craig Storey
Origin WebRing Member - http://g.webring.com/hub?ring=originwebring

Edited by - CStorey on 04/04/2002 16:45:03
Go to Top of Page

Jose

Netherlands
93 Posts

Posted - 04/05/2002 :  06:30:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That doesn't work properly in my version 7.0. I take your code and change the if condition using (%a==%b') and also get a yes.

Once I remove the quotes I always get a yes doesn't matter what I compare, but including the quotes doesn't give the desired result. (The returned value in the following examples is bold).


%a=result';
%b=result;

if (%a==%b) type yes; else type no;
if (%a==%b') type yes; else type no;
if (%a=="%b'") type yes; else type no;
if (%b'=="%a") type yes; else type no;
if ("%b'"=="%a") type yes; else type no;


Of course this seems to be a conflict with quotes. If instead of it I use a dot, comparison works fine:


%a=result.;
%b=result;

if (%a=="%b.") type yes; else type no;
if (%b.=="%a") type yes; else type no;
if ("%b."=="%a") type yes; else type no;


Do you find another way?

j.

Jose Via, Origin WebRing member

P.S. By the way, using another variable doesn't solve the problem...

Edited by - Jose on 04/05/2002 06:36:57
Go to Top of Page

CStorey

Canada
137 Posts

Posted - 04/08/2002 :  12:22:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry Jose, you're right and I didn't do enough testing. It agree that the "'" is the culprit. If you add anoter type command in after the variable declaration, maybe something like...

%a=result';
%b=result;


Type "-------------------------------\r\nYes or No does %A == %B ??";

if (%a == '%b') {....


then the type command comes out with the " quotes in place. It seems like the "'" is not treated properly. I would suggest that LabTalk use all three quotes ",',` interchangeably, making it possible to imbed any of them inside a string.

Example:

%A="It's time."; --> It's time.
%B=`"Come over here, it's ready", he said.`; --> "Come over here, it's ready", he said.
%C="``` E=mc^2 ```"; --> ``` E=mc^2 ```


Craig

Craig Storey
Origin WebRing Member - http://g.webring.com/hub?ring=originwebring
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000