Select to view content in your preferred language

Need Help with converting a VB code into ArcGIS pro Format

206
2
Jump to solution
06-03-2024 06:33 AM
JamieMorris_SNG
New Contributor II

Hello all, a brief explanation, so i have an old VB Script that i need to convert into use within ArcGIS Pro. 

the script should do the following, if there is a date in the "SurveyDay" field it should add on the number of months in the "Reinspection_Period" field and set a new date into the future within "SurveyDay" field based on the VB Script. 

Regular inspected trees 

12/06/2019 12:05:19 

36 

DateAdd ( "m", "Reinspection_Period" , "SurveyDay" ) 

 

so if the date was 12th June 2019 and we wanted to add 36 months onto this date it would set the date as 12th June 2022 HH:MM:SS the same if the number in this field was either a 6, 12 or any number typed in this "Reinspection_Period" Field

However i cannot get any script to work and anything i try generates <Null> values within the "SurveyDay" Field.

Can anyone help with the conversion from VB into either Arcade or Python expression when using the field calculate on the required column?

Thank you 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The DateAdd function expects the input date first, then the value to be added, then the units. The units have to be spelled out ("months" instead of "m"). This code checks if there is a date in the SurveyDay field, then adds the proper number of months.

 

if (!IsEmpty($feature.SurveyDay)) DateAdd($feature.SurveyDay, $feature.Reinspection_Period, 'months')

 

 

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

The DateAdd function expects the input date first, then the value to be added, then the units. The units have to be spelled out ("months" instead of "m"). This code checks if there is a date in the SurveyDay field, then adds the proper number of months.

 

if (!IsEmpty($feature.SurveyDay)) DateAdd($feature.SurveyDay, $feature.Reinspection_Period, 'months')

 

 

0 Kudos
JamieMorris_SNG
New Contributor II

Thanks for the Help Ken!. i have tried this script out and it functions as intended. 
any undefined values within the Re-Inspection Period (Months) will generate the same date in the column Re_inspection Date which is absolutely fine and expected if there is no number it cannot add on the required number of Months. 
Super Appreciated for your help on this 

0 Kudos