Reputation: 134
Having difficulty formatting an email I'm sending out. All the data I need is being returned, but some of the vbNewLines are not working.
Here's the code. Note that the large block here at the top works fine, including the & vbNewLine & vbNewLine double space at the end.
Dim arErrors As Array = Array.CreateInstance(GetType(String), 1000)
<<SQL select>>
odbcCmd = New OdbcCommand(strSQL.ToString, odbcConn)
odbcCmd.CommandTimeout = 100000
Rs = odbcCmd.ExecuteReader()
Do While Rs.Read
If Len(Trim(Rs.Item("Cu_Rep_Id").ToString)) = 6 Then
odbcCmd2 = New OdbcCommand(<<SQL Select>>)
odbcCmd2.CommandTimeout = 100000
Rs2 = odbcCmd2.ExecuteReader()
If Rs2.HasRows Then
If Trim(Rs2.Item("Rep_Job_Cd").ToString).IndexOf("SMIC REP, SMIC - WAVERLY, SALES REP - WAVERLY, SALES REP - MADISON") = -1 Then
If CType(Rs2.Item("Rep_Term_Dt"), Date) < Now() Then
arErrors.SetValue("Difference for Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " (Rep terminated on " & Rs2.Item("Rep_Term_Dt").ToString & ")", intMax)
intMax = intMax + 1
Else
arErrors.SetValue("Difference for Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for SMIC Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for Unknown Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Rs2.Close()
ElseIf Len(Trim(Rs.Item("Cu_Rep_Id").ToString)) = 8 Then
odbcCmd2 = New OdbcCommand(<<SQL Select>>)
odbcCmd2.CommandTimeout = 100000
Rs2 = odbcCmd2.ExecuteReader()
If Rs2.HasRows Then
If CType(Rs2.Item("Prog_End_Dt"), Date) < Now() Then
arErrors.SetValue("Difference for CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " CU Status: " & Rs2.Item("Cu_Status").ToString & " (CU terminated on " & Rs2.Item("Prog_End_Dt").ToString & ")", intMax)
intMax = intMax + 1
Else
arErrors.SetValue("Difference for CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " CU Status: " & Rs2.Item("Cu_Status").ToString, intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for Unknown CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Rs2.Close()
Else
If Trim(Rs.Item("Cu_Rep_Id").ToString) <> "" Then
arErrors.SetValue("Invalid Ps_Nr or Contr_Nr: " & Trim(Rs.Item("Cu_Rep_Id").ToString), intMax)
intMax = intMax + 1
End If
End If
Loop
Rs.Close()
If Dts.Variables("DeletedCount").Value <> "0" Then
strBody = strBody & Dts.Variables("DeletedCount").Value & " records were removed from TruComp_Detail prior to load." & vbNewLine & vbNewLine
End If
Again, the above vbNewLine & vbNewLine works perfect as a double space. Below is the offending loop that is giving me fits. The data is returned, but the & vbNewLine doesn't work.
intCount = 0
Do While intCount < intMax
strBody = strBody & arErrors.GetValue(intCount).ToString & vbNewLine
intCount = intCount + 1
Loop
strBody = strBody & "Process complete."
Upvotes: 0
Views: 2342
Reputation: 4420
E-mails use HTML formatting, so you want to use <br/>
instead.
Do While intCount < intMax
strBody = strBody & arErrors.GetValue(intCount).ToString & "<br/>"
intCount = intCount + 1
Loop
Upvotes: 6
Reputation: 4101
I recently had the same exact problem. I got around it by using a StringBuilder and the Append(System.Environment.Newline) method instead of regular string concatenation.
I don't know if it makes any difference, but I was using C#.
In my app a switch to HTML format wasn't feasible because there were a number of other emails sent from the app, all text formatted.
Upvotes: 0