change string into an integer

Michiel Spape Michiel.Spape at nottingham.ac.uk
Tue Aug 24 08:31:11 UTC 2010


Hi David,
Point taken... This auto-casting is the black art, I tell you! After programming e-prime experiments for a while, I find the VB type of programming makes one extremely careless and lazy, and it seems all other coding skills degenerate because of it...
Cheers,
Mich

Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology


-----Original Message-----
From: e-prime at googlegroups.com [mailto:e-prime at googlegroups.com] On Behalf Of David McFarlane
Sent: 23 August 2010 19:51
To: e-prime at googlegroups.com; e-prime at googlegroups.com
Subject: RE: change string into an integer

Michiel Spape wrote:
>2. Attributes themselves are like (or just are?) variants, which 
>VisualBasic slightly awkwardly casts depending on their value.

Just on that point, context attributes are not variants, they are 
always just ordinary strings.  But do not take my word for that, if 
you run the following code in any inline,

     c.SetAttrib "MyAttrib", 0
     MsgBox TypeName( c.GetAttrib("MyAttrib") )

the message box will indicate that MyAttrib has the type "String", no 
matter what you put in for the value of the attribute.

That said, Visual Basic (and hence E-Basic) will attempt to cast the 
attribute to an appropriate type as it gets used.  E.g., both

     c.SetAttrib "MyAttrib", 1
     MsgBox 2 + TypeName( c.GetAttrib("MyAttrib") )

and

     c.SetAttrib "MyAttrib", 1
     MsgBox TypeName( c.GetAttrib("MyAttrib") ) + 2

produce the numeric result 3, whereas

     c.SetAttrib "MyAttrib", 1
     MsgBox "2" + TypeName( c.GetAttrib("MyAttrib") )

produces the string "21", and

     c.SetAttrib "MyAttrib", 1
     MsgBox TypeName( c.GetAttrib("MyAttrib") ) + 2

produces the string "12".

So it is a safer practice to always explicitly cast attributes to the 
desired type, e.g.

iValue = CInt( c.GetAttrib("MyAttrib") )

-- dkm

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.   Please do not use, copy or disclose the information contained in this message or in any attachment.  Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.



More information about the Eprime mailing list