Page 1 of 3 1 2 3 >
Topic Options
#56973 - 04/30/19 12:16 PM need help with PressTalk case statement
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Hi, I need help with finding a value from a long list.

I think I need PPressTalk to use a "case" statement or equivalent method to find the answer rather then creating so many conditions!

The value can be found by checking the "age" and "gender"
For example


if ( age = 50 ) and (gender = M )
benefit = $2500
if ( age = 51 ) and (gender = F )
benefit = $3500
....
....
if ( age = 85 ) and (gender = M )
benefit = $1500

Can you help please.

THANKS
_________________________
Peace

Top
#56974 - 04/30/19 12:33 PM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
Unfortunately, there is no "switch case" in PressTalk.

You could define arrays and scroll through them with a loop.

Here's my idea:

4 arrays:
  • arrMaleAge
  • arrMaleBenefit
  • arrFemaleAge
  • arrFemaleBenefit


Each arr<Male/Female>Age holds the ages you are concern with.
Each arr<Male/Female>Benefit holds the corresponding benefit.

Using a loop, scroll through the arr<Male/Female>Age, find the right age and get the benefit from the arr<Male/Female>Benefit which reside at the same index.

Hope that helps.

Top
#56975 - 04/30/19 02:46 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
This making perfect since, but I'm not that advanced to write the code! if you can find an example on the forum please let me know.

THANKS
_________________________
Peace

Top
#56976 - 04/30/19 02:59 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
I think you misunderstood me, let me refrain my question
I have value age
I have value gender

I need to look and match the age and gender to input the Benefit amount from a table I have.

if (&age = 50) AND (&gender = 'M')
&Benefit := '12,00.00'

I will have to hard code the Benefit amount from a table I have!
_________________________
Peace

Top
#56977 - 04/30/19 03:01 PM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
You will have to hard code everything in the arrays...yes...

Top
#56978 - 04/30/19 05:49 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
can you help me how to start the array then I'll finish it up
just need a jump start smile

THANKS
_________________________
Peace

Top
#56979 - 04/30/19 06:03 PM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
Now that I think of it, you only need 3 arrays. 1 for the ages and 2 for the benefits (male and female)

What you'll find between < > is for you to set, without the < > of course.

Code:
define(&arrAge,arrayinteger,<number of age>)
&arrAge[0] := 40
&arrAge[1] := 41
&arrAge[2] := 42
...

define(&arrMaleBenefit,arraystring, <same number as $arrAge>)
&arrMaleBenegit[0] := '1200.50'
&arrMaleBenefit[1] := '1150.20'
&arrMaleBenefit[2] := '960.20'
...

define(&arrFemaleBenefit,arraystring, <same number as $arrAge>)
&arrFemaleBenegit[0] := '1100.50'
&arrFemaleBenefit[1] := '1350.20'
&arrFemaleBenefit[2] := '1960.20'
...

Top
#56981 - 05/02/19 11:20 AM Re: need help with PressTalk case statement [Re: Sami786]
Damita Offline
OL Newbie

Registered: 10/28/15
Posts: 7
Loc: Georgia
I am trying to write an IF statement that requires a string to be placed in a box within the document and I am having an issue doing this in PlanetPress 7...basically understanding how to do it.

Here is what I would like to write:

IF line 97 is X put in box 55 BUT if line 97 is EMPTY put an X in box 22
_________________________
Damita Knuckles

Top
#56982 - 05/02/19 11:21 AM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
I Damita,

This should be asked in a new thread as to not confused other users when they read this post back.

Thanks.

Top
#56983 - 05/02/19 11:24 AM Re: need help with PressTalk case statement [Re: Jean-Cédric]
Damita Offline
OL Newbie

Registered: 10/28/15
Posts: 7
Loc: Georgia
Okay thank you Jean I will do that. I apologize.
_________________________
Damita Knuckles

Top
#56990 - 05/02/19 03:22 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Jean, can you help me complete this please.

define(&arrAge,arrayinteger,[50,51,52,53,54,55,56,57,58,59])
&arrAge[0] := 50
&arrAge[1] := 51
&arrAge[2] := 52

