dc

dc

  • NA
  • 663
  • 0

vb.net indexs of

Nov 26 2016 12:20 AM
In a vb.net 2010 application, I am replacing an initial mail address with other
mailling addresses that a student has. The same exact letter needs to be sent
out to different addresses since a student can has more than 1 guardian. I
am using a span id to locate the addresses that need to be replaced. The literals that need to
be looked at in the span id that needs to be replaced is between span id tags of
Dim startAddrSearch As String = "ADDR_BEG" and  Dim endAddrSearch As String = "ADDR_END"
The following code works, However I am wondering if there is 'better' code that can be setup
to be used and I am hoping you can show me better code that can be used.
#Region "Public Function addMultipleMailAddresses(ByVal StudentAttendanceLetter
As AttendanceLetter) as  AttendanceLetter "
    Public Function addMultipleMailAddresses(ByVal StudentAttendanceLetter As
AttendanceLetter) As AttendanceLetter
        Dim MailAttendanceLetter As AttendanceLetter = New AttendanceLetter()
        Dim _alLetters As AttendanceLetters = New AttendanceLetters()
        MailAttendanceLetter = StudentAttendanceLetter
        Dim _dtMailAddresses As DataTable = New DataTable()
        _dtMailAddresses =
_alLetters.SelectStudentMailingAddresses(StudentAttendanceLetter.StudentLink)
        Dim _attendanceLetterOrig As String = StudentAttendanceLetter.Letter
        Dim _attendanceLetterModified As String = String.Empty
        Dim startAddrSearch As String = "ADDR_BEG"
        Dim endAddrSearch As String = "ADDR_END"
        Dim _attendanceLetterStrbldr As StringBuilder = New StringBuilder
        Dim _attendanceLetterAddr As StringBuilder = New StringBuilder
        Dim txtStartPosition As Integer
        Dim txtEndPosition As Integer
        Dim txtAddrLength As Integer = 0
        txtStartPosition = _attendanceLetterOrig.IndexOf(startAddrSearch)
        txtEndPosition = _attendanceLetterOrig.IndexOf(endAddrSearch)
        txtAddrLength = txtEndPosition - txtStartPosition
        Dim txtOrigAddress As String =
_attendanceLetterOrig.Substring(txtStartPosition, txtAddrLength)
        Dim txtReplaceAddress As String = String.Empty
        If _dtMailAddresses.Rows.Count > 0 Then
            For i = 0 To _dtMailAddresses.Rows.Count - 1
                txtReplaceAddress = String.Empty
                _attendanceLetterModified = String.Empty
                _attendanceLetterModified = _attendanceLetterOrig
                _attendanceLetterAddr.Clear()
                _attendanceLetterAddr.Append("""ADDR_BEG"" > </span>  <p>" +
_dtMailAddresses.Rows(i)(_dtMailAddresses.Columns(2).ColumnName()).ToString() +
"</p>")
                _attendanceLetterAddr.Append("<span id=""ADDR_NEXT"">" +
_dtMailAddresses.Rows(i)(_dtMailAddresses.Columns(3).ColumnName()).ToString() +
", ")
                _attendanceLetterAddr.Append(_dtMailAddresses.Rows(i)(_dtMailAdd
resses.Columns(4).ColumnName()).ToString()
+ " ")
                _attendanceLetterAddr.Append(_dtMailAddresses.Rows(i)(_dtMailAdd
resses.Columns(5).ColumnName()).ToString()
+ "<span id=""")
                txtReplaceAddress = _attendanceLetterAddr.ToString()
                _attendanceLetterModified =
_attendanceLetterModified.Replace(txtOrigAddress, txtReplaceAddress)
                _attendanceLetterStrbldr.Append(_attendanceLetterModified)
                'The following is used by the student letter ssrs report to know
when to print the letter ALF letter on a separate page.
                If i < _dtMailAddresses.Rows.Count - 1 Then
                    _attendanceLetterStrbldr.Append("<spand
id=""END_PAGE""></span")
                End If
            Next
        Else
            _attendanceLetterStrbldr.Append(_attendanceLetterOrig)
        End If
 
        MailAttendanceLetter.Letter = _attendanceLetterStrbldr.ToString()
        Return MailAttendanceLetter
    End Function
#End Region

Answers (1)