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 for Programming
 LabTalk Forum
 Text, Numbers and Blanks
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kid

USA
20 Posts

Posted - 08/23/2001 :  3:36:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
how can, if it can, labtalk know if it's looking at a string, a number or a blank cell?

Alex

CStorey

Canada
137 Posts

Posted - 08/23/2001 :  6:26:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You could try something like the code below...then you could search through the %R string and pick out the numbers. Beware there are limitations to this script!

I never bothered to report the wierd behaviour of the "=" == VALUE comparison. Is this result supposed to occur?

// Return number if char. 1 is a number.
// Fails for %A="E-N"; where N is a number (i.e. recognizes Exponential Notation)
// Fails if %A contains an "=" anywhere. (Doesn't like to compare "=" == Value)

type.redirection=1;
%A="Not a number, but neither is 0 really.";
%R=""; ///results string

len=%[%A];

If (len>0)
{
// Is it only a number???
If ($(%A)!="--")
{
type "String is number! $(%A)";
}
// Does it contain numbers????
Else
{
For(aaa=1; aaa<=len; aaa++)
{
//type "--> $(aaa) - %[%A, aaa:aaa]";
If (%[%A, aaa:aaa]=="0") { %R="%R/0@c$(aaa)";};
If (%[%A, aaa:aaa]=="1") { %R="%R/1@c$(aaa)";};
If (%[%A, aaa:aaa]=="2") { %R="%R/2@c$(aaa)";};
If (%[%A, aaa:aaa]=="3") { %R="%R/3@c$(aaa)";};
If (%[%A, aaa:aaa]=="4") { %R="%R/4@c$(aaa)";};
If (%[%A, aaa:aaa]=="5") { %R="%R/5@c$(aaa)";};
If (%[%A, aaa:aaa]=="6") { %R="%R/6@c$(aaa)";};
If (%[%A, aaa:aaa]=="7") { %R="%R/7@c$(aaa)";};
If (%[%A, aaa:aaa]=="8") { %R="%R/8@c$(aaa)";};
If (%[%A, aaa:aaa]=="9") { %R="%R/9@c$(aaa)";};
};
If (%[%R]>0)
{
type "String is $(len) chars long. Is NOT a NUMBER. But contains numbers at %R.";
}
Else
{
type "String is $(len) chars long. Is NOT a NUMBER. DOES NOT contain any numbers.";
};
};
}
Else
{
type -b "String is a BLANK";
};
Return;

Craig Storey
Origin WebRing Member - http://nav.webring.yahoo.com/hub?ring=originwebring
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/31/2001 :  09:29:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This problem with evaluating strings containing "=" intrigued me so I did some testing.
// Test 1
if( %A==0/0 ) type string;
else type number;

// Test 2
if( %A!=0/0 ) type number;
else type string;

// Test 3
if( %A!="=" ) type not "=";
else type "=";

// Test 4
if( %A=="--" ) type "--";
else type not "--";

// Test 5
if( "%A"=="--" ) type "--";
else type not "--";
The results for various strings containing "=" are given in the table below.



%ATest 1Test 2Test 3Test 4Test 5
=stringnumber=--not --
a=bnumberstringnot =not --not --
=bnumberstringnot =not --not --
a=stringstringnot =--not --

If we want all strings containing "=" to evaluate as strings rather than numbers or missing values (--) then we can use tests 2, 3 and 5 as follows. (I'm assuming that we're testing the contents of cells in column B of the active worksheet.)
%A=col(B)[n]$;
%S=string;
if( "%A"=="--" ) %S=missing value;
if( %A!=0/0 && %A!="=" ) %S=number;
type Row $(n) contains a %S.;
I didn't include a test for blank cells (%A="") because they will be filled with "--" when the worksheet window refreshes.

Mike Buess
Origin WebRing Member

P.S. I should have pointed out that Tests 1 and 2 contain the fuzzy logic with regard to "=". When %A="=" both (%A==0/0) and (%A!=0/0) are true. When %A="a=b" or "=b" both are false. Only when %A="a=" is one true and the other false, in which case both tests give the correct answer.

Edited by - Mike Buess on 08/31/2001 09:33:20

Edited by - Mike Buess on 08/31/2001 09:37:45

Edited by - Mike Buess on 08/31/2001 11:19:13
Go to Top of Page

tib

Switzerland
105 Posts

Posted - 10/24/2003 :  2:01:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Is there anything better in the meantime?

My problem is even simpler:
I just wanted to test if there is any thing in the cell or not.
I thought the following would do the job

if (%[%(%H,x,y)]==0) {type -b Cell contains no value.}
else {type -b The cell value is %(%H,x,y)};

This should give 0 for empty or non existing cell
and any a value > 0 for a cell with content.

However, with empty cells (or not existing cells) I get back some arbitrary strange numbers, i.e. 2, 11, 17... for %[%(%H,x,y)]
Any ideas why?
Tilman.



Go to Top of Page

cpyang

USA
1407 Posts

Posted - 10/24/2003 :  6:09:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
how about this

%A=cell(x,y)$;

if (%A=="" || %A=="--")
{
type -b Cell contains no value.;
}
else {
type -b "The cell value is %A";

}



CP




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