define(&arrMaleBenefit,arraystring,[50,51,52,53,54,55,56,57,58,59])
&arrMaleBenegit[0] := '1200.50'
&arrMaleBenefit[1] := '1150.20'
&arrMaleBenefit[2] := '960.20'

define(&arrFemaleBenefit,arraystring,[50,51,52,53,54,55,56,57,58,59])
&arrFemaleBenegit[0] := '1100.50'
&arrFemaleBenefit[1] := '1350.20'
&arrFemaleBenefit[2] := '1960.20'

define (&Benefit1Year,integer,0)
define(&i,integer,0)
for(&i,1,1,1)

&Gender := @(105,1,1)
if &Gender = 'M'
&Benefit1Year := &arrMaleBenegit
else

&Benefit1Year := &arrFemaleBenegit
endif
endfor
_________________________
Peace

Top
#56991 - 05/02/19 03:40 PM Re: need help with PressTalk case statement [Re: Sami786]
jouberto Offline
OL Toddler

Registered: 04/18/18
Posts: 32
Hi,

In your age array, you already defined the ages as you declare the array, so no need to put values again in each slot afterwards.

In your benefit arrays, instead of declaring them with the age at each position then overwriting them with the amounts, you should declare them with the amounts from the start
define(&arrMaleBenefit,arraystring,['1200.50','1150.20',...,...,...])

then in your for loop you will want to iterate more than once I'm assuming, and call the array with the index:counter-1
&Benefit1Year := &arrMaleBenegit[&i-1]

Also fix the Benegit typo in your array names wink

Top
#56992 - 05/02/19 03:52 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Jouberto, thank you for your help, it's my first time using arrays and I need further help please if you can.

This is what I got and it's not correct.

...

define(&arrAge,arrayinteger,[50,51,52,53,54,55,56,57,58,59])
define(&arrMaleBenefit,arraystring,[1200.00,1150.20,960.20])
define(&arrFemaleBenefit,arraystring,[1100.50,1350.20,1960.20])


define (&Benefit1Year,integer,0)
define(&i,integer,0)

for(&i,1,1,1)

&Gender := @(105,1,1)

if &Gender = 'M'
&Benefit1Year := &arrMaleBenefit[&i-0]
&Benefit1Year := &arrMaleBenefit[&i-1]
&Benefit1Year := &arrMaleBenefit[&i-2]
&Benefit1Year := &arrMaleBenefit[&i-3]
else

&Benefit1Year := &arrFemaleBenefit[&i-0]
&Benefit1Year := &arrFemaleBenefit[&i-1]
&Benefit1Year := &arrFemaleBenefit[&i-2]
&Benefit1Year := &arrFemaleBenefit[&i-3]
endif
endfor
_________________________
Peace

Top
#56993 - 05/02/19 03:58 PM Re: need help with PressTalk case statement [Re: Sami786]
jouberto Offline
OL Toddler

Registered: 04/18/18
Posts: 32
Many things can be wrong about what you have there. Please define "not correct".

For one thing, you are passing float values to an array of strings. Make sure to pass strings ('123.45').
Your for loop will run only once, change its parameters.
Your IF statements needs the evaluation to be between parentheses.
Your referenced array indexes should only read [&i-1]. The for loop will take care of changing the results.
You are overwriting many times the benefit1year variable. Only assign it once in each portion of the IF statement.

I feel you should definitely open a support ticket so we can understand what you are dealing with, and what you are expecting out of it.

Thanks.

Top
#56994 - 05/02/19 05:12 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
as you mentioned there might be allot of things incorrect which I don't know yet, and I'm learning! thanks to you. If I'm not very far away then I think it would be very nice of you to help me now else I have to contact support. This way I learned solid smile

define(&arrAge,arrayinteger,[50,51,52,53,54,55,56,57,58,59])
define(&arrMaleBenefit,strtofloat,[1200.00,1150.20,960.20])
define(&arrFemaleBenefit,strtofloat,[1100.50,1350.20,1960.20])

define (&Benefit1Year,integer,0)
define(&i,integer,0)

for(&i,1,1,20)

&Gender := @(105,1,1)

