Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbCr and Empty Strings

Status
Not open for further replies.

klornpallier

Technical User
Aug 28, 2002
98
GB
Hi,

I would be very greatful if someone could me an idea with this one. I'm sending an Outlook email and printing the values to the body:

oMsg.Body = "Dear " & Me.PREFERREDLabel1.Text & "," & vbCr & vbCr _

Me.DrivingLicErrLabel.Text & vbCr & _
Me.DrivLicExpErrLabel.Text & vbCr & _
Me.RegNoErrLabel.Text


My problem is if Me.DrivLicExpErrLabel.Text = "" then it prints an empty line where I would like it to move Me.RegNoErrLabel.Text up a line. Any advice?
 
Use an IF statement to only include the vbCr if the textbox isn't empty.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Thanks I sort of worked tha bit out myself but cannot seem to get the code right! Using the example could you show me how to do it?
 

You may try [tt]IIF[/tt]:
Code:
DrivingLicErrLabel.Text & vbCr & _
[blue]IIf(Strings.Len(DrivLicExpErrLabel.Text) = 0, "", DrivLicExpErrLabel.Text & vbCr)[/blue] & _
RegNoErrLabel.Text

Have fun.

---- Andy
 
What about doing a replace after the creation of string?
[tt]String = Replace(String, vbcrlf & vbcrlf, vbcrlf)[/tt]

Zameer Abdulla
 

I'd use a stringbuilder.

Code:
Dim sb As New System.Text.StringBuilder

With sb
  .Append("Dear ").Append(Me.PREFERREDLabel1.Text).AppendLine(",")
  .AppendLine("")
  If Me.DrivingLicErrLabel.Text.Trim <> "" Then
    .AppendLine(Me.DrivingLicErrLabel.Text)
  End If
  .AppendLine(Me.RegNoErrLabel.Text)
End With

oMsg.Body = sb.ToString
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top