INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Split variable if contains comma

Split variable if contains comma

(OP)
I have a variable which may or may not contain a , (comma).

If it does contain a comma it will always be in the centre of the two parts (without spaces)

I would like to do the following:

CODE

If Variable contains "," Then
Split variable into two parts
Before comma is NewVar1
After comma is NewVar2
End if 

so if the starting value is

W1,Mayfair

I would want this split into two new variables

W1 and Mayfair

RE: Split variable if contains comma

(OP)
Great link there. Thanks a lot. I should be able to get that working quite easily.

RE: Split variable if contains comma

(OP)
In this example pickup = W1,Mayfair

CODE

If instr(pickup,",") Then

a = Split(pickup)
a(0) = Var1
a(1) = Var2

End If 

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 1]'

/quote.asp, line 12


Is there an obvious error here?

RE: Split variable if contains comma

a = Split(pickup, ",")

RE: Split variable if contains comma

And .... If you still want to assign the values to two other variables, it would be
Var1 = a(0)
Var2 = a(1)

RE: Split variable if contains comma

(OP)
Thank you. It's working now.

RE: Split variable if contains comma

@axLW

Quote:

Thank you. It's working now.

In that case it is always good practice to click on that little link on the bottom right of the helpful post that answered your question; the link named "Great post? Star it!".
That way others can more easily identify threads that probably have an answer.
winky smile


"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Split variable if contains comma

(OP)
Noted ;)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close