Results 1 to 5 of 5

Thread: help please, variable definition

  1. #1

    Exclamation help please, variable definition

    Hi,

    please, can you tell if I made a mistake ?

    testagain0.tbasic
      
    uses "CONSOLE"
    
    #Include "easing4.tbasicu"
    
    dim etest as easing
    
    
    WaitKey
    
    easing4.tbasicu
    uses "math"
    
    
    
    Type easing
    
      totalDuration as DWORD Value = 0
      
    end type
    
    I think it's anormal I get this error :
    Code=173
    Description=TYPE error: missing AS clause in element definition
    Line=7
    LineCode=TOTALDURATION AS DWORD VALUE = 0
    Token=TOTALDURATION
    Additional=
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Sebastian,

    you cannot give member of UDT a default value.

    This is okay:
    Type easing
     
      totalDuration as DWORD
       
    end type
    
    This is not okay:
    Type easing
     
      totalDuration as DWORD VALUE 0
       
    end type
    
    totalDuration will be, as all numeric types, initialized to 0 by default.

    I understand it would be nice to initialize some non-default values, but it is not possible at the moment.

    There are some "close" solutions, like:

    uses "console"
    
    
    type easing
    
    
      totalDuration as dword
    
    
      function _create()
        me.totalDuration = 5 ' some default value
      end function
    end type
    
    
    dim e1 as easing ' -- will initialize with constructor, whoa!
    printl e1.totalDuration
    
    
    waitkey
    
    Petr
    Last edited by Petr Schreiber; 04-11-2019 at 20:48.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Quote Originally Posted by Petr Schreiber View Post

    I understand it would be nice to initialize some non-default values, but it is not possible at the moment.

    There are some "close" solutions, like:
    Right Petr ! I miss this help page about _create()

    This is indeed the good practice.

    But, again, the error description is very misleading.

    Thanks Petr.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  4. #4
    Is it accurate to say that the error description you received was misleading, and were you able to resolve the issue with Petr's suggestion regarding the _create() function?

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,528
    Rep Power
    170
    You can : initialize static udt-elements (these are the same to all udt-members)

    Restriction: only standard-types can be static.

    And the other thing - initializing udt-variables on _Create - seems there was a change - i had a strange error-message explaining to me how i have to initialize the array using Dim X() as Whatever= val1,val2,val3,...
    i am not sure if i understood correct but you can easily reproduce the error
    Type tTest
    X as Long
    Function _Create(byval sName(any) as String)
    msgbox "Names received : " & $ crlf join$(sName, $crlf)
    End function
    End Type
    
    Dim abc as tTest(("Peter", "Paul", "Mary"))
    
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. "The nationalist is by definition an ignoramus."
    By danbaron in forum Shout Box Area
    Replies: 0
    Last Post: 07-03-2012, 21:22
  2. New in next thinBasic: FOR with on-the-fly variable definition
    By ErosOlmi in forum thinBasic vaporware
    Replies: 16
    Last Post: 09-07-2008, 09:39

Members who have read this thread: 5

Posting Permissions

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