Skip to main content

For Looping (First, Second, Third, Fourth,.....)

    Set db = Client.OpenDatabase("Working\Management Fees Final.IMD")
    Set task = db.TableManagement
    Set field = db.TableDef.NewField
    field.Name = "FIRST_DDN_MGMT_FEE"
    field.Description = "Added field"
    field.Type = WI_VIRT_NUM
    field.Equation = "-FIRST_DDN_AMOUNT*COL2*FIRST_DDN_DURATION/365"
    field.Decimals = 2
    task.AppendField field
    task.PerformTask
    Set task = Nothing
    Set db = Nothing
    Set field = Nothing
 
How can I put a loop to automate the process for Second, Third.... Upto Sixth(User Importable)?
 

Brian Element Wed, 06/15/2022 - 08:57

There are a few ways you can do it, this example uses arrays to hold the field names:

 Sub Main


	'Create array to hold fields names
	Dim sFieldAmountNames(3) As String
	Dim sFieldDurationNames(3) As String
	sFieldAmountNames(0) = "FIRST_DDN_AMOUNT"
	sFieldAmountNames(1) = "SECOND_DDN_AMOUNT"
	sFieldAmountNames(2) = "THIRD_DDN_AMOUNT"
	sFieldAmountNames(3) = "FOURTH_DDN_AMOUNT"
	
	sFieldDurationNames(0) = "FIRST_DDN_DURATION"
	sFieldDurationNames(1) = "SECOND_DDN_DURATION"
	sFieldDurationNames(2) = "THIRD_DDN_DURATION"
	sFieldDurationNames(3) = "FOURTH_DDN_DURATION"
	
	For i = 0 To 3
	
		Set db = Client.OpenDatabase("Working\Management Fees Final.IMD")
		Set task = db.TableManagement
		Set field = db.TableDef.NewField
		field.Name = "FIRST_DDN_MGMT_FEE" & i
		field.Description = "Added field"
		field.Type = WI_VIRT_NUM
		field.Equation = "-" & sFieldAmountNames(i) & "*COL2*" & sFieldDurationNames(i) & "/365"
		field.Decimals = 2
		task.AppendField field
		task.PerformTask
		Set task = Nothing
		Set db = Nothing
		Set field = Nothing
		
	Next i

End Sub