Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split variable if contains comma 1

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
GB
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

 
Great link there. Thanks a lot. I should be able to get that working quite easily.
 
In this example pickup = W1,Mayfair

Code:
If instr(pickup,",") Then

a = Split(pickup)
a(0) = Var1
[b]a(1) = Var2[/b]

End If

Microsoft VBScript runtime error '800a0009'

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

/quote.asp, line 12


Is there an obvious error here?
 
And .... If you still want to assign the values to two other variables, it would be
[tt]Var1 = a(0)
Var2 = a(1)[/tt]
 
@axLW
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.
;-)


"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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top