Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2007, 10:39 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok, in the select statement I don't see any problems, however this CASE is going to be huge (and it isn't very readable). I suggest you break that email code out into one method such as

Sub sendEmail(state)
Dim sEmail
  Select Case state
    Case "NY"
       sEmail = "NY@advancetabco.com"
    Case "MS"
       sEmail= "MS@advancetabco.com"
  End Select

objNewMail.From = sEmail
'Send the email
End

Your above case code becomes:

Select Case sState
    Case "NY"
        sendEmail("NY")
    Case "MS"
        sendEmail("MS")
End Select

Much more readable isn't it? ^^ Also, check to see if your code is ever entering the MS Case by doing a response.write inside of the case. If your text gets wrote to the screen, the problem lies in the email code, not the Case logic.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 16th, 2007, 11:03 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again Dparsons! getting there, almost...
I get a compliation error when using SUB:

<%
Dim warehouse, MyArray
warehouse=Request.Form("warehouse")
MyArray = Split(warehouse,",") 'the delimiter is the comma
For I = 0 to UBound(MyArray)
  sState = MyArray(I)
  SELECT CASE sState
  Sub sendEmail(sState)
Dim sEmail
  Select Case sState
    Case "NY"
       sEmail = "NY@advancetabco.com"
    Case "MS"
       sEmail= "MS@advancetabco.com"
  End Select

objNewMail.From = sEmail
'Send the email

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sEmail
objNewMail.To = rs("email")

objNewMail.Subject = "An Advance Tabco Order From Your NY Factory!"
objNewMail.BodyFormat = CdoBodyFormatHTML
objNewMail.Body = " <BR><img src='http://www.advancetabco.com/pics/AT_emailLogo.jpg' border=0><BR><b>**** EXCESS INVENTORY ORDER! ****</b><BR>If you have any questions regarding this order,<BR>Please contact Customer Service!<BR><BR><b>COMPANY INFO:</b><BR>Order Date: " & Request.Form("date") & "<BR>P.O. Number: " & Request.Form("po") & "<br> " & "Customer Number: " & Request.Form("custcode") & "<BR>"& "Company: " & Request.Form("custname") & "<br>" & "Phone: " & Request.Form("phone") & "<br>" & "Address 1: " & Request.Form("add1") & "<br>" & "Address 2: " & Request.Form("add2") & "<BR>"& "City: " & Request.Form("city") & "<br>"& "State: " & Request.Form("state") & "<br>"&" Zip Code: " & Request.Form("zip") &"<br><br><br><b>SHIPPING INFO:</b><BR>" & "Address 1: " & Request.Form("shipadd1") & "<br>" & "Address 2: " & Request.Form("shipadd2") & "<BR>"& "City: " & Request.Form("shipcity") & "<br>"& "State: " & Request.Form("shipstate") & "<br>"&" Zip Code: " & Request.Form("shipzip") & "<BR>"&" Attention: " & Request.Form("attention") &"<BR>"& Request.Form("warehouse") &"<BR><BR><b>ORDER INFO:</b><BR>"& " "& Request.Form("model") & "<br><br><b>"& "Total Cost: $" & Request.Form("grandtotal") & "</b><br>"
objNewMail.Send
End
Set objNewMail = Nothing
Select Case sState
    Case "NY"
        sendEmail("NY")
    Case "MS"
        sendEmail("MS")
End Select

  response.write myArray(i) & "<br>"

Next
%>

 
Old May 16th, 2007, 11:36 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. I am going to make the assumption that you are new to programming period and not just ASP; is that a correct assumption? Also I noticed a problem with my code.

Your code should look like this:
'This should replace the code i have been helping you with since the beining of the post
Select Case sState
    Case "NY"
        sendEmail("NY", rs("email"))
    Case "MS"
        sendEmail("MS", rs("email"))
End Select

'This should exist in the same file as the above code
Sub sendEmail(state, sEmailTo)
Dim sEmail
Select Case state
    Case "NY"
     sEmail = "NY@advancetabco.com"
    Case "MS"
     sEmail= "MS@advancetabco.com"
End Select

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sEmail
objNewMail.To = sEmailTo

objNewMail.Subject = "An Advance Tabco Order From Your NY Factory!"
objNewMail.BodyFormat = CdoBodyFormatHTML
objNewMail.Body = " <BR><img src='http://www.advancetabco.com/pics/AT_emailLogo.jpg' border=0><BR><b>**** EXCESS INVENTORY ORDER! ****</b><BR>If you have any questions regarding this order,<BR>Please contact Customer Service!<BR><BR><b>COMPANY INFO:</b><BR>Order Date: " & Request.Form("date") & "<BR>P.O. Number: " & Request.Form("po") & "<br> " & "Customer Number: " & Request.Form("custcode") & "<BR>"& "Company: " & Request.Form("custname") & "<br>" & "Phone: " & Request.Form("phone") & "<br>" & "Address 1: " & Request.Form("add1") & "<br>" & "Address 2: " & Request.Form("add2") & "<BR>"& "City: " & Request.Form("city") & "<br>"& "State: " & Request.Form("state") & "<br>"&" Zip Code: " & Request.Form("zip") &"<br><br><br><b>SHIPPING INFO:</b><BR>" & "Address 1: " & Request.Form("shipadd1") & "<br>" & "Address 2: " & Request.Form("shipadd2") & "<BR>"& "City: " & Request.Form("shipcity") & "<br>"& "State: " & Request.Form("shipstate") & "<br>"&" Zip Code: " & Request.Form("shipzip") & "<BR>"&" Attention: " & Request.Form("attention") &"<BR>"& Request.Form("warehouse") &"<BR><BR><b>ORDER INFO:</b><BR>"& " "& Request.Form("model") & "<br><br><b>"& "Total Cost: $" & Request.Form("grandtotal") & "</b><br>"
objNewMail.Send
Set objNewMail = Nothing
End Sub



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 16th, 2007, 03:22 PM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Very close now!!

