title: Get same nth day of the month in x number of months
body: <p>I am needing some help converting a function from access vba to vb.net.
  The script generates a new date, based on the date entered, and the number of months to be added.
  “If today is the second Tuesday in March, what will be the second Tuesday in 4 months?”</p>
  
  <pre><code>Public Function NdNwk(dType As String, _
          dtSpan As Integer, sDate As Date) As Variant
  '  This Function RETURNS the DAY of WHICH WEEK
  '  (e.g. Second Tuesday of the Month).
  '  FUNCTIONS to be passed to Variables:
  '  gtDoW: Day of the WEEK of the START DATE.
  '  (1 for Sunday, 2 for Monday, etc.)
  '  gtWoM: WEEK of the MONTH of the START DATE.
  '  (1 for First, 2 for Second, etc.)
  '  gtDSTdt: Desired DATE
  '  (generated by the [DateAdd] Function).
  
  '  CALL EXAMPLE: If TODAY is Tuesday, March 10, 2020, 
  ‘  (second Tuesday of March), then using
  '  NdNwk(m, 2, #5/21/2020#)
  '  Would generate the DATE 5/12/2020,
  '  As the SECOND TUESDAY of MAY.
  
      Dim gtDSTdt As Date, gtWoM As Integer, gtDoW As Integer
      Dim iLoop As Integer, iPick As Integer, dstDTdom As Date
  
      gtDoW = Weekday(sDate)
      gtWoM = (Int((Day(sDate) - 1) / 7) + 1)
      gtDSTdt = DateAdd(dType, dtSpan, sDate)
  
      For iLoop = 1 To Day(DateSerial(Year(gtDSTdt), _
                      Month(gtDSTdt) + 1, 0))
  
          dstDTdom = DateSerial(Year(gtDSTdt), _
                  Month(gtDSTdt), iLoop)
  
          If Weekday(dstDTdom, 1) = gtDoW Then
              iPick = iPick + 1
              If iPick = gtWoM Then
                  NdNwk = dstDTdom
                  Exit Function
              End If
  
          End If
      Next
  End Function
  </code></pre>
  
  <p>Any and all help is appreciated here.</p>