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
 Switch inside a for loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

srmcarneir

Brazil
33 Posts

Posted - 07/08/2004 :  08:20:31 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi All,

We have a LabTalk script which contains a block as follows:
...


for (aa = 1; aa <= iNum; aa++ )
{
ierrGeg = fdlog.get(A, aa);

if ( ierrGet == 1 )
run.section(,ChooseCondition, aa);
}

[ChooseCondition]

switch (%1)
{
case 1:
...some calculations...
break;

default:
...other calculations...
break;
}

return 0;


We have noticed that the for loop stopped after
having run for aa = 1, even when iNum > 1.
It seems that the "break" command makes an exit
out of the switch command, by exiting the for
loop also. We have not found a way to let
the for loop continue running until aa <= iNum (when iNum >1) yet.
We also have tried the command continue, unsuccessfully.

Best Regards,

Ricardo Carneiro

Mike Buess

USA
3037 Posts

Posted - 07/08/2004 :  10:23:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ricardo,

This might just be a typo in your post but it's best to eliminate the obvious first...

You define ierrGeg=fdlog.get(A,aa) but use if(ierrGet==1) as the condition. If that's really in your script then ierrGet is always undefined and your script will fail.

Mike Buess
Origin WebRing Member
Go to Top of Page

srmcarneir

Brazil
33 Posts

Posted - 07/08/2004 :  1:08:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike, All,

Thanks for your prompt response!

I apologize for that , it is really a misspelling.
Please consider ierrGet in all cases instead of
ierrGeg.
I wish this mistake was made in the original script of mine,
that would make things much easier.

By the way, we are planning to redesign our script
from scratch because this has already taken too
long to debug. We are also considering the "translation"
of some LabTalk blocks to OriginC.

[Just forgot to inform: we are using OriginPro 7 with SR4 under
Win2k. Sorry for that!]

We appreciate your help!

Regards,

Ricardo Carneiro
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 07/08/2004 :  2:19:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ricardo,

I tried this simplied version of your script...

for(aa=1; aa<iNum; aa++)
{
run.section(,ChooseCondition,aa);
};

[ChooseCondition]
switch(%1)
{
case 1: ty 0; break;
default: ty $(%1); break;
};

It works fine unless iNum is undefined. I'd look closely at the calculations in the switch statement and make sure they don't change the value of either iNum or aa. An advantage or disadvantage (depending on your viewpoint) of LabTalk over Origin C is that LabTalk variables are global. Changing the value of aa in the switch command will effect the for loop which calls it. In fact, it's not necessary to pass aa as an argument - run.section(,ChooseCondition,aa). This will work just as well...

for (aa=1; aa<=iNum; aa++)
{
run.section(,ChooseCondition);
}

[ChooseCondition]
switch(aa)
{
}

Mike Buess
Origin WebRing Member
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