davidxc davidxc - 2 months ago 11
Vb.net Question

End of statement expected, when writing .Net form to body of an email

I get a End of Statement Expected on:

"by: " & txtTitle.Text & txtFName.Text & txtLName.Text "." & vbCrLf & vbCrLf & _


In this code block for writing a form on the body of an email:

'Set the body
objMM.Body = "Hello. At " + DateTime.Now + " an initial enquiry " & _
"was made " & _
"by: " & txtTitle.Text & txtFName.Text & txtLName.Text "." & vbCrLf & vbCrLf & _
txtAdOne.Text & vbCrLf & _
txtAdTwo.Text & vbCrLf & _
txtAdThree.Text & vbCrLf & _
txtCity.Text & vbCrLf & _
txtPostCode.Text & vbCrLf & _
txtPhone.Text & vbCrLf & _
txtEmail.Text & vbCrLf & _
txtWhenBuy.Text & vbCrLf & _
txtEstBudget.Text & vbCrLf & _
txtIdea.Text & vbCrLf & _
txtMsg.Text & vbCrLf


Have I left something out?

Answer

Using a StringBuilder makes your message a lot clearer and prevents a lot of these little mistakes.

    Dim sb As New System.Text.StringBuilder
    sb.Append("Hello. At {0} an initial enquiry was made by: {1} {2} {3}.", DateTime.Now, txtTitle.Text, txtFName.Text, txtLName.Text).AppendLine()
    sb.AppendLine(txtAdOne.Text)
    ...
    Dim result = sb.ToString()

how would I go about putting a space in between Title, First and Last name

You can do this just by concatenating " " to your string.

"by: " & txtTitle.Text & " " & txtFName.Text & " " & txtLName.Text & "." & vbCrLf & vbCrLf & _

But the first approach is much easier on the eyes