Home All Groups Group Topic Archive Search About
Author
2 Jun 2006 2:46 PM
Terry Olsen
I send out a daily email to technicians regarding nightly backup logs. I
use the following code to generate the body of the email:

tmpBody += vbCrLf
tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody += vbCrLf
tmpBody += <Specific Server Error Message>

However, I get emails that sometimes have the linebreak before the
Specific Server Error Message, and some that don't.  Here's a sample
email:

----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
canceled a Physical Volume Library operation.

Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
look at the email in a hex editor, it's just a space. Some of the emails
look correct, such as:

----- neb1jwg (3 servers monitored) -----
NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
error on a request to write data to media.Error reported:Data error
(cyclic redundancy check). Warning - A severe error occurred while
reading or writing data.  This job may not have been successfully
completed.Robotic Library: Drive: COMPAQ 1Slot:   A communications
failure has occurred between the Backup Exec job engine and the remote
agent.

Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***

Author
2 Jun 2006 3:51 PM
Mike Lowery
Not sure this will help with your problem, but I would rewrite your code like
this:

tmpBody = vbCrLf
tmpBody &= "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody &= vbCrLf
tmpBody &= <Specific Server Error Message>

When dealing with Strings it's good practice to avoid "+" and use "&" instead
since the former is an arithmetic operator which can cause problems when there
are numbers in your string.

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> wrote in message
news:OzZwnNlhGHA.3424@TK2MSFTNGP05.phx.gbl...
>I send out a daily email to technicians regarding nightly backup logs. I
> use the following code to generate the body of the email:
>
> tmpBody += vbCrLf
> tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
> monitored) -----"
> tmpBody += vbCrLf
> tmpBody += <Specific Server Error Message>
>
> However, I get emails that sometimes have the linebreak before the
> Specific Server Error Message, and some that don't.  Here's a sample
> email:
>
> ----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
> Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
> canceled a Physical Volume Library operation.
>
> Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
> look at the email in a hex editor, it's just a space. Some of the emails
> look correct, such as:
>
> ----- neb1jwg (3 servers monitored) -----
> NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
> error on a request to write data to media.Error reported:Data error
> (cyclic redundancy check). Warning - A severe error occurred while
> reading or writing data.  This job may not have been successfully
> completed.Robotic Library: Drive: COMPAQ 1Slot:   A communications
> failure has occurred between the Backup Exec job engine and the remote
> agent.
>
> Any ideas?
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
2 Jun 2006 4:22 PM
Mythran
Show quote Hide quote
"Terry Olsen" <tolse***@hotmail.com> wrote in message
news:OzZwnNlhGHA.3424@TK2MSFTNGP05.phx.gbl...
>I send out a daily email to technicians regarding nightly backup logs. I
> use the following code to generate the body of the email:
>
> tmpBody += vbCrLf
> tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
> monitored) -----"
> tmpBody += vbCrLf
> tmpBody += <Specific Server Error Message>
>
> However, I get emails that sometimes have the linebreak before the
> Specific Server Error Message, and some that don't.  Here's a sample
> email:
>

I would use String.Format :)

Const BODY_FORMAT As String = _
    vbNewLine & "----- {0} ({1} server{2} monitored) -----" & _
    vbNewLine & "{3}"

Dim tmpBody As String = String.Format( _
    BODY_FORMAT, _
    SupTechs.Item(j), _
    tmpCount, _
    IIf(tmpCount = 1, String.Empty, "s"), _
    <specific server error message here> _
)

HTH :0

Mythran
Author
2 Jun 2006 4:23 PM
Mythran
Show quote Hide quote
"Terry Olsen" <tolse***@hotmail.com> wrote in message
news:OzZwnNlhGHA.3424@TK2MSFTNGP05.phx.gbl...
>I send out a daily email to technicians regarding nightly backup logs. I
> use the following code to generate the body of the email:
>
> tmpBody += vbCrLf
> tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
> monitored) -----"
> tmpBody += vbCrLf
> tmpBody += <Specific Server Error Message>
>
> However, I get emails that sometimes have the linebreak before the
> Specific Server Error Message, and some that don't.  Here's a sample
> email:
>
> ----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
> Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
> canceled a Physical Volume Library operation.
>
> Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
> look at the email in a hex editor, it's just a space. Some of the emails
> look correct, such as:
>
> ----- neb1jwg (3 servers monitored) -----
> NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
> error on a request to write data to media.Error reported:Data error
> (cyclic redundancy check). Warning - A severe error occurred while
> reading or writing data.  This job may not have been successfully
> completed.Robotic Library: Drive: COMPAQ 1Slot:   A communications
> failure has occurred between the Backup Exec job engine and the remote
> agent.
>
> Any ideas?
>
> *** Sent via Developersdex http://www.developersdex.com ***

Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds.  Are you setting the body format type to text, specifically?

