Results 1 to 4 of 4

Thread: Returning UDT from Class Function

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Returning UDT from Class Function

    Hi everyone!!!

    According to this page (http://msdn.microsoft.com/vba/Prodinfo/features.asp) this should be possible to do! I've got the following code I'm trying to use in a word vba class module (which has been made public):

    VB Code:
    1. Public Type udtSTYLEFONTINFO
    2.     Bold                As Boolean
    3.     CharacterSpacing    As Integer
    4.     Colour              As String
    5.     Italic              As Boolean
    6.     Size                As Integer
    7.     SmallCaps           As Boolean
    8.     Underline           As Boolean
    9. End Type
    10.  
    11. Public Function GetStyleFontInfo(ByVal strStyleName As String) As udtSTYLEFONTINFO
    12.     GetStyleFontInfo.bold = true
    13. End Sub

    When I hit space after the as part of the function declaration, or try to write the .bold = true part, I get no intellisense for the custom udt appear. If I try to run the code, it highlights the "As udtSTYLEFONTINFO" part stating "User defined type not defined".

    Um, HELP!!!!! please!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    From my shallow skill level, it looks good to me....

    Just as a guess, did you copy and paste that code in? Sometimes VBA will trip out for some reason and re-doing the line breaks will fix things (or retyping things by hand).

    edit: I don't have a clue what you are doing with that code, but I pasted it into an Excel 2003 VBA module. I put the Public Type decleration in the global objects area and passed the function a string. Nothing happened, but I didn't get any errors.
    Last edited by Garratt; Apr 22nd, 2004 at 07:27 AM.

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Thanks for the reply there Garratt I'm trying to use a UDT (a variable which can hold several different data types like integers, strings etc) to hold several pieces of information about a word style (such as whether the style's font is bold (which is a true/false value), the style's indent (which is a numerical value) etc.

    I pasted it then added the line break so it'll look okay on this page. I've managed to sort it a different way now but I'd like to know if anyone can actually get this working/whether this is possible to do as above.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    It looks like it works fine for me. I pasted the public type into a
    module and I put the function into a class. The in the
    ThisWorkbook class I declared a var of my class type and
    instanciated the class. Then I call the function in the class an it
    run ok. I get the intellisense and udt as well.
    VB Code:
    1. 'Standard Module (module1)
    2. Public Type udtSTYLEFONTINFO
    3.     Bold                As Boolean
    4.     CharacterSpacing    As Integer
    5.     Colour              As String
    6.     Italic              As Boolean
    7.     Size                As Integer
    8.     SmallCaps           As Boolean
    9.     Underline           As Boolean
    10. End Type
    11.  
    12. 'Public Class (Class1)
    13. Public Function GetStyleFontInfo(ByVal strStyleName As String) As udtSTYLEFONTINFO
    14.     GetStyleFontInfo.Bold = True
    15. End Function
    16.  
    17. 'ThisWorkbook class
    18. Option Explicit
    19.  
    20. Private classTest  As Class1
    21.  
    22. Private Sub Workbook_Open()
    23.     Set classTest = New Class1
    24.     classTest.GetStyleFontInfo ("Arial")
    25. End Sub
    Is this what you were trying to do?
    BTW, Excel 2003
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width