469,266 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

If statement based on 'contains a certain string'?

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 = ab*@cats.com

Else
To= db*@cats.com

End If

Appreciate any help here!

Thanks
Jason
Jul 22 '05 #1
9 26307
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...vsfctInStr.asp

WSH Documentation Online:
http://msdn.microsoft.com/library/en...chnologies.asp

WSH Documentation Download:
http://www.microsoft.com/downloads/d...6-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

--

Ray at work
Microsoft ASP/ASP.NET MVP
<ja***@catamaranco.com> wrote in message
news:OZ**************@TK2MSFTNGP10.phx.gbl...
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 = ab*@cats.com

Else
To= db*@cats.com

End If

Appreciate any help here!

Thanks
Jason


Jul 22 '05 #2
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 = "hu**@catamarans.com;
ba*****@catamarans.com,gi****@catamarans.com, jo**********@catamarans.com,
ga***@catamarans.com, ol****@catamarans.com, do***@catamarans.com"

Case Else
objMail.cc = "ba*****@catamarans.com,gi****@catamarans.com,
jo**********@catamarans.com, ga***@catamarans.com, ol****@catamarans.com,
do***@catamarans.com"

End Select

Ray Wrote

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

--

Ray at work
Microsoft ASP/ASP.NET MVP

Jul 22 '05 #3
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

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #4
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

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
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

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #5
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

<ja***@catamaranco.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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

Jul 22 '05 #6
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
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

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

Ray at work
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
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #8
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!

<[REMOVED]> wrote in message news:eq**************@TK2MSFTNGP09.phx.gbl...
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

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

--

Ray at work
Microsoft ASP/ASP.NET MVP


Jul 22 '05 #9
Steven Burn wrote:
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.
Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by ChrisB | last post: by
10 posts views Thread by ale.of.ginger | last post: by
7 posts views Thread by Sunny | last post: by
6 posts views Thread by tshad | last post: by
13 posts views Thread by eman1000 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.