Calculate end date based on drop-down list

Avatar

Avatar

thaong

Avatar

thaong

thaong

28-03-2020

I have a drop-down list with 8 different programs that the company is delivering and 2 date/ time fields called StartDate and EndDate. Depending on what is selected from the drop-down list, the EndDate is calculated accordingly. I have the scripts here but it doesn't seem to work. Can you help me point out where I got wrong please? Many thanks

 

form1.#subform[0].StartDate::exit - (FormCalc, client)

 

var date = Date2Num(StartDate.formattedValue,"DD/MM/YYYY")
var value = Programs.boundItem(xfa.event.newText)
if (value == "1") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "2") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "3") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "4") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "5") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") else

if (value == "6") then
EndDate.formattedValue = Num2Date(date + 457,"DD/MM/YYYY") else

if (value == "7") then
EndDate.formattedValue = Num2Date(date + 639,"DD/MM/YYYY") else

if (value == "8") then
EndDate.formattedValue = Num2Date(date + 548,"DD/MM/YYYY") 

endif

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

28-03-2020

The formattedValue is defined by a display pattern. You can't set it via scripting. 

And never use reserved names such as "value" or "date" for variables, this can cause unexpected results. 

 

Here's a much shorter FormCalc script you can put into the calculate event of the EndDate field.

var nDate = Date2Num(StartDate.formattedValue,"DD/MM/YYYY")
var nSelection = Programs
var nAddDays = Choose(nSelection, 548, 457, 548, 457)
$ = Num2Date(Sum(nDate, nAddDays),"DD/MM/YYYY")

 

Answers (0)