Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default User Type vs. Variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default User Type vs. Variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User Type vs. Variable


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
clearing a user-defined Type variable Chip Pearson Excel Programming 0 December 28th 06 06:04 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Clearing all values in a User Defined Type variable J Streger Excel Programming 2 April 27th 06 08:01 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
User Defined Type Structure - want it to be variable not numeric literal WyoCracker Excel Programming 1 July 21st 03 09:28 PM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"