I assumed you had floats because you said you had floats :)

I've never actually done excel automation with ruby so I'm not even sure
what is stored in the array in your code.   I extracted myself from MS
offices grip long ago so I don't even have excel installed - so I can't even
test it out for you.

If you can get to the raw value and it is compatible with int then .to_i
will do the trick for you.

-andy

On Fri, Jan 30, 2009 at 7:48 AM, <[email protected]> wrote:

>
>
> Hello, and thank you for your answer.
> I did what you said, but it complains about the fact that I can't use
> to_i / convert to integer on an array element.
>
> "undefined method 'to_i' for [1200.0:Array (NoMethodError)".
>
> Is it possible for you to run the program, and maybe come up with some
> workaround, maybe in regards to:
>
> val = worksheet.Range('b2:b4')['Value']
>
> I might do this in another way and possible convert to integer when I
> put the values from Excel into the array, not after?
> Any idea how I can di that?
>
> Cheers
>
>
>
> On 30 Jan, 13:31, Andy Sipe <[email protected]> wrote:
> > I didn't get a chance to run your entire program to see but with just a
> > look...
> >
> > val[count].to_i
> >
> > Takes the value at index count and converts it to and integer and returns
> > that value.  So, you need to store that return:
> >
> > val[count] = val[count].to_i
> >
> > This will change val[count] to be an integer and will discard the
> original
> > value stored in val[count].
> >
> > Hope that helps,
> >
> > -andy
> >
> >
> >
> > On Fri, Jan 30, 2009 at 5:01 AM, <[email protected]> wrote:
> >
> > > Hello, I want to remove decimals from elements in an array, i.e.
> > > convert from Float to Integer and I do this:
> >
> > > val[count].to_i
> >
> > > but it is not working. How do I convert elements in an Array from
> > > Float to Integer? Any suggestions? In Ruby, that is.
> > > My program is pasted in below.
> >
> > > Cheers!
> >
> > > require "watir"
> > > require 'win32ole'
> >
> > > excel = WIN32OLE::new("excel.Application")
> > > workbook = excel.Workbooks.Open("C:\\Programfiler\\Ruby\\FPSdata.xls")
> > > worksheet = workbook.WorkSheets(1)
> >
> > > site = worksheet.Range("a2").Value.to_s
> > > #value = worksheet.Range("b2").Value.truncate.to_s # Bruker truncate
> > > for å fjerne desimaler
> > > val = worksheet.Range('b2:b4')['Value']
> >
> > > test_site = site
> > > belop = val
> >
> > > workbook.Close
> > > excel.Quit
> >
> > > ######  Løkke for å gå gjennom arrayen tilsvarende ganger det finnes
> > > elementer i arrayen  ######
> > > count = 0
> > > while count < (val.length)
> >
> > > #puts "Element:  " + count + "  Verdi:  " + val[count].truncate
> >
> > > val[count].to_i
> >
> > > puts val[count]
> >
> > > ie = Watir::IE.new
> > > ie.goto test_site
> > > ie.text_field(:name, "trust-121212124878").set val[count].to_s
> > > ie.close();
> >
> > > count += 1
> >
> > > end– Skjul sitert tekst –
> >
> > – Vis sitert tekst –
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to