Hello,
My question is about creating User-Defined Data Types. Is there ANY way possible i can create a User-Defined Data Type that declares a variable of another User-Defined Data Type instead of the Pre-Defined User Types like String, Integer, etc?
The following explains my problem in more detail.
I know to create a User-Defined Data Type at the top of the module before any procedures. Like this:
In a procedure I would then declare a variable as that type using a Dim statement. Like this:Code:Type CustomerInfo Company As String RegionCode As Integer End Type
So, in the first code example above I created a User-Defined Data Type called CustomerInfo. And in that User-Defined Data Type I declared the variable Company and RegionCode as a String and Integer, respectively. String and Integer being, of course, Pre-Defined Data Types.Code:Sub TestDataType Dim Customer(1 To 100) As CustomerInfo End Sub
Then in the next code example I declared the variable in a procedure.
All that works just great.
BUT... Is there any possible way to create a User-Defined Data Type with a variable that is declared not as a Pre-Defined Data Type, like String and Integer, but instead is declared as another User-Defined Data Type?
It's my understanding an example would look like this:
The above would come at the top of the module, before the procedures. The only problem with this is that I didn't declare the variable EveryCompany using a Dim statement. That's something you have to do when using a User-Defined Data Type but not when using a Pre-Defined Data Type. However, the VBE won't allow me to use a Dim statement before the first procedure.Code:Type CustomerInfo Company As String RegionCode As Integer End Type Type EveryCustomer EveryCompany As CustomerInfo End Type
So, in light of this, is there ANY way possible i can create a User-Defined Data Type that declares a variable of User-Defined Data Type instead of the Pre-Defined User Types like String, Integer, etc.
Is there any workaround? I really want to create a hierarchy of Data Types...
Thanks for your help in advance!!! I really appreciate the guidance!
Last edited by CrazyFileMaker; 04-13-2009 at 03:48 AM. Reason: Forgot the Code Tags!
Yes, you can.
Please edit your post to add code tags.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Great!!
Could you or someone elaborate as to how?
Crazy, as my colleague requested earlier, please modify your original thread to enclose any code within CODE tags. In the post editor, you can press the # button on screen to generate code tags, and then place your code between those tags.
You will not get responses from others until you've complied with the request of a moderator (that's part of the forum rules as well).
Oops... Sorry shg! And thanks for pointing that out pjoaquin. At first I misunderstood and actually tagged the post with the word "code"!![]()
Hi
I am afraid I don't really understand what problem you are having - your code should compile without a problem (so please explain exactly what steps you are taking which is causing you problems). The following which is similar also works without issue:
RichardCode:Type Customer ID As Long Nm As String End Type Type SpecialCustomer Spec As Customer End Type Sub test() Dim c As SpecialCustomer c.Spec.ID = 1 c.Spec.Nm = "Richard" Debug.Print c.Spec.ID & " " & c.Spec.Nm End Sub
Richard Schollar
Microsoft MVP - Excel
Richard,
I see now I was actually making a mistake in the procedure. Your example cleared things up for me. Thanks to you, I'm making some great strides now. I appreciate the help!![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks