change string into an integer
David McFarlane
mcfarla9 at msu.edu
Mon Aug 23 18:51:04 UTC 2010
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.
More information about the Eprime
mailing list