If statement based on 'contains a certain string'?

G

Guest

Is it possible to construct a CDO.To statement based on the value of an
incoming form drop down list which contains any word such as "ChangeStatus:"

How would I construct the IF statement to isolate the 'string' in the
incoming variable to allow a branching statement:

If Request.form("ChangeStatue") containts the string "Sales Alert" Then

'//
Else
'//

End If

Would it use something like Instr(Request.form("ChangeStatus"),
"SalesAlert") Then

To = (e-mail address removed)

Else
To= (e-mail address removed)

End If

Appreciate any help here!

Thanks
Jason
 
R

Ray Costanzo [MVP]

Instr returns an integer representing the [relative] starting
position in a string of the string that you're looking for. Example.

Instr("cat", "a") = 2
Instr("dog", "a") = 0 ''doesn't exist

So, if the value > 0, then it's found.

If Instr(Request.Form("ChangeStatus"), "Sales Alert") > 0 Then...

Note that the default comparison method is binary, meaning it's case
sensitive.

InStr Documentation Online:
http://msdn.microsoft.com/library/en-us/script56/html/vsfctInStr.asp

WSH Documentation Online:
http://msdn.microsoft.com/library/en-us/script56/html/vtoriMicrosoftWindowsScriptTechnologies.asp

WSH Documentation Download:
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9

A more graceful way of handling your situation may be:

sValue = UCase(Request.Form("ChangeStatus"))

Select Case True
Case Instr(sValue, "Sales Alert") > 0
''do something
Case Instr(sValue, "Theft Alert") > 0
''do something else
End Select
 
G

Guest

Thanks, Ray, but it does not appear to be working.

ChangeStatus = UCase(Request.Form("ChangeStatus"))
Response.write "<br><bR>" & ChangeStatus & "<br><br>"

'//SALES STAGE ALERT: Under Offer

Select Case ChangeStatus

Case Instr(ChangeStatus, "SALES") > 0
objMail.cc = "(e-mail address removed);
(e-mail address removed),[email protected], (e-mail address removed),
(e-mail address removed), (e-mail address removed), (e-mail address removed)"

Case Else
objMail.cc = "(e-mail address removed),[email protected],
(e-mail address removed), (e-mail address removed), (e-mail address removed),
(e-mail address removed)"

End Select



Ray Wrote
 
E

Evertjan.

wrote on 05 jan 2005 in microsoft.public.inetserver.asp.general:
Thanks, Ray, but it does not appear to be working.

ChangeStatus = UCase(Request.Form("ChangeStatus"))
Response.write "<br><bR>" & ChangeStatus & "<br><br>"

'//SALES STAGE ALERT: Under Offer

Select Case ChangeStatus

Case Instr(ChangeStatus, "SALES") > 0

The above is not logical and should be:

Select Case True
Case Instr(ChangeStatus, "SALES") > 0

=====================

even better use if..then..else..,
That gives less mistakes for the beginner:

If Instr(ChangeStatus, "SALES") > 0 then
...
Else
...
End If
 
G

Guest

Ahhhhhhhhhh....okay..it works but I am finding that my Case Else statement
is not working...

Thus, if none of the top two conditions are true I wish to default to
'
//code
.......
Case Else
MasterList = MasterList & MasterList

I also tried:

Case False
MasterList = MasterList & MasterList

Is this by design?

Thanks
Jason
 
R

Ray Costanzo [MVP]

Well, considering that the SELECT CASE portion is qualified with "true" that
means that whichever case is true should be executed. Since false is not
true, that will not be executed. Instead of case false, use the built-in
Case Else.


Select Case True
Case 1 = 2
Response.write "Huh?"
Case 3 > 302923
Resposne.Write "Really?"
Case Else
Response.Write "I'm else."
End Select

Ray at home
 
E

Evertjan.

Ray Costanzo [MVP] wrote on 05 jan 2005 in
microsoft.public.inetserver.asp.general:
Well, considering that the SELECT CASE portion is qualified with
"true" that means that whichever case is true should be executed.
Since false is not true, that will not be executed. Instead of case
false, use the built-in Case Else.


Select Case True
Case 1 = 2
Response.write "Huh?"
Case 3 > 302923
Resposne.Write "Really?"
Case Else
Response.Write "I'm else."
End Select

Which means it can be done this way as I suggested, but:

It seems that the case statement this way is not very intuitive,
so I suggest to the OP to use old faithfull if..then instead:

if 1 = 2 then
Response.write "Huh?"
elseif 3 > 302923 then
Response.Write "Really?"
else
Response.Write "I'm else."
end if
 
R

Ray Costanzo [MVP]

Yeah, either way. Personally, I'm not much of a fan of elseif, but
to each his own.

Ray at work
 
S

Steven Burn

On a sidenote, posting e-mail address's on forums/newsgroups etc etc etc, is
highly unwise as it opens you up to a whole collection of spam and their
bot's.

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Thanks, Ray, but it does not appear to be working.

ChangeStatus = UCase(Request.Form("ChangeStatus"))
Response.write "<br><bR>" & ChangeStatus & "<br><br>"

'//SALES STAGE ALERT: Under Offer

Select Case ChangeStatus

Case Instr(ChangeStatus, "SALES") > 0
objMail.cc = "[REMOVED"

Case Else
objMail.cc = "[REMOVED]"

End Select



Ray Wrote
 
D

Dave Anderson

Steven said:
On a sidenote, posting e-mail address's on forums/newsgroups etc etc
etc, is highly unwise as it opens you up to a whole collection of
spam and their bot's.

I'm not sure I agree. You can reply directly to this address and I will get
your post. True, I get a fair amount of garbage through it, but no more than
from any of my other addresses, each of which I have protected jealously
over the years.

So even though I use Spammotel[1] to generate throwaway addresses and
Bugmenot[2] (one of the *BEST* Firefox extensions ever) to browse the web
somewhat anonymously, I still get a ton of spam, just like everyone[3].

On a side note, my former employer finally cut off a huge source of spam for
me personally -- my old employee account. When I left, I set it up to
forward to my new address, and my employer forgot to shut it down until a
recent audit -- and even then, they sent notice that the account would be
closing in 6 weeks.

I left there almost 5 years ago. I haven't used that address for 5 years,
but it still gets buckets and buckets of spam.



[1] http://spammotel.com/
[2] http://bugmenot.com/
[3] But since Spammotel can customize the Subject lines before forwarding
messages, I can easily filter them into quarantine. I do this rather than
simply delete for two reasons: (1) so people really can reach me directly,
and (2) in case I ever decide to act on my disclaimer.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top