if (&Gender = 'M')
&Benefit1Year := &arrMaleBenefit[&i-1]

else

&Benefit1Year := &arrFemaleBenefit[&i-1]

endif
endfor


Edited by Sami786 (05/02/19 05:13 PM)
_________________________
Peace

Top
#56995 - 05/02/19 06:10 PM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
There is a notion that seems to elude you. The idea of using 3 arrays as to get a reference benefit amount based on the age requires that they have the same number of element.

Right now, your:
  • &arrAge has 10 elements.
  • &arrMaleBenefit has 3 elements
  • &arrFemaleBenefit has 3 elements


In order for this to work in a loop instead of a lot of nested if/elseif/else, you need to have the same amount of elements in each array. Once you have found the correct age from your &arrAge, you look in the corresponding gender array of benefit and grab the value that is at the same index(&i).

If multiple age have the same benefit amount, simply repeat the amount multiple time in the gender arrays.

BTW, strtofloat is not a type for array but a conversion function that takes a string and convert into a type float.

Top
#56999 - 05/06/19 04:04 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Hi,

Can you help me further, I tried to make this as simple as possible so I understand then once it's working I can add all the other ages and values accordingly.

Below code gives errors, not liking the arrays! can you please test this with many thanks.

define(&arrAge,arrayinteger,[50,51,52])
define(&arrMale,arraystring,['150','151','152'])
define(&arrFemale,arraystring,['250','251','252'])

define(&Total,integer,0)
define(&i,integer,0)
define(&Gender,string,'0')

for(&i,1,1,3)

&Gender := 'M'

if(&Gender = 'M')
&Total := &arrMale[&i-1]
else
&Total := &arrFemale[&i-1]

endif
endfor
_________________________
Peace

Top
#57005 - 05/07/19 01:28 PM Re: need help with PressTalk case statement [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 475
Loc: Québec, Canada
More something like this:

Code:
define(&myAge,integer,52)

define(&myIndex,integer,0)

define(&arrAge,arrayinteger,[50,51,52])
define(&arrMale,arraystring,['150','151','152'])
define(&arrFemale,arraystring,['250','251','252'])

define(&Total,string,'0')
define(&i,integer,0)
define(&Gender,string,'0')

for(&i,0,1,2)
  if(&arrAge[&i] = &myAge)
    &myIndex := &i
  endif()
endfor()

&Gender := 'M'

if(&Gender = 'M')
    &Total := &arrMale[&myIndex]
else
    &Total := &arrFemale[&myIndex]
endif()
show(&Total)


This would show 152

Top
#57006 - 05/07/19 04:01 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Thank you so much for the script Jean, I'll try this now.

THANKS
_________________________
Peace

Top
#57008 - 05/08/19 05:22 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Hi Jean, Now I'm getting my results smile thanks to you.
I need to do some math and I need your help again with many thanks.

for example:
Benefit := (age * &TotalValue div (1000))

define(&myAge,integer,0)
set(&myAge,strtoint(@(1,1,2)))
define(&myIndex,integer,0)

define(&Benefit,integer,0)

define(&arrAge,arrayinteger,[50,51,52])
define(&arrFirstYearMale,arraystring,['63','67','71'])
define(&arrFirstYearFemale,arraystring,['39','42','44'])

define(&Total,string,'0')
define(&TotalValue,string,'0')
define(&i,integer,0)
define(&Gender,string,'0')

for(&i,0,1,2)
if(&arrAge[&i] = &myAge)
&myIndex := &i
endif()
endfor()

%&Gender := 'F'
&Gender := @(2,1,1)

if(&Gender = 'M')
&TotalValue := &arrFirstYearMale[&myIndex]
else
&TotalValue := &arrFirstYearFemale[&myIndex]
endif()

&Benefit := (inttostr(mul(&TotalValue,&myAge )div(1000)))

%show(&Benefit)


Edited by Sami786 (05/08/19 05:26 PM)
_________________________
Peace

Top
#57011 - 05/09/19 01:33 PM Re: need help with PressTalk case statement [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Thank you for all your great helps Jean, I'll open a separate page for Math.
_________________________
Peace

Top
Page 1 of 3 1 2 3 >