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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Manipulation problem

Status
Not open for further replies.

Gaff

Programmer
Dec 13, 2001
30
0
0
IE
In my database i'm keeping peoples names in the following format Surname, FirstName. When i bring back these details to the form in VB i want to split the string. I'm using the InStr function to try and split it on the comma. I have no problem assigning just the surname part to a variable as follows:
varname = left$(FullName, mypos - 1)
Where mypos is the postion of the comma from the InStr function.

Now if i try
varname1 = Right$(FullName, mypos + 1) then i get the following error:
"Type declaration character does not match declared data type" I have both varname and varname 1 declared as strings so i don't see what the problem is. If i remove the "$" then i get an "expecting an array" error. If anyone has any insight into this or can suggest an alternative way to manipulate the string i would appreciate it. Thanks
 
Show the variable definitions.

Right needs a length not a start, use
Right$(FullName, Len(FullName) - mypos)
Or
Mid$(FullName, mypos + 1)
You may want to use Rtrim$ on the result if you might have
Firstname, LastName

Be sure to check MyPos for a value of zero in case FullName does not have a comma (empty?). Compare Code (Text)
Generate Sort in VB or VBScript
 
You could also try the split function:

dim sNames as string
dim sTemp() as string
dim sFirst as string
dim sLast as string

sNames = "Williams,Troy"
sTemp = split(sNames,",") 'returns an array starting at 0
sLast = sTemp(0)
sFirst = sTemp(1)


Troy Williams B.Eng.
fenris@hotmail.com

 
John i was still getting the same error when i did it based on len(). I suppose i should have mentioned that the code was in an if then and only gets executed if mypos is greater than one. However the split worked fine. thanks troy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top