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
 IF-ELSE statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

alkamid

Poland
27 Posts

Posted - 10/19/2010 :  08:18:03 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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?

larry_lan

China
Posts

Posted - 10/19/2010 :  10:18:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

alkamid

Poland
27 Posts

Posted - 10/19/2010 :  11:35:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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$).
Go to Top of Page

larry_lan

China
Posts

Posted - 10/19/2010 :  11:42:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - larry_lan on 10/19/2010 11:47:08 AM
Go to Top of Page

alkamid

Poland
27 Posts

Posted - 10/19/2010 :  11:45:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Of course, sorry for missing that and thank you for your patience and help. It works properly now.

Thanks!
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