Solved

vbscript function to separate field into multiple variables

Posted on 2011-03-15
4
634 Views
Last Modified: 2012-06-27
i have a form on my asp page for an email address

people are putting multiple addresses in this textbox either separated with a [space] [,] or a [;]

example: bob@yahoo.com;mary@aol.com
or
bob@yahoo.com mary@aol.com
or
bob@yahoo.com,mary@aol.com

i need a function that can separate these into two variables
then assign to session variables

session("email1")
session("email2")


0
Comment
Question by:rmardis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35143905
Hi, try this.

Regards,

Rob.
strUserInput = "bob@yahoo.com;mary@aol.com"
SplitEmails strUserInput

Sub SplitEmails(strEmailString)
	arrAddresses = Array("")
	If InStr(strUserInput, " ") > 0 Then
		arrAddresses = Split(strUserInput, " ")
	ElseIf InStr(strUserInput, ";") > 0 Then
		arrAddresses = Split(strUserInput, ";")
	ElseIf InStr(strUserInput, ",") > 0 Then
		arrAddresses = Split(strUserInput, ",")
	End If
	If arrAddreses(0) <> "" Then
		For intEmail = 0 To UBound(arrAddresses)
			session("email" & intEmail + 1) = arrAddresses(intEmail)
		Next
	End If
End Sub

Open in new window

0
 

Author Comment

by:rmardis
ID: 35144037
The Line

session("email" & intEmail + 1) =

will this result in  session("email"1)

if so

who would i get it to result in session("email1")
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35144291
No, it should interpret as
session("email1") = "emailaddress1"
session("email2") = "emailaddress2"

As long as the session variables can be assigned that way....should work....
0
 

Author Closing Comment

by:rmardis
ID: 35206153
Worked Beautifully!
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question