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 April 26th, 2007, 09:47 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default variable to equal part of string

Hi all.

I have an ASP email form that grabs all the data from a form. the form has "Looped" data so the form field called "warehouse" will sometimes pass multiple names in one string...
For example: NY, MS, SC.

These are states my factories are in. If a single state is entered, (no ,looping) then the email sends that factory the order, and works perfectly.
I use;
If warehouse = NY Then
email code blah blah
Else
If factory = MS Then
email code blah blah

The problem is, how can i seprate the feild name when it shows NY, MS, SC all in one string??

Did this make any sense?

 
Old April 26th, 2007, 10:01 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

Split the string based on ,

You can then loop through the individual states that are returned in the string.

Search the net for ASP's Split function.

================================================== =========
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, 09:13 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I finally got a split function to seperate my form field data which has "," seperating them.

But now I dont know how to use each seperated data to do something... For example:

I originally have a form field capturing data looking like this...

NY, MS, TX

Once my Split code runs i get this:

NY
MS
TX

How do I make "NY" go to an ASP email, and have MS go to another email and so on?
I can seem to figure out how to make use of the new split result.

Help! Please!! Thanks!!!
 
Old May 16th, 2007, 09:20 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

Something like this:

For I = 0 to UBound(someArray)
  sState = someArray(I)
  SELECT CASE sState
    Case "NY"
       'Do Something
    Case "MS"
       'Do Something
    'etc, etc, etc.
  END Select
Next

hth

================================================== =========
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, 09:41 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, Here is my code...
I get an error:
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'UBound'

CODE:
<%
Dim warehouse, MyArray
warehouse=Request.Form("warehouse")
MyArray = Split(warehouse,",") 'the delimiter is the comma
For I = 0 to UBound(someArray)
  sState = someArray(I)
  SELECT CASE sState
    Case "NY"
       ' First create an instance of NewMail Object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

' If you like you can use this one line of code to send the mail.
' objNewMail.Send From, To, Subject, Message
' or you can give every value seperate

objNewMail.From = "[email protected]"
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

' After the Send method, NewMail Object become Invalid
' You should set it to nothing to relase the memory

Set objNewMail = Nothing
    Case "MS"
       ' First create an instance of NewMail Object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

' If you like you can use this one line of code to send the mail.
' objNewMail.Send From, To, Subject, Message
' or you can give every value seperate

objNewMail.From = "[email protected]"
objNewMail.To = rs("email")

objNewMail.Subject = "An Advance Tabco Order From Your MS 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

' After the Send method, NewMail Object become Invalid
' You should set it to nothing to relase the memory

Set objNewMail = Nothing
    'etc, etc, etc.
  END Select
Next
%>

 
Old May 16th, 2007, 09:53 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

Oh wow. You copied my code directly from the board and tried to use it without first verifying that the code would work with your code and such. I am not going to tell you how to fix this error, its quite obvious, and I think you need to be a little proactive in resolving your problem and not just copy and pasting Interpeter Errors.

Very rarely do I supply code on the forum that "just works", I am not here to do someones work for them, I am here to give them a hand and help them along. (If they want to HIRE me to do work for them, then ya sure, Ill pony up the source code)

Let me know if you have any other problems.

================================================== =========
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, 10:05 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I understand.

My new problem is that the states are dynamic. They will always change. I will never know what will state will be in the fields. Could be TX, NY or MS, GA etc...
So how do I make the CASE statement dynamic?

 
Old May 16th, 2007, 10:13 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

A case statement IS dynamic. You supply it a parameter that can be anything and it will execute code relevant to that parameter as long as you have provided a case statement for the value of the parameter. To save yourself lines of code, if you have multiple states that you need to do the same processing with, you can use a
Code:
Case Else
which will execute if the parameter supplied does not have a corrosponding CASE.

What I should point out here is that your Case Else will fire whenever there is not a match in the list and this behavior may or may not be desireable. If, for example, you have 5 States that you call processA on and then 5 states that you call processB on, a Case Else is not ideal in your situation and you could do this instead:

CASE "OH", "PA", "NY"
'Do Something
CASE "TX", "CT", CO"
'Do Something
CASE Else
'Default processing.

================================================== =========
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, 10:25 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, no more erros showing, thanks.
But now my second email code isnt processing...
It should being that the form field data is NY, MS

Only the "NY" email goes through. I know you wont code this, but do you see anything wrong??
Next email code for "MS" starts after the CASE "MS".

<%
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"
       ' First create an instance of NewMail Object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = "[email protected]"
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

Set objNewMail = Nothing

    Case "MS"
       ' First create an instance of NewMail Object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

' If you like you can use this one line of code to send the mail.
' objNewMail.Send From, To, Subject, Message
' or you can give every value seperate

objNewMail.From = "[email protected]"
objNewMail.To = rs("email")

objNewMail.Subject = "An Advance Tabco Order From Your MS 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

' After the Send method, NewMail Object become Invalid
' You should set it to nothing to relase the memory

Set objNewMail = Nothing
    'etc, etc, etc.
  END Select
  response.write myArray(i) & "<br>"

Next
%>


 
Old May 16th, 2007, 10:26 AM
Authorized User
 
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I truly appeciate your help. I am thrown into this ASP stuff, learning alot, but always feel I still know little.






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.