+ Reply to Thread
Results 1 to 28 of 28

Beginner to User Defined Data Types (Custom Type, UDTs)

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Beginner to User Defined Data Types (Custom Type, UDTs)

    Thanks for the explanation Kyle. +1

    Quote Originally Posted by Kyle123 View Post
    they can be handy when dealing with data with multiple properties and you can pass them around as parameters
    True. On the other hand, I could use global level variables to pass data around instead of using a UDT could I not? As for the data with multiple properties - instead of using a UDT with 5 properties (or whatever they are called in UDTs), I could use 5 global variables.

    Quote Originally Posted by Kyle123 View Post
    tbh I don't usually bother with UDTs, classes are much more useful.
    I'm beginning to think of skipping UDTs and jump straight to classes. From what I've read/heard, they are much more useful!
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Beginner to User Defined Data Types (Custom Type, UDTs)

    Quote Originally Posted by mc84excel View Post
    On the other hand, I could use global level variables to pass data around instead of using a UDT could I not? As for the data with multiple properties - instead of using a UDT with 5 properties (or whatever they are called in UDTs), I could use 5 global variables.
    No, no, and a thousand times no. To take your logic to its natural conclusion, why even have functions at all? You wouldn't need them if everything is a global variable.

    Scope should be kept as small as possible, have a read here about scope http://www.vb6.us/tutorials/variable-scope, then here (http://www.xtremevbtalk.com/showthread.php?t=201646) about why global variables (as opposed to constants) are bad, or at least why they should really only be used as a last resort.

    Quote Originally Posted by mc84excel View Post
    I'm beginning to think of skipping UDTs and jump straight to classes. From what I've read/heard, they are much more useful!
    I think you should cover the basics first and understand good programming practice, without understanding scope, I think public and private members of classes will completely pass you by.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Beginner to User Defined Data Types (Custom Type, UDTs)

    Quote Originally Posted by Kyle123 View Post
    To take your logic to its natural conclusion, why even have functions at all? You wouldn't need them if everything is a global variable..
    I'm afraid I'm having trouble following that logic. Functions return a value (usually as a result of a calculation). Variables can only retain a value.

    Quote Originally Posted by Kyle123 View Post
    Scope should be kept as small as possible, have a read here about scope http://www.vb6.us/tutorials/variable-scope, then here (http://www.xtremevbtalk.com/showthread.php?t=201646) about why global variables (as opposed to constants) are bad, or at least why they should really only be used as a last resort..I think you should cover the basics first and understand good programming practice, without understanding scope, I think public and private members of classes will completely pass you by.
    You don't need to convince me on the coding practice of keeping scopes as small as possible. That is something that I do practice when coding.
    Having said that, I do occasionally use global (well project level ) variables when I need to hold values that will be reused in the same WB session.
    Last edited by mc84excel; 11-19-2013 at 10:41 PM. Reason: Removed example since proven to be incorrect

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is it possible to combine 2 User Defined Types?
    By tom.hogan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2012, 09:08 AM
  2. User-Defined Data Types
    By CrazyFileMaker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2009, 05:23 AM
  3. Editing User Defined Lists - Beginner
    By Julesy9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2006, 08:23 AM
  4. Setting up a Custom type, User-defined, Default Chart
    By Kurt in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-22-2005, 03:45 PM
  5. [SOLVED] How do I share User-Defined Custom Chart Types in Pivot Charts?
    By jantz_question in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 09-20-2005, 09:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1