Expand my Community achievements bar.

SOLVED

if/then statement

Avatar

Level 3

I am designing a form which features 2 columns and I'm looking for a script to populate one column based on data in the other.  Specifically, if grades A, B, C, or D are entered into the left column, then the right column populates with 3 credit hours.

I assumed a fairly simple if/then statement . . . Found one in in the help section of my software, plugged it in, named fields appropriately in the object pallet and within the script.  No go.

JT Terry's book not helpful and my IT guy isn't versed in Java.

Or, maybe I'm making this too hard and FormCalc would be the right choice?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi Milly,

You haven't said what else is in the grade or what the possibilities are A+, B-, etc. AND whether these are in a table row. I will assume they are in a table. I would think about a drop-down box for the grade. That said, this could work for either a drop-down box or a text field containing the grade (depending on how you have the drop down box configured) or this script is easily modified for a drop-down box containing numeric item values in the "Binding" tab. This would lend itself to computing GPA (if that is an ultimate goal).

GradeCredit
A3
C3
F0
A3

The script is easy enough.

Make sure you place this on the calculate event of the "credit" field AND formCalc is the language :

////////////////////////////

     if     (grade < "F")      then

          $ = 3

     else

          $ = 0

     endif

////////////////////////////

if there are + or - grades you could use

////////////////////////////

     if     (Substr(grade,1,1)  <  "F")      then

          $ = 3

     else

          $ = 0

     endif

////////////////////////////

The: Substr(grade,1,1) extracts the 1st letter of the grade and uses that for the comparison

Substitute the name of your grade field for the "grade" above and you should be good to go.

Good luck,

Stephen

View solution in original post

7 Replies

Avatar

Correct answer by
Level 7

Hi Milly,

You haven't said what else is in the grade or what the possibilities are A+, B-, etc. AND whether these are in a table row. I will assume they are in a table. I would think about a drop-down box for the grade. That said, this could work for either a drop-down box or a text field containing the grade (depending on how you have the drop down box configured) or this script is easily modified for a drop-down box containing numeric item values in the "Binding" tab. This would lend itself to computing GPA (if that is an ultimate goal).

GradeCredit
A3
C3
F0
A3

The script is easy enough.

Make sure you place this on the calculate event of the "credit" field AND formCalc is the language :

////////////////////////////

     if     (grade < "F")      then

          $ = 3

     else

          $ = 0

     endif

////////////////////////////

if there are + or - grades you could use

////////////////////////////

     if     (Substr(grade,1,1)  <  "F")      then

          $ = 3

     else

          $ = 0

     endif

////////////////////////////

The: Substr(grade,1,1) extracts the 1st letter of the grade and uses that for the comparison

Substitute the name of your grade field for the "grade" above and you should be good to go.

Good luck,

Stephen

Avatar

Level 3

Thanks so much! I'll give it a try and report back.

Avatar

Level 3

It works!

I might try the drop down box because the letter grade entered must be capitalized for the script to work.  This is not a big deal and otherwise it's great.

Very much appreciated - thanks again

Avatar

Level 7

Milly,

There are a couple of ways to deal with the lower case issue:


1) if you want the "grade" field to convert it so it always displays the upper case:

///////////////////////////////////////////////////  Without + or - grades Put this on the "exit" event of the grade field using formCalc

$ = Upper($)

//////////////////////////////////////////////////// With + or - grades then put this on the "exit" event of the grade field using formCalc

var letter           =  Upper(Substr($,1,1))

var plusMinus   = ""

if      (Len($) > 1)     then

     plusMinus = Substr($,2,1)
endif

$ = letter + plusMinus

//////////////////////////////////////////////////////

2) if you just want the script to work regardless whether its upper or lower (and don't care how the grade is displayed in the "grade" field):

//////////////////////////////////////////////////// With + or - grades   --   Change your existing script to this:

     if     (Substr(Upper(grade),1,1)   <   "F")      then

          $ = 3

     else

          $ =  0

     endif

/////////////////////////////////////////////////// Without + or - grades --   Change your existing script to this:

    if     (Upper(grade) < "F")      then

          $ = 3

      else

          $ = 0

     endif

//////////////////////////////////////////////

You need to do #1 above or #2 above  -- not both

Finally, in the "Object" pallet for your grade field, check the box "Limit Length" to "2" Characters if you use + or - grades and "1" Character if you don't.

Good luck!

Stephen

Avatar

Level 3

Wow! Thanks again. I'm trying to find a class to take somewhere . . .

We don't use + /- . I opted not to do the drop down because I think it'll be quicker/more convenient for users to just tab through quickly, rather than pausing to use the drop down. We're all for whatever makes it easier for the end user - hence the new forms!

I can't thank you enough . . .

~ M

Avatar

Level 7

Opps,

Milly, I erred, use this:

///////////////////////////////  With + or - grades then put this on the "exit"  event of the grade field using formCalc

var letter =  Upper(Substr($,1,1))
var plusMinus   = ""
if      (Len($) > 1)     then
     plusMinus = Substr($,2,1)
endif
$ = Concat(letter,plusMinus)

///////////////////////////////////////

Don't use:  $ = letter + plusMinus

Sorry, got in a hurry,

Stephen

Avatar

Level 3

Really? I tried this from your just previous message and it worked:

1) if you want the "grade" field to convert it so it always displays the upper case:

/////////////////////////////////////////////////// Without + or - grades Put this on the "exit" event of the grade field using formCalc

$ = Upper($)