Jump to content

Assistance with Visual Basic


Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.