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
 All Forums
 Origin Forum
 Origin Forum
 String Comparisons in LabTalk

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
a_user Posted - 08/20/1998 : 7:14:00 PM
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...

5   L A T E S T    R E P L I E S    (Newest First)
CStorey Posted - 04/08/2002 : 12:22:54 PM
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
Jose Posted - 04/05/2002 : 06:30:11 AM
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 Viņa, 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
CStorey Posted - 04/04/2002 : 4:41:33 PM
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
Jose Posted - 04/04/2002 : 1:40:55 PM
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 Viņa, Origin WebRing member
a_user Posted - 08/20/1998 : 7:17:00 PM
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.";


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000