Results 1 to 8 of 8

Thread: TypeOf and secret Static UDT-members...

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170

    TypeOf and secret Static UDT-members...

    Lets have a look at this code:

    Uses "console"
    
    Type tVec2S
      x As Single
      y As Single
    End Type   
    
    Type tVec3S Extends tVec2S
      z As Single
    End Type 
    
    Dim a As Long
    Dim b As tVec2S
    Dim c As tVec3S
    
    PrintL TypeOf(a)
    PrintL TypeOf(b)
    PrintL TypeOf(c)
    
    WaitKey
    
    It runs without any error, but it does not print anything.
    So TypeOf still is a dead keyword without any functionality.



    Lets think about
    Dim a As Long
    
    built-in primitive type information as Byte, Long, String, Variant etc. are stored internally as some numeral that i can retrieve when i abuse
    thinBasic_VariableGetInfoEx - but thinCore.dll its not intended to be used from within thinBasic-scripts this way.
    And i have to translate the number in retrieved MainType into its String-expression before when i want to

    Dim foo Like TypeOf(a)

    Should not be so difficult to make the already existing keyword TypeOf functional for primitive types

    But what if MainType holds 24? ( = %MainType_UDT )

    So i think an UDT could have some built-in secret static udt-subelement that holds the name of the udt, automatic assigned when the type gets defined.


    In case of the example above it would work like
    Type tVec2S
      Secret Static TypeOf As String = "TVEC2S"  ' automatic done by thinCore
      x As Single
      y As Single
    End Type   
    
    Type tVec3S Extends tVec2S
      Secret Static TypeOf As String = "TVEC3S" ' thinCore should have a separate static for each udt-extension ;)
      z As Single
    End Type 
    
    Dim b As tVec2S
    Dim c As tVec3S
    
    PrintL TypeOf(b)
    PrintL TypeOf(c)
    
    '  equals then:
    
    PrintL b.TypeOf
    PrintL c.TypeOf
    
    Assume "Secret" something be done by thinCore in background when keyword "Type" encountered...

    Currently an issue is that static subelement TypeOf-information of Vec3S overwrites the content of same named static subelement of Vec2S when assigning TypeOf.

    Maybe an idea.
    Last edited by ReneMiner; 25-09-2016 at 09:03.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    It runs without any error, but it does not print anything.
    no i get error with PrintL TypeOf(a) in windows xp and in windows 7. not only display nothing. it is may be windows 10 are more forgiving.
    but TypeOf$ works, it gives OutPut: Numeric.Long for
    Dim a As Long
    PrintL TypeOf$(a)

    i found it in thinBasic_Keywords.ini, the only other places for TypeOf keyword is in Oxygen.

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Yeah, TypeOf$ works!

    But in case example above the output is incorrect for the tVec2S:
    seems the extending type tVec3s overwrites the correct information of the extended type tVec2S
    Guess Eros already used a secret static udt-element
    I think there are missing some Forum-sections as beta-testing and support

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    and i got another problem here. If dimensioning another variable after udt within same function-level it seems the UDTs loose theirs information.

    Uses "console"
    
    Type tVec2S
      x As Single
      y As Single
    End Type   
    
    Type tVec3S Extends tVec2S
      z As Single
    End Type 
    
    Dim a As Long
    Dim b As tVec2S
    Dim c As tVec3S
    
    PrintL TypeOf$(a)
    PrintL TypeOf$(b)
    PrintL TypeOf$(c)
    
    PrintL
    PrintL "now dim another variable d:"
    
    Dim d As String
    
    PrintL TypeOf$(a)
    PrintL TypeOf$(b)
    PrintL TypeOf$(c)
    PrintL TypeOf$(d)
    
    WaitKey
    
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Thanks for reporting.
    I think I've solved all those bugs.

    ATTENTION: only for testing purposes, attached a thinCore.dll you can put into your \thinBasic\ directory replacing your current one.
    I'm undergoing a lot of changes for next thinBasic version.
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    I'll try it after work when the weekend Starts.
    Thanks already, got something in mind😂
    I think there are missing some Forum-sections as beta-testing and support

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    First test, seems now TypeOf and TypeOf$ are the same output.

    For real-life use i need only type-name but not type of type ("Numeric.", "UDT.")
    perhaps you can make TypeOf to return just name and TypeOf$ to give full description? As
    Uses "console"
    
    Dim a As Long
    Dim b As String
    
    PrintL Get_TypeOf(TypeOf(a)) ' TypeOf only return this
    PrintL Get_TypeOf(TypeOf(b))
    
    PrintL TypeOf$(a) ' TypeOf$ as currently
    PrintL TypeOf$(b)
    WaitKey
    
    Function Get_TypeOf(ByVal sTypeOf As String) As String
                
      Dim sResult() As String
      If Split(sTypeOf, ".", sResult) = 2 Then
        Function = sResult(2)
      Else
        ' default "variant" if something invalid occurs 
        ' to avoid run-time-error when Dim ... Like [some stored TypeOf]
        Function = "Variant"
      EndIf          
     
    End Function
    
    Could as well introduce a new Keyword as TypeName but currently we have 2 doing the same...
    Last edited by ReneMiner; 09-10-2016 at 09:27.
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I'm thinking ... also to future when I will be able to give type/subtype of an UDT element or sub-elements.


    TypeOf$ will return a concatenation of information.
    MainTypeOf$ will return the main type: UDT, Numeric, String ...
    SubTypeOf$ will return the subtype: Long, Single, Ext, String, ...


    Than I think something like NameOf$ ...


    Thinking ...
    Thinking ...
    Last edited by ErosOlmi; 10-10-2016 at 17:37.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. TypeOf- ideas
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 45
    Last Post: 29-07-2014, 22:34
  2. The Secret of Oz
    By Charles Pegge in forum Shout Box Area
    Replies: 0
    Last Post: 27-02-2014, 19:12
  3. Members who have read this thread
    By ErosOlmi in forum Web and Forum
    Replies: 0
    Last Post: 17-03-2013, 12:50
  4. Members map
    By ErosOlmi in forum General
    Replies: 11
    Last Post: 15-03-2007, 21:32

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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