View Full Version : SPLIT string error


chris-uk-lad
09-19-2008, 12:27 AM
hi all,

Just kinda bumping this cause its annoying me XD


dim strArray() as variant
dim strName as string

strName = "123-1-Cornwall"

strArray = split(strName, "-")

strname = strAray(1) & " - " & strArray(3)


Problem being it says type mismatch on the line:
strArray = split(strName, "-")
The syntax for splitting the string whereever "-" occurs looks correct to me so not sure why its popping this error. Any thoughts?

Rabbie
09-19-2008, 12:44 AM
If you want to bump a thread use the same thread and add a request.

This code seems to do the job when I tested it. Dim strArray() As String
Dim strName As String
strName = "123-1-Cornwall"
strArray = Split(strName, "-")
strName = strArray(0) & " - " & strArray(2)

stopher
09-19-2008, 12:55 AM
hi all,

Just kinda bumping this cause its annoying me XD


dim strArray() as variant
dim strName as string

strName = "123-1-Cornwall"

strArray = split(strName, "-")

strname = strAray(1) & " - " & strArray(3)


Problem being it says type mismatch on the line:
strArray = split(strName, "-")
The syntax for splitting the string whereever "-" occurs looks correct to me so not sure why its popping this error. Any thoughts?You have spelt strArray as strAray in the last line.

Regards
Chris

stopher
09-19-2008, 01:01 AM
As Rabbie pointed out, the array is zero based so will only have elements 0,1,2 and not 3.
Chris