Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have several user forms that I use to calculate costs of different types of
products. One userform per product. I would like to know the advantages and disadvantages of using variables or my own user types. For example, ' user types in standard module Type Sign SignHeight As Double SignWidth As Double End Type ' userform button code Sub Calculate() Dim EMC As Sign With EMC .SignHeight = TextBox1 + TextBox2 .SignWidth = TextBox3 + TextBox4 End With End Sub VS. Sub Calculate() Dim SignHeight As Double Dim SignWidth As Double SignHeight = TextBox1 + TextBox2 SignWidth = TextBox3 + TextBox4 End Sub -- Cheers, Ryan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
User defined types are useful when you want to store mutiple pies of
information about a single thing. It gives you some of the benefits of creating objects without having to go to the trouble of creating objects. You can pass a single variable which stores multiple pieces of info about that thing. In your example if you wanted to pass the sign to another procedure you would have to pass the height and width and ... as individual variables. If you want to add another variable to your sign you will need to change your sub procedure definitions. As a Type you can pass just the single variable and all of the info goes to the sub. The other benefit is that it makes arrays easier to deal with. Instead of having a multi dimensional array you can have a single dimensional array. There are 2 benefits here. Multi dim arrays are a pain to debug as it is not obvious what each dimension holds. Arrays hold groups of like data so you can not mix strings and numbers unless you declare the array as type variant. If you want to add another dimension with a UDT you just change the UDT definition and you are ready to go. With multi dim array you may need to change counters and such used to traverse through the array. With arrays of UDT's you can redim easily. With Multi dim you can on redim the final dimension which can be limiting. -- HTH... Jim Thomlinson "RyanH" wrote: I have several user forms that I use to calculate costs of different types of products. One userform per product. I would like to know the advantages and disadvantages of using variables or my own user types. For example, ' user types in standard module Type Sign SignHeight As Double SignWidth As Double End Type ' userform button code Sub Calculate() Dim EMC As Sign With EMC .SignHeight = TextBox1 + TextBox2 .SignWidth = TextBox3 + TextBox4 End With End Sub VS. Sub Calculate() Dim SignHeight As Double Dim SignWidth As Double SignHeight = TextBox1 + TextBox2 SignWidth = TextBox3 + TextBox4 End Sub -- Cheers, Ryan |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() User-defined data types are usually convenient when you would otherwise have multiple arrays of varying type to contain data about a item, like a String name, a Long quantity, a floating point value for cost , ... For just containing two items of like type (e.g., height and width), you'd be as well served with a 2D array. -- shg ------------------------------------------------------------------------ shg's Profile: http://www.thecodecage.com/forumz/member.php?userid=13 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=30597 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
clearing a user-defined Type variable | Excel Programming | |||
Type Mismatch: array or user defined type expected | Excel Programming | |||
Clearing all values in a User Defined Type variable | Excel Programming | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
User Defined Type Structure - want it to be variable not numeric literal | Excel Programming |