views:

102

answers:

2

I really need some quick tips here.

I've got this VBScript script which sends an e-mail. And I want to do several checks to see if an attribute is true and if it is, write an additional line in the mail.

How can I do this? This is part of the script:

    obMessage.HTMLBody = ""_
        & "<MENU>"_
        & "<LI type = square>This is a line</i>."_

I want something which looks like this:

    obMessage.HTMLBody = ""_
        & "<MENU>"_
    If statement1 = true Then
        & "<LI type = square>This is an additional line</i>."_
    end if

Preferrably, could some select statements be made? I don't really mind what the code looks like, I just want it to work as soon as possible :)

A: 

Something like:

obMessage.HTMLBody = "Begin Text" & _ 
IIf(statement1 = true, "<LI type = square>This is an additional line</i>.", "") & _
"Further text"

Should work ok.

DAC
It won't work because you are missing the string concatenation operator. Also, VBScript doesn't have the built-in `IIf` function.
Helen
Didn't know VBScript lacked IIF support. Thanks.
DAC
+3  A: 

It will look like spaghetti code no matter how you do it. This is one of the most straight forward approach:

obMessage.HTMLBody = & "<MENU>"

if statement1 then
  obMessage.HTMLBody = obMessage.HTMLBody & "<LI type=""square"">This is a line</LI>."
end if

if statement2 then
  obMessage.HTMLBody = obMessage.HTMLBody & "<LI type=""square"">This is another line</LI>."
end if

However, I suggest that you concatenate the lines to a temporary string, the assign the resulting string to obMessage.HTMLBody, such as:

Dim Foo
Foo = "<MENU>"

if statement1 then
  Foo = Foo & "<LI type=""square"">This is a line</LI>."
end if

.
.
.

obMessage.HTMLBody = Foo
Salman A
Ah ok. So this is actually what I was wondering. Because I cannot do an IF statement inside a string, obviously. So I had to do this outside. Thanx! :)
Kenny Bones