HTH again,
Mythran
Author
3 Jun 2006 5:12 AM
Terry Olsen
> Oh, and I forgot to mention, it seems like your email viewer may be
> translating the text as html, therefore removing carriage-returns and
> linefeeds.  Are you setting the body format type to text, specifically?

Yes, I figured it out.  Outlook was "removing extra linefeeds in plain-text
messages."  I cleared that and everything looks fine.  But I do appreciate
the pointers about the strings.  Would a StringWriter or StringBuilder be a
better choice?  For that matter, what's the difference between the two?
Author
3 Jun 2006 7:01 AM
Cor Ligthert [MVP]
Terry,

The first thing to do is in my idea taking the advice of Mike Lowery.

With Option Strict of your code as now can give very unpredictable results.

Cor

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> schreef in bericht
news:OjE2$wshGHA.4404@TK2MSFTNGP05.phx.gbl...
>> Oh, and I forgot to mention, it seems like your email viewer may be
>> translating the text as html, therefore removing carriage-returns and
>> linefeeds.  Are you setting the body format type to text, specifically?
>
> Yes, I figured it out.  Outlook was "removing extra linefeeds in
> plain-text messages."  I cleared that and everything looks fine.  But I do
> appreciate the pointers about the strings.  Would a StringWriter or
> StringBuilder be a better choice?  For that matter, what's the difference
> between the two?
>
Author
3 Jun 2006 10:08 AM
Göran_Andersson
Terry Olsen wrote:
>> Oh, and I forgot to mention, it seems like your email viewer may be
>> translating the text as html, therefore removing carriage-returns and
>> linefeeds.  Are you setting the body format type to text, specifically?
>
> Yes, I figured it out.  Outlook was "removing extra linefeeds in plain-text
> messages."  I cleared that and everything looks fine.  But I do appreciate
> the pointers about the strings.  Would a StringWriter or StringBuilder be a
> better choice?  For that matter, what's the difference between the two?
>
>

A StringBuilder would be the better choise.

A StringBuilder is used to put together a string without making new
copies of the string for each operation.

The += operator might give the impression that a string is added at the
end of an existing string, but that is not so. Strings in .NET are
immutable, e.g. they can not be changed. The += operator concatenates
the strings into a new string, and the reference to the new string
replaces the original string.

For a few short strings the += operator works fine, but the larger the
string grows, the more data has to be copied for each operation. You
should use a StringBuilder when there are more than a few strings, and
always if you don't know beforehand how many strings there will be.

A StringWriter is a TextWriter wrapper around a StringBuilder. One
specific advantage of the StringWriter is when you write different data
types to it. You can specify a culture when you create the StringWriter,
and that cuture is then used to convert things like numbers and dates to
strings when you write them to the StringWriter. When you do the same
using a StringBuilder, it always uses the default culture, or you have
to specify the culture for each value you add using the AppendFormat method.
Author
3 Jun 2006 10:47 AM
Cor Ligthert [MVP]
Terry,

The Stringbuilder (a mutable string (collection) of char objects) would give
you in your problem probably not any advantage. For that are the strings to
short.

A stringwriter gives you the oppurtinity to write whatever to a string
instead of to a file or a stream.

http://www.vb-tips.com/default.aspx?ID=06d9730e-9e33-404c-947a-c891846eaf0b

I hope this gives some direct answers on your latest question.

Cor

Show quoteHide quote
"Terry Olsen" <tolse***@hotmail.com> schreef in bericht
news:OjE2$wshGHA.4404@TK2MSFTNGP05.phx.gbl...
>> Oh, and I forgot to mention, it seems like your email viewer may be
>> translating the text as html, therefore removing carriage-returns and
>> linefeeds.  Are you setting the body format type to text, specifically?
>
> Yes, I figured it out.  Outlook was "removing extra linefeeds in
> plain-text messages."  I cleared that and everything looks fine.  But I do
> appreciate the pointers about the strings.  Would a StringWriter or
> StringBuilder be a better choice?  For that matter, what's the difference
> between the two?
>