Ok, my code will only take the first state and mail to that address. I need the email to go to ALL the states listed in that dynamic field. If someone orders 2 products that come my different factories, those factories in those steates ned the same email info.

code:
Dim warehouse, MyArray
warehouse=Request.Form("warehouse")
MyArray = Split(warehouse,",") 'the delimiter is the comma
For I = 0 to UBound(MyArray)
  sState = MyArray(I)
Select Case sState
    Case "NY"
        sendEmail "NY", rs("email")
    Case "MS"
        sendEmail "MS", rs("email")
End Select
Next
Sub sendEmail(state, sEmailTo)
Dim sEmail
 Select Case state
    Case "NY"
     sEmail = "melkin@advancetabco.com"
    Case "MS"
     sEmail= "graphics@advancetabco.com"
     Case "TX"
     sEmail= "melkin@advancetabcohome.com"
 End Select
response.write myArray(i) & "<br>"

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sEmail
objNewMail.To = sEmail

 
Old May 16th, 2007, 04:19 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

hmm. I am not sure I understand. This is very cryptic: I need the email to go to ALL the states listed in that dynamic field.

Please explain.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 17th, 2007, 07:51 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my full code. Based on the fields showing NY, MS it only outputs whatever the first state is. BUT it will write BOTH states to the page and display BOTH states

<%
Dim warehouse, MyArray
warehouse=Request.Form("warehouse")
MyArray = Split(warehouse,",") 'the delimiter is the comma
For I = 0 to UBound(MyArray)
  sState = MyArray(I)
Select Case sState
    Case "NY"
        sendEmail "NY", rs("email")
    Case "MS"
        sendEmail "MS", rs("email")
End Select
response.write myArray(i) & "<br>"

Next
Sub sendEmail(state, sEmailTo)
Dim sEmail
 Select Case state
    Case "NY"
     sEmail = "melkin@advancetabco.com"
    Case "MS"
     sEmail= "graphics@advancetabco.com"
     Case "TX"
     sEmail= "melkin@advancetabcohome.com"
 End Select

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sEmail
objNewMail.To = sEmail

objNewMail.Subject = "An Advance Tabco Order From Your NY Factory!"
objNewMail.BodyFormat = CdoBodyFormatHTML
objNewMail.Body = " <BR><img src='http://www.advancetabco.com/pics/AT_emailLogo.jpg' border=0><BR><b>**** EXCESS INVENTORY ORDER! ****</b><BR>If you have any questions regarding this order,<BR>Please contact Customer Service!<BR><BR><b>COMPANY INFO:</b><BR>Order Date: " & Request.Form("date") & "<BR>P.O. Number: " & Request.Form("po") & "<br> " & "Customer Number: " & Request.Form("custcode") & "<BR>"& "Company: " & Request.Form("custname") & "<br>" & "Phone: " & Request.Form("phone") & "<br>" & "Address 1: " & Request.Form("add1") & "<br>" & "Address 2: " & Request.Form("add2") & "<BR>"& "City: " & Request.Form("city") & "<br>"& "State: " & Request.Form("state") & "<br>"&" Zip Code: " & Request.Form("zip") &"<br><br><br><b>SHIPPING INFO:</b><BR>" & "Address 1: " & Request.Form("shipadd1") & "<br>" & "Address 2: " & Request.Form("shipadd2") & "<BR>"& "City: " & Request.Form("shipcity") & "<br>"& "State: " & Request.Form("shipstate") & "<br>"&" Zip Code: " & Request.Form("shipzip") & "<BR>"&" Attention: " & Request.Form("attention") &"<BR>"& Request.Form("warehouse") &"<BR><BR><b>ORDER INFO:</b><BR>"& " "& Request.Form("model") & "<br><br><b>"& "Total Cost: $" & Request.Form("grandtotal") & "</b><br>"
objNewMail.Send
Set objNewMail = Nothing
End Sub
%>

 
Old May 17th, 2007, 08:09 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. Case Statements ARE case sensitive so if MS is actually ms it is going to be ignored by the case statement.

So do this:

sState = MyArray(I)
sState = ToUpper(sState)

That will convert your string to all upper case. Also, for the sake of argument, place a Response.Write in your Case for MS and see if it executes.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 17th, 2007, 08:13 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The states are pulled from a database, then appears in thei fields. Like a shopping cart, showing what the person is purchasing.in which is ALWAYS uppercase. Dont think this is the issue?

 
Old May 17th, 2007, 08:22 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Quote:
quote:Originally posted by dparsons
Also, for the sake of argument, place a Response.Write in your Case for MS and see if it executes.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 17th, 2007, 08:25 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what was you last post dparsons? I dont see your comments.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract part of String carrie09 Access 6 August 24th, 2007 10:04 AM
set password equal to variable fizzerchris SQL Server 2005 3 April 30th, 2007 01:45 AM
Getting Part of a String needelp Access VBA 4 September 19th, 2006 06:22 AM
Use a variable as a part of an XPath? NotesSensei XSLT 2 July 7th, 2004 04:10 AM
Conversion part of string to date MRvLuijpen Access 5 May 18th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.