Normal Topic Create an IF statement using an other file (Read 767 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Create an IF statement using an other file
Aug 18th, 2016 at 3:52pm
Print Post Print Post  
In my programming are several IF statements that allow/disallow actions based on @Group and @UserID info.  Many of these IF statements have several of these in a row, using "or" to connect them.  For example: If @Group="X" or @UserID="Y" or @UserID="Z"....

Because these are part of the programming, when changes are necessary I must re-program and then update the working database.  I find this cumbersome, especially since we are using more of Sesame's capabilities than ever before.

Is there a simple way to create these IF statements using records from another file?  I'm thinking that if I create a file for each user and have Y/N elements for the various tasks, I would then be able to select all the users and/or groups I need to create the IF statement from that file.

Any suggestions?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Create an IF statement using an other file
Reply #1 - Aug 20th, 2016 at 5:13am
Print Post Print Post  
Depending on the structure of your code you could use #include statements:
Code
Select All
#include "MyFile.sbas"
 


which will act as though the code in that file were simply inserted wherever the #include statement is. Combining #include statements with subroutines or functions in the global code area gives you a lot of centralized reuse, even across multiple applications.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Create an IF statement using an other file
Reply #2 - Aug 22nd, 2016 at 1:44pm
Print Post Print Post  
Thanks.  I can't find any documentation on #include "MyFile.sbas". 

Do I write that statement as part of an IF statement, for example:  "If @group=#include "myFile.sbas" then...?

Will it include every record in the file?

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Create an IF statement using an other file
Reply #3 - Aug 22nd, 2016 at 1:54pm
Print Post Print Post  
No, you probably want to place the #include statement in your code where ever you have code that repeats and you want to be able to edit it from just one file.

In your included file (let's name it "greet_john.sbas"):
Code
Select All
if(@User() = "John")
{
    writeln("Hello John")
}
else
{
    writeln("What happened to John?")
}
 



Then in any code that needs to greet John:
Code
Select All
#include "greet_john.sbas"
 



Wherever you place the #include, the text from the file named right after "#include" (in this case "greet_john.sbas") will be inserted. That way, you can write the code once and use it in many events or even many applications, and edit it from a central file.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Create an IF statement using an other file
Reply #4 - Aug 22nd, 2016 at 2:50pm
Print Post Print Post  
That's a little clearer but I don't understand what the "file" is for "greet_john.sbas".  I don't know what kind of file ".sbas" is.  Is it a text file? Where does the file need to reside, in the Sesame data directory?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Create an IF statement using an other file
Reply #5 - Aug 22nd, 2016 at 6:56pm
Print Post Print Post  
You can specify either a complete or relative path to the file. If the path is relative, it is relative from the "Start In" directory specified in your icon. So, if your "start in" directory is: "C:\Users\NHUser\Sesame" and you specify "#include MyInclude.sbas", then the file, it will insert will be:

C:\Users\NHUser\Sesame\MyInclude.sbas

The .sbas extension is completely optional, but it stands for "SBasic". The file does need to be a text (ASCII) file containing valid SBasic source code.

All it really does is insert the contents of the file into your SBasic program right at the point where the #include statement is in your code. If you do go this route, remember that all of your client computers will need a copy of the included file, always in the same relationship with your "start in" directory.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged