Forum: wxRuby Ruby and Excel Issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F4387b44a3f17713865d010641d3461b?d=identicon&s=25 Jason Shelton (Guest)
on 2008-12-17 17:33
(Received via mailing list)
All,

It seems that Ruby has a problem with using variables in certain
scenarios.  Previously, I was passing a parameter to a class named
'Test' with a function in it named 'go'.  This is the syntax that I
used, Test.new.go('hello')  The function 'go' would open a .xls file
with the parameter in the path, such as C:\hello\data.xls.  Everything
was working fine then.  Now, instead of using the actual string 'hello'
as the parameter, I am using an array element variable, so the syntax is
Test.new.go(array[x]).  Now the 'go' function throws the ''File not
found' error.  In the error message, both the path and file are correct,
so I do not understand why the file cannot be found.  Does anyone have
any idea about what could be going on?  Thanks in advance for any help.
- Shelton
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-12-17 19:00
(Received via mailing list)
Hi

I wasn't clear this was a question about wxRuby, or just a general Ruby
question. If it's the latter, it's better directed to comp.lang.ruby
newsgroup / ruby-talk mailing list.

Jason Shelton wrote:
> It seems that Ruby has a problem with using variables in certain
> scenarios.

Don't take this the wrong way - but if Ruby had a defect by which it
randomly changed the value of variables under your nose, someone would
probably have run into it before and reported it...

> Previously, I was passing a parameter to a class named 'Test' with a
> function in it named 'go'.  This is the syntax that I used,
> Test.new.go('hello')  The function 'go' would open a .xls file with
> the parameter in the path, such as C:\hello\data.xls.  Everything was
> working fine then.  Now, instead of using the actual string 'hello' as
> the parameter, I am using an array element variable, so the syntax is
> Test.new.go(array[x]).  Now the 'go' function throws the ''File not
> found' error.  In the error message, both the path and file are
> correct, so I do not understand why the file cannot be found.

Hard to know what might be going on without sight of the code. There
*must* be some difference between the literal string 'hello' and the
array element.

Things to suspect are: the array index 'x' doesn't point to a valid
member; the input value array[x] is not what you expect - perhaps it
contains spaces or newlines or wrong-case characters so that it doesn't
stand out as wrong; the 'go' method is altering the parameter in some
unanticipated way.

I would recommend writing some tests for your class, so you can verify
your assumptions about how that class works with different input. Give
it both correct and incorrect input parameters, to check that it works
in the first case and fails gracefully in the second. Writing tests can
also help structure your code better; specifically to GUI code, it can
help identify where too much application logic is being moved into the
GUI layer. There are numerous testing frameworks for ruby; personally I
find 'test/unit', included by default with Ruby, does everything I need,
but you may wish to explore other options (eg rspec).

hth
a
This topic is locked and can not be replied to.