## Connecting two codes to work together

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

05-11-2012

I am trying to connect the following codes to work together. The way it's constructed one code will work but not the other, this is also true when the code is reversed. The 1st part of the code represents a change in the percentage and the 2nd part of the code calculates the actual percentage.

The percentage is formatted as "00.00% When it exceeds 80.00%, I need it to change color and the same for over 90.00%

if (LTV1st > 80)then

LTV1st.fillColor = "239,122,242"

elseif (\$ > 90) then

LTV1st.fillColor = "110,0,0"

else LTV1st.fillColor = "208,208,208"

endif

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

Both are under the formcalc, calculate event.

Thanks.

#### Accepted Solutions (1)

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I'll take a look at the form. Thanks again. Just to be clear, i'm not dividing 500.000 by 450.000. I'm dividing \$450,000.00 (Four hundred and fifty thousand dollars) into \$500,000.00 (Half a million dollars) to get 90.00%.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

12-11-2012

I finally figured it out. Thanks for starting me down the right path!.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

08-11-2012

You changed the code to:

var LVT = (100 / SalesPrice) * FirstLien.

By adding 100, you solved my problem, thank you. Because another code uses this code it no longer functions. Where can I insert the 100 into the following code?

if(rate1>0 and FirstLien>0 and rate2>=0 and Second>=0 and SalesPrice>0 and LTV1st>=0 and LTV2nd>=0) then Blendrate = (rate1 * FirstLien + rate2 * Second) / SalesPrice / (LTV1st + LTV2nd) ;

endif

Thank you.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

07-11-2012

Any word on my last post?

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I am thankful for your help insolving the color problem. By inserting the code, Look at the yellow highlight (100).

if (FirstLien gt 0 and SalesPrice gt 0) then

var LVT = (100 / SalesPrice) * FirstLien

if (LVT gt 80 and LVT lt 90) then

\$.ui.numericEdit.border.fill.color.value = "239,122,242"

;\$.fillColor = "239,122,242"

elseif (LVT gt 90) then

\$.ui.numericEdit.border.fill.color.value = "180,0,0"

;\$.fillColor = "180,0,0"

else

\$.ui.numericEdit.border.fill.color.value = "210,210,210"

;\$.fillColor = "210,210,210"

endif

\$ = LVT

endif

This caused several other fields not to function correctly. I tried to add * 100 and / 100 to these fields but it does not work.

The only field that was affected was the blendrate field which relies on the calculation of the Firstlien, secondlien and salesprice for weighting. Here is the affected code:

if (rate1>0 and FirstLien>0 and rate2>=0 and Second>=0 and SalesPrice>0 and LTV1st>=0 and LTV2nd>=0)

then Blendrate = (rate1 * FirstLien + rate2 * Second) / SalesPrice / (LTV1st + LTV2nd) ;

endif

Thanks.

MVP

Total Posts

2.7K

Likes

392

488

MVP

Total Posts

2.7K

Likes

392

488
MVP

06-11-2012

Hi,

well I didn't know what your trying to calculate, but now I know.

The problem is when you devide 500.000 by 450.000 the result is always 0.9 not 90.

Even if your display pattern formats the calculated result into 90% the data behind is still 0.9.

That's why the color never changes in that way you are expecting.

I changed the script to calculate it percents.

`var LVT = (100 / SalesPrice) * FirstLien ...`

https://acrobat.com/?d=LRInxmXPdibb0xSRkOruXQ

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I changed the format and re-uploaded the form you fixed, still the only clolor that works is the gray. "208,208,208"

Thanks.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I did fix the formatting back to: num{zzz9.99 %}. This allows me to see the percentage as 85.43% instead of .85 or .8543.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I downloaded the form. I appreciate your effort, however, the form still does not work. For some reason on your form when you divide the firstlien (450,000.00) into the salesprice of (500,000.00) you get .9% instead of 90.00%. Maybe you changed the format. I can fix that but the color does not change. It needs to change above 80.00% and then above 90.00%. As far as the colors bing coded wrong, I can also fix that with kuler.

