![codemorphis.com Forum Index](templates/subSilver/images/CodeMorphis_Logo.jpg) |
codemorphis.com Software development: pure and simple.
|
View previous topic :: View next topic |
Author |
Message |
yodatek2k
Joined: 01 Feb 2009 Posts: 4 Location: New York
|
Posted: Mon Feb 02, 2009 11:53 am Post subject: If Then Else |
|
|
I found the tips pages to be fantastic. Can someone please show me what an If, then else looks like in Synopsis?
Also, some sample code showing how to take user input and evaluate it and do something based on a match would be great too.
Thanks. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
CodeMorphis
Joined: 02 Dec 2003 Posts: 252
|
Posted: Mon Feb 02, 2009 2:19 pm Post subject: |
|
|
Let’s take a look at a couple of sample programs that demonstrate how to make IF/Else and IF/Else/Then constructs. At the same time we will show how to build a simple UI for Login/Password entry.
Here are the two sample programs that we will explain:
http://www.codemorphis.com/articles/ans09/ans_020209/IF_Else.vpd
http://www.codemorphis.com/articles/ans09/ans_020209/Switch.vpd
For both programs we will use the same UI:
If you double click the textbox for the password field you will see that we have set the “PasswordChar” property to “*” so that as the user enters the password the text is concealed by showing the typical “*” characters.
In each of these programs we have added a Windows Event Callback component to handle the logic when the Login button is clicked. The Windows Event Callback component is a new logic control component that we will cover soon in another article. Basically, it allows you to trap Windows Events without having to use logic components to explicitly test Windows Events and other conditions.
In our sample programs, we have set the Windows Event Callback component to be called each time the user clicks the Login button in the UI.
For the IF/Else sample program, the logic contained in the Windows Event Callback component looks like this:
The Get UI Component Text component retrieves the text from the User textbox UI component in our Windows Form above and then passes the text to the If Equal logic component. We have set the data in port 1 of the If Equal component to “SuperUser”. This means that if the login name is “SuperUser” we will branch to the logic connected to output process port 1. This leads to the Message Box component which displays a message to indicate that the Login button was clicked with the text “SuperUser” entered in the User textbox UI. At this point we could implement whatever other logic desired for handling this special case.
Note that there is no logic connected to process output port 0 of the If Equal component. This means that if anything other than “SuperUser” is in the User UI field when the Login button is clicked then we do nothing. We could add any logic to this output process port to do whatever we want here. We could also continue the logic by adding more If Equal components or any of the other logic components found in the Logic tab of the Component Tray. In this way you can construct a cascading If Then, Else If Then, … Else If Then, Else construct.
Note that in a Windows Event Callback component, when a process path ends (i.e. control is passed through a component’s output process port that is not connected to another component) then the logic control returns to the main Windows event loop, waiting for more user mouse clicks, text entry, etc.
If you have many cases to check for an easy way to collapse all of the logic tests is to use the Switch component as in the second sample program Switch.vpd. Here we have the following logic in the Windows Event Callback component:
By default the Switch component can test against two cases and is like an If Equal Then, Else If Equal Then, Else construct. In the above, we had double-clicked the Switch component and set the “Number of switch arguments” property to 3, meaning we want to test an incoming value (input data port 0) against 3 different values and take a different logic path for each case.
We set a value of “SuperUser” in data port 1 of the Switch component, “SpecialUser1” in data port 2 and “SpecialUser2” in data port 3. What will happen is that now the text from the User UI textbox is compared against the three values and each comparison has its own logic path. Output process port 1 is followed if the value in data port 1 is matched, output process port 2 is followed if the value in data port 2 is matched and output process port 3 is followed if the value in data port 3 is matched. If none of the values are matched then the logic of output process port 0 is followed. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
yodatek2k
Joined: 01 Feb 2009 Posts: 4 Location: New York
|
Posted: Mon Feb 02, 2009 4:01 pm Post subject: If Then Else |
|
|
Great explanation. I will download the source and see if I can integrate it in to my application. Thank you. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|