Urgent help required#<NoMethodError:

prompts5 = [“Span type”]
defaults5 = [“1. Simply supported”]
@t_slab = [“1. Simply supported |2. Interior span |3. End span |4.
Cantilever”]
list5 = [@t_slab]
title5=“Please select the type of the span”
@input_tslab = inputbox prompts5, defaults5, list5,title5

kay_array = [1.0, 1.5, 1.3, 0.4]
@ka = kay_array[(@input_tslab).to_i-1]

If “3. End span” is selected by in the UI, following error is
displayed…

Error: #<NoMethodError: undefined method `to_i’ for ["3. End span
"]:Array>

On Fri, Oct 8, 2010 at 2:05 AM, Atul D. [email protected]
wrote:

If “3. End span” is selected by in the UI, following error is
displayed…

Error: #<NoMethodError: undefined method `to_i’ for ["3. End span
"]:Array>

Without knowing what inputbox does, it seems from the error message
that it’s returning an Array. If you are sure that what you are after
is in the first position of the array, you could do:

@ka = kay_array[@input_tslab.first.to_i-1]

Jesus.

On Thu, Oct 7, 2010 at 7:05 PM, Atul D.
[email protected]wrote:

If “3. End span” is selected by in the UI, following error is
displayed…

Error: #<NoMethodError: undefined method `to_i’ for ["3. End span
"]:Array>

Posted via http://www.ruby-forum.com/.

I assume you are using Google sketchup, and you are invoking this method
Homepage | SketchUp Developer If so,
you
can see they say that it returns nil or an Array, so @input_tslab would
be
an Array. Then, you call (@input_tslab).to_i, first of all, you do not
need
parentheses, they don’t do anything. Second, that means you are invoking
the
to_i method on the array that @input_tslab has received from the
inputbox
method. But to_i is not a method that Arrays have (
class Array - RDoc Documentation).

You need to figure out explicitly what will be returned (ie what does
this
Array actually contain? I know nothing about sketchup, so can only guess
that it is the text contents of the inputbox – if it even has a
textbox.)
And then you need to figure out what you want to do with it. In this
case,
it looks like you want to associate it with a number. Figure out how to
get
from what is returned to the desired number. In your particular example,
it
looks like saying @input_tslav.first.to_i will work, but this might be a
shaky solution, I’d expect if you get more familiar with the API this
will
be easier for you.

Also, make sure to handle the situation where the user cancels the box,
and
nil is returned.