Thank you.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

Thanks you so much!!! I havent been able to download the form you fixed but I do appreciate your help. The color codes I used came from Kuler. They are

\$.fillColor = "255,13,255"

elseif (\$ gt 90) then

\$.fillColor = "188,40,29"

else

\$.fillColor = "210,210,210"

MVP

Total Posts

2.7K

Likes

392

488

MVP

Total Posts

2.7K

Likes

392

488
MVP

06-11-2012

Hi,

https://acrobat.com/?d=d6lhDJILedI989QOmwhy0A

Btw. you have several script to change the fill colors in the enter events, which all use invalid color values.

`this.fillColor = "400,450,400";`

You need to change those scripts.

The color values can only be between "0,0,0" and "255,255,255".

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I changed the code today to:

Form1.#subform[0].LTV1st::calculate - (FormCalc, client)

if(FirstLien gt 0 and SalesPrice gt 0) then

\$ = FirstLien / SalesPrice

if (\$ gt 80 and \$ lt 90) then

\$.fillColor = "255,13,255"

elseif (\$ gt 90) then

\$.fillColor = "188,40,29"

else

\$.fillColor = "210,210,210"

endif

endif

It still doesnt work. Does it have something to do with the field being calc-Read only?

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

06-11-2012

I dont know how to upload a form to this site. The form can be downloaded from box.net.

The link to the form is: https://www.box.com/s/61n32urjw3xglsjnhjg4

Thanks again.

MVP

Total Posts

2.7K

Likes

392

488

MVP

Total Posts

2.7K

Likes

392

488
MVP

06-11-2012

Not sure what's wrong at your end, the code works for me.

Can you share your form, so I can check it?

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

05-11-2012

Using the following code, the results are the same.

if(FirstLien gt 0 and SalesPrice gt 0) then

\$ = FirstLien / SalesPrice

if (\$ gt 80) then

\$.fillColor = "50,62,49"

elseif (\$ gt 90) then

\$.fillColor = "75,100,75"

else

\$.fillColor = "210,210,210"

endif

endif

The numbers dont calculate and only the 208 fill color changes.

MVP

Total Posts

2.7K

Likes

392

488

MVP

Total Posts

2.7K

Likes

392

488
MVP

05-11-2012

Hi,

well, use this one,

`if (FirstLien gt 0 and SalesPrice gt 0) then          \$ = FirstLien / SalesPrice          if (\$ gt 80 and \$ lt 90) then                    \$.fillColor = "50,62,45"          elseif (\$ gt 90) then                    \$.fillColor = "75,100,75"          else                    \$.fillColor = "210,210,210"          endif      endif`

Attention: Color values are only have values between 0 and 255.

In your last script you used 450 and 500, which is not possible.

NY2CA

Total Posts

59

Like

1

3

NY2CA

Total Posts

59

Like

1

3
NY2CA

05-11-2012

Thank you. The only color that works is the "else" fill color of 208. The form does not calculate or change with the percentage. This is the code i'm using.

if(FirstLien gt 0 and SalesPrice gt 0) then

\$ = FirstLien / SalesPrice

if (\$ gt 80) then

\$.fillColor = "500,62,450"

elseif (\$ gt 90) then

\$.fillColor = "75,100,75"

else

\$.fillColor = "210,210,210"

endif

endif

MVP

Total Posts

2.7K

Likes

392

488

MVP

Total Posts

2.7K

Likes

392

488
`if (FirstLien gt 0 and SalesPrice gt 0) then           \$ = FirstLien / SalesPrice          if (\$ gt 80)then                    \$.fillColor = "239,122,242"          elseif (\$ gt 90) then                    \$.fillColor = "110,0,0"          else                    \$.fillColor = "208,208,208"          endifendif`