Question about Structures

  • Thread starter Thread starter Jerry Spence1
  • Start date Start date
J

Jerry Spence1

As a base line to my question, a structure can look like this:

Public FullName as xName

Structure xName

Public FirstName as String
Public SecondName as String
Public Title as ?????? (see below)
End Structure

I would like to add into the Structure statement Public Title which could be
a choice of Mr, Mrs, Ms, Sir, Dr etc. How can I form the choices? I would
like it to be like you have "TextBox1.BackColor = " and then as soon as you
type the "=" you get a whole range of choices under Color.White, Color.Black
etc.

So I would type in FullName.Title = TitleConstants.Mr

Hard to explain. I hope you understand what I'm getting at.

-Jerry
 
I would like to add into the Structure statement Public Title which
could be a choice of Mr, Mrs, Ms, Sir, Dr etc. How can I form the
choices? I would like it to be like you have "TextBox1.BackColor = "
and then as soon as you type the "=" you get a whole range of choices
under Color.White, Color.Black etc.

So I would type in FullName.Title = TitleConstants.Mr

Hard to explain. I hope you understand what I'm getting at.

Enums is what you're looking for.

Public Enum Title
Mr
Mrs
Ms
Sir
Dr
End Enum

But considering there are so many variation of titles, you might be
better off leaving it a string.

Also, is there a reason you're declaring a structure instead of a class?
 
As a base line to my question, a structure can look like this:

Public FullName as xName

Structure xName

Public FirstName as String
Public SecondName as String
Public Title as ?????? (see below)
End Structure

I would like to add into the Structure statement Public Title which could be
a choice of Mr, Mrs, Ms, Sir, Dr etc. How can I form the choices? I would
like it to be like you have "TextBox1.BackColor = " and then as soon as you
type the "=" you get a whole range of choices under Color.White, Color.Black
etc.

So I would type in FullName.Title = TitleConstants.Mr

That's an Enum, but it has some drawbacks for your use here, mainly
because Enums are numeric. That means you will have to translate them
back to text for display. I also wonder about the advisability of
having a fixed set of titles. If you run into a situation where you
need a new one you will have to build a new version.

Structure xName
Public FirstName as String
...
Public Title as NameTitle
End Structure

Public Enum NameTitle
Mr
Mrs
Dr
Sir
End Enum
 
Jerry Spence1 said:
As a base line to my question, a structure can look like this:

Public FullName as xName

Structure xName

Public FirstName as String
Public SecondName as String
Public Title as ?????? (see below)
End Structure

I would like to add into the Structure statement Public Title which could be
a choice of Mr, Mrs, Ms, Sir, Dr etc. How can I form the choices? I would
like it to be like you have "TextBox1.BackColor = " and then as soon as you
type the "=" you get a whole range of choices under Color.White, Color.Black
etc.

So I would type in FullName.Title = TitleConstants.Mr

Hard to explain. I hope you understand what I'm getting at.

-Jerry

I have to agree with the previous answers. One of my hobbies is "family
trees" and hence my tag. It's amazing in my family tree how many titles
there are that you left off (deacon, pastor, prisoner :) ). If I were to
hard code stuff, I would be continually updating the enum. Also, I would
prefer a class than the struct.
 
Thanks for your suggestions. I've not played with Enums before.

My example was just for simplicity - my program has nothing to do with
people, but thanks anyway.

-Jerry
 
Back
Top