PDA

View Full Version : help please, variable definition



DirectuX
04-11-2019, 17:20
Hi,

please, can you tell if I made a mistake ?

10090


uses "CONSOLE"

#Include "easing4.tbasicu"

dim etest as easing


WaitKey

10091

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=

Petr Schreiber
04-11-2019, 20:41
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

DirectuX
05-11-2019, 08:40
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() (https://www.thinbasic.com/public/products/thinBasic/help/html/_create.htm)

This is indeed the good practice.

But, again, the error description is very misleading.

Thanks Petr.

NuddNog
10-02-2024, 07:01
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?

ReneMiner
10-02-2024, 08:24
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"))