seriessix Posted December 30, 2006 Share Posted December 30, 2006 Hi, I have to do a one off project in VB 6 by Monday (legacy system). It's not a language I have had to use before but so far so good. Anyway the last piece is a function that will format a name. I have the function as just a wrapper right now and need to fill in the code. Anyway, it needs to take in a string as input which will be either in Lastname, Firstname format or Firstname Lastname format. If it's in Firstname Lastname (i.e. Firstname space Lastname) it needs to be reformatted to Lastname, Firstname (lastname comma space first name). So the function either returns the input as is or returns the name formatted in the correct way Lastname, Firstname. I have found the length functions and the text from left functions but there not what I need. I need to loop along the name string character by character or something similar. Any pointers would be greatly received! Link to comment Share on other sites More sharing options...
KenH Posted December 30, 2006 Share Posted December 30, 2006 You can do this several way, here are some pointers:- you can find the position of a space (or any char) using InStr() and then use Left() and Right() to get both sides of it. You can split the string using Split(). This builds an array of parts of the original string which are separated by the char you specify as and argument. Link to comment Share on other sites More sharing options...
Wannabeuk Posted December 30, 2006 Share Posted December 30, 2006 im not sure i understand fully, how will you know which order the names are in the input string? Link to comment Share on other sites More sharing options...
seriessix Posted December 30, 2006 Author Share Posted December 30, 2006 Thanks Ken. To answer the above post... They will be either in 'Lastname, Firstname' format or 'Firstname Lastname' format, I need to check the string in the function to decide if I need to reformat or not to 'Lastname, Firstname' format. Link to comment Share on other sites More sharing options...
Wannabeuk Posted December 30, 2006 Share Posted December 30, 2006 right, so the function would look for a , and if that wasnt there would swap over the words and return? Link to comment Share on other sites More sharing options...
JoeP Posted December 30, 2006 Share Posted December 30, 2006 Thanks Ken. To answer the above post... They will be either in 'Lastname, Firstname' format or 'Firstname Lastname' format, I need to check the string in the function to decide if I need to reformat or not to 'Lastname, Firstname' format. The VB Instr() function could be used to spot the comma - instr(sName,",") will return 0 if there's no comma in the string and the position of the comma otherwise. The main thing to watch is whether there might be more than one first name entered. If so, you'd need to work from the end of the string to pick off the last name (in the absence of a comma indicating the name is already in the correct format) . Hope this helps. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.