VBscript multiple conditions

50 views Asked by At

I'm not a programmer, just a little geek, but I'm trying to build up a vb script for a mailing software I use. It should write in the body of the email something depending on the non-numerical values present in two fields of the records of the various contacts, "company" (so, the company name) and "category". What I exactly need is that if the company name is unknown, it just writes nothing but if it is known, then if the category is VENUE, then it writes down "at " but if it is whatever else category, it writes down "with ". Here is what I'm trying but, naturally, it's not working. Thanks in advance for your help!

if Contact.Field("company") = "" Then
  document.write("")
Else
if Contact.Field("category") = "VENUE" Then
document.write("at " & Contact.Field("company"))

if Contact.Field("category") = "INSTITUTION" Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "ASSOCIATION" Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "EV.ORG." Then
document.write("with " & Contact.Field("company"))

if Contact.Field("category") = "AGENCY" Then
document.write("with " & Contact.Field("company")
1

There are 1 answers

3
Michael Foster On

As Ali Sheikhpour stated in the comments, document.write is for displaying something in a web page, and I'm not sure that is what you want to do. If it is, then the code looks like it would work, but could be simplified:

Dim co
co = Contact.Field("company")
If co = "" Then
    document.write("")
Else
    Select Case Contact.Field("category")
        Case "VENUE"
            document.write("at " & co)
        Case "INSTITUTION", "ASSOCIATION", "EV.ORG.", "AGENCY"
            document.write("with " & co)
        Case Else    ' Any other possibilities? Otherwise, nothing will be written.
    End Select
End If

If this isn't working, I suspect you need to replace the document.write with something else, such as file system manipulation. Just where do you want the output to go?

Also, do you really need to write nothing, or is doing nothing enough? I have no vision as to what the rest of the output is or how it should look.