change string into an integer

982 views
Skip to first unread message

Matt Paffel

unread,
Aug 20, 2010, 3:28:17 PM8/20/10
to E-Prime
I have a question regarding the changing logged data from a string
into an integer. I have a little bit of script before a label which
designates the starting values in a trial which is:

Dim vCount As String
Dim pCount As String
Dim InitialValue As String
Dim InitialPie As String
vCount = c.GetAttrib("InitialValue")
pCount = c.GetAttrib("InitialPie")

at the end of a second inline, this little bit of script logs the data
designated in the first.

c.SetAttrib "InitialValue", vCount
c.SetAttrib "InitialPie", pCount

pCount is fine but vCount logs value of Value02, which is a nested
attribute. I would like to have it return the value contained in the
attribute "Value02". I've tried to make this happen a number of
different ways, e.g. CInt(vCount), CStr(CInt(vCount) + 0), etc.) but
each time i get an error message of type mismatch. is there any way to
change this string into an integer?

Michiel Spape

unread,
Aug 23, 2010, 4:37:58 AM8/23/10
to e-p...@googlegroups.com
Hi Mark & group,
I understand that string InitialValue takes a value from attribute InitialValue (i.e. [InitialValue]), which in turn refers to nested attribute [Value02]?
1. Why do you not just have vCount = c.GetAttrib("Value02")?
2. Attributes themselves are like (or just are?) variants, which VisualBasic slightly awkwardly casts depending on their value. Point is:
Dim vCount as integer
vCount = c.GetAttrib ("InitialValue")
vCount = vCount + 1 'or whatever you do with your intial value
c.SetAttrib "InitialValue", vCount
...should also work, as long as the value of [initialvalue] actually was found to be a number
3. All of that should hardly matter, but if vCount has value of "Value02" (rather than [Value2]), my quick guess would be that your nested attribute is wrongly set to be Value02 instead of Value02. So:
vCount = c.GetAttrib("InitialValue") 'is where it goes wrong
...adding the following line should give you a quick check to see whether this is tru:
debug.print cstr(vCount) 'shows value in output log.
If this shows a) nothing at all, or b) a value that is not a number (like 'Value02'), then quite obviously, you cannot change this into an integer. Although, if you like, you can change Value02 into an integer of 02 (i.e. 2) by doing something like
Dim newvalue as integer
Newvalue = cint(mid(vCount,6,2))
(not sure on exact syntax)

Best,
Mich

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

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@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.

Matt Paffel

unread,
Aug 23, 2010, 10:25:52 AM8/23/10
to E-Prime
gotcha, thanks michiel!

On Aug 23, 3:37 am, Michiel Spape <Michiel.Sp...@nottingham.ac.uk>
wrote:
> For more options, visit this group athttp://groups.google.com/group/e-prime?hl=en.

David McFarlane

unread,
Aug 23, 2010, 2:51:04 PM8/23/10
to e-p...@googlegroups.com
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

Michiel Spape

unread,
Aug 24, 2010, 4:31:11 AM8/24/10
to e-p...@googlegroups.com
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

and

-- dkm

--

Reply all
Reply to author
Forward
0 new messages