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 for Programming
 LabTalk Forum
 IF-ELSE statement

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
alkamid Posted - 10/19/2010 : 08:18:03 AM
Hello,

Is something wrong with my code here?
if(exist(Bookg1) == 0)
{
	string litera$ = "g";
}
else
{
	if(exist(Bookj1) == 0)
	{
		string litera$ = "j";
	}
	else
	{
		if(exist(Bookm1) == 0)
		{
			string litera$ = "m";
		}
		else
		{
			if(exist(Booko1) == 0)
			{
				string litera$ = "o";
			}
			else
			{
				if(exist(Bookr1) == 0)
				{
					string litera$ = "r";
				}
				else
				{
					if(exist(Bookt1) == 0)
					{
						string litera$ = "t";
					}
					else
					{
						type -a "out of range";
					}
				}
			}
		}
	}
}
litera$=;

With the last command I get #Command Error!. Why?

4   L A T E S T    R E P L I E S    (Newest First)
alkamid Posted - 10/19/2010 : 11:45:02 AM
Of course, sorry for missing that and thank you for your patience and help. It works properly now.

Thanks!
larry_lan Posted - 10/19/2010 : 11:42:16 AM
Hi:

You should not re-declare the variable again inside "{ }". Please see my example above, I didn't declare the variable inside IF statement. That is, I use "litera$ = "g";", NOT "string litera$ = "g";".

P.S, There is a chapter, Scope of Variables, in our LabTalk document. Maybe that will help.

Larry
alkamid Posted - 10/19/2010 : 11:35:19 AM
I changed it to:
string litera;
if(exist(Bookg1) == 0)
{
	string litera$ = "g";
}
else
{
	if(exist(Bookj1) == 0)
	{
		string litera$ = "j";
	}
	else
	{
		if(exist(Bookm1) == 0)
		{
			string litera$ = "m";
		}
		else
		{
			if(exist(Booko1) == 0)
			{
				string litera$ = "o";
			}
			else
			{
				if(exist(Bookr1) == 0)
				{
					string litera$ = "r";
				}
				else
				{
					if(exist(Bookt1) == 0)
					{
						string litera$ = "t";
					}
					else
					{
						type -a "out of range";
					}
				}
			}
		}
	}
}
litera$=;


Unfortunately, it still doesn't work (there's no value assigned to litera$).
larry_lan Posted - 10/19/2010 : 10:18:00 AM
You declare the variable, litera$, inside the brace, which means that you can only visit it within the scope of "{ }". You should have script like:

string litera;
if(...)
{
litera$ = "g";
}
else
{
...;
}
litera$ = ;


Larry
OriginLab

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