Normal Topic IF...THEN... (Read 1019 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
IF...THEN...
Feb 15th, 2012 at 10:20pm
Print Post Print Post  
I have a new project to create a statement (not a financial statement) in one element (call it process step 1) depending on the value in another element.  I have about 25 potential values that each require a different statement. 

I know I can accomplish this with a series of 25 If/Then statements but i also have 15 of these process step elements to fill.

To fill all the process step elements, I need to go through 25 If/Then statements 15 times!  This seems very cumbersome. 

I was wondering if there is a simple, more elegant solution?  Any ideas?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: IF...THEN...
Reply #1 - Feb 15th, 2012 at 10:51pm
Print Post Print Post  
Well, firstly, you want to use if...then...else.
Secondly, if your element names are predictable, like Process1, Process2, Process3, then you can use loops and @Field.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: IF...THEN...
Reply #2 - Feb 20th, 2012 at 4:57pm
Print Post Print Post  
I looked at the @Field command, but I can't figure out how to make it work.  I want to check step1, step2, step3 through step15 and based on what is in the "step" elements, change the "PFStatement" (PFStatement1, PFStatement2, etc). A sample of the If/Then statements are below.

if step1="A" then PFStatement1 = "Rubber: " +elastomer#+"        Lot #: _________________"
if step1="B" then PFStatement1 = PFS2
if step1="C" then PFStatement1 = "Fabric: " +Fabric#+"        Lot #: _________________"
if step1="D" then PFStatement1 = PFS2
if step1="E" then PFStatement1 = pfs2
if step1="F" then PFStatement1 = pfs2
if step1="G" then PFStatement1 = pfs1
if step1="h" then PFStatement1 = pfs2 + "  Temp: __________   Time: __________ "


I can't figure out how to use a for/next loop to change the variable names.  Would you give me an example of how to create the "step" variable?  I tried using "stepn" (with a for n=1 to 15, next n loop), but that didn't work.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: IF...THEN...
Reply #3 - Feb 20th, 2012 at 5:23pm
Print Post Print Post  
It's hard to test syntax without your forms, but it would go something like this:

Code
Select All
var vStep as String
var vField as String
var vPFS1 as String
var vPFS2 as String
var vElast as String
var vFabric as String
var vLoop as Int

	vPFS1 = pfs1
	vPFS2 = pfs2
	vElast = elastomer#
	vFabric = Fabric#

	For vLoop = 1 To 15
		vStep = @Field("step" + @Str(vLoop))
		vField = "PFStatement" + @Str(vLoop)
		If vStep = "A"
		{
			@Field(vField) = "Rubber: " + vElast + "        Lot #: _________________"
		}
		Else If (vStep = "B") Or (vStep = "D") Or (vStep = "E") Or (vStep = "F")
		{
			@Field(vField) = vPFS2
		}
		Else If (vStep = "C")
		{
			@Field(vField) = "Fabric: " + vFabric + "        Lot #: _________________"
		}
		Else If (vStep = "G")
		{
			@Field(vField) = vPFS1
		}
		Else If (vStep = "H")
		{
			@Field(vField) = vPFS2 + "  Temp: __________   Time: __________ "
		}
	Next 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: IF...THEN...
Reply #4 - Feb 20th, 2012 at 9:01pm
Print Post Print Post  
I've tried your suggestion and it's now doing exactly what I need!

Thanks for the help!!
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: IF...THEN...
Reply #5 - Feb 20th, 2012 at 9:14pm
Print Post Print Post  
NHUser wrote on Feb 20th, 2012 at 9:01pm:
I've tried your suggestion and it's now doing exactly what I need!

Thanks for the help!!

You're welcome!  Smiley
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: IF...THEN...
Reply #6 - Mar 2nd, 2012 at 7:57pm
Print Post Print Post  
How about creating a simple lookup table database or an array and just do a lookup?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: IF...THEN...
Reply #7 - Mar 2nd, 2012 at 8:24pm
Print Post Print Post  
Bob_Hansen wrote on Mar 2nd, 2012 at 7:57pm:
How about creating a simple lookup table database or an array and just do a lookup?


An array - maybe. But an lookup database would require an unnecessary and costly trip to the engine and back, to retrieve information already at hand.
  

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