[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Displaying HTML with OLE

RichardOnRails

1/23/2007 9:52:00 PM

Hi,

I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The
Ruby Way,2nd ed., with modified HTML (which I tested independently).
When I run it in a Command Window, I get:

K:\_Projects\Ruby\_Ruby_Techniques\Win32Ole>TestingOleWithHtml.rb
K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in
`method_missing': document (WIN32OLERuntimeError)
OLE error code:80004005 in <Unknown>
<No Description>
HRESULT error code:0x80020009
Exception occurred. from
K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22

Any ideas?

Thanks in Advance,
Richard

# Source: The Ruby Way, 2nd ed., pg. 585

require "win32ole"

msg = "Hello, World"

html = <<EOF
<html>
<head>
<title>Hello, World</title>
</head>
<body>
<h1><center>My "Hello, World" Demo</center></h1>
<p>
<h2><center>Not much of a demo, eh?</center></h2>
</body>
</html>
EOF

ie = WIN32OLE.new("InternetExplorer.Application")

ie.document.open # <====
Line 22
ie.document.write html
ie.document.close

sleep 5
quit

4 Answers

David Mullet

1/24/2007 12:04:00 AM

0



On Jan 23, 4:51 pm, "Richard"
<RichardDummyMailbox58...@USComputerGurus.com> wrote:
> Hi,
>
> I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The
> Ruby Way,2nd ed., with modified HTML (which I tested independently).
> When I run it in a Command Window, I get:
>
> K:\_Projects\Ruby\_Ruby_Techniques\Win32Ole>TestingOleWithHtml.rb
> K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in
> `method_missing': document (WIN32OLERuntimeError)
> OLE error code:80004005 in <Unknown>
> <No Description>
> HRESULT error code:0x80020009
> Exception occurred. from
> K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22
>
> Any ideas?
>
> Thanks in Advance,
> Richard
>
> # Source: The Ruby Way, 2nd ed., pg. 585
>
> require "win32ole"
>
> msg = "Hello, World"
>
> html = <<EOF
> <html>
> <head>
> <title>Hello, World</title>
> </head>
> <body>
> <h1><center>My "Hello, World" Demo</center></h1>
> <p>
> <h2><center>Not much of a demo, eh?</center></h2>
> </body>
> </html>
> EOF
>
> ie = WIN32OLE.new("InternetExplorer.Application")
>
> ie.document.open # <====
> Line 22
> ie.document.write html
> ie.document.close
>
> sleep 5
> quit

Try navigating to a page before writing to the Document object. The
code below worked for me...

ie = WIN32OLE.new("InternetExplorer.Application")
ie.Visible = 1
ie.Navigate('about:blank')
sleep(1) while ie.ReadyState != 4
ie.Document.open
ie.Document.write html
ie.Document.close
sleep 5
quit

Hope that helps.

Mully

RichardOnRails

1/24/2007 3:50:00 AM

0

Hi David,

Your technique worked perfectly. I was disappointed by my system's
performance, however.

I used a .rbw extension to avoid the creation of a temporary Command
Window. Is there a simple approach to putting up a graphical progress
bar that:
-- loops while checking to see whether the IE window had opened yet;
and
-- closes when the IE window is displayed?

Best wishes,
Richard

On Jan 23, 7:04 pm, "mully" <david.mul...@gmail.com> wrote:
> On Jan 23, 4:51 pm, "Richard"
>
>
>
> <RichardDummyMailbox58...@USComputerGurus.com> wrote:
> > Hi,
>
> > I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The
> > Ruby Way,2nd ed., with modified HTML (which I tested independently).
> > When I run it in a Command Window, I get:
>
> > K:\_Projects\Ruby\_Ruby_Techniques\Win32Ole>TestingOleWithHtml.rb
> > K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in
> > `method_missing': document (WIN32OLERuntimeError)
> > OLE error code:80004005 in <Unknown>
> > <No Description>
> > HRESULT error code:0x80020009
> > Exception occurred. from
> > K:/_Projects/Ruby/_Ruby_Techniques/Win32Ole/TestingOleWithHtml.rb:22
>
> > Any ideas?
>
> > Thanks in Advance,
> > Richard
>
> > # Source: The Ruby Way, 2nd ed., pg. 585
>
> > require "win32ole"
>
> > msg = "Hello, World"
>
> > html = <<EOF
> > <html>
> > <head>
> > <title>Hello, World</title>
> > </head>
> > <body>
> > <h1><center>My "Hello, World" Demo</center></h1>
> > <p>
> > <h2><center>Not much of a demo, eh?</center></h2>
> > </body>
> > </html>
> > EOF
>
> > ie = WIN32OLE.new("InternetExplorer.Application")
>
> > ie.document.open # <====
> > Line 22
> > ie.document.write html
> > ie.document.close
>
> > sleep 5
> > quitTry navigating to a page before writing to the Document object. The
> code below worked for me...
>
> ie = WIN32OLE.new("InternetExplorer.Application")
> ie.Visible = 1
> ie.Navigate('about:blank')
> sleep(1) while ie.ReadyState != 4
> ie.Document.open
> ie.Document.write html
> ie.Document.close
> sleep 5
> quit
>
> Hope that helps.
>
> Mully

David Mullet

1/25/2007 1:43:00 AM

0


On Jan 23, 10:50 pm, "Richard"
<RichardDummyMailbox58...@USComputerGurus.com> wrote:
> Hi David,
>
> Your technique worked perfectly. I was disappointed by my system's
> performance, however.
>

Richard-

Try reducing the sleep interval...

sleep(1) while ie.ReadyState != 4

....to...

sleep(0.1) while ie.ReadyState != 4

Mully

RichardOnRails

1/26/2007 2:25:00 AM

0

Hi David,

> Try reducing the sleep interval...
>
> sleep(1) while ie.ReadyState != 4

That sped it up a lot. Of course, a couple of test runs doesn't prove
much, e.g. my virus checker might have been running unattended in
background yesterday.

Nevertheless, this is a useful technique for me.

Again, many thanks.
Richard

On Jan 24, 8:42 pm, "mully" <david.mul...@gmail.com> wrote:
> On Jan 23, 10:50 pm, "Richard"
>
> <RichardDummyMailbox58...@USComputerGurus.com> wrote:
> > Hi David,
>
> > Your technique worked perfectly. I was disappointed by my system's
> > performance, however.Richard-
>
> Try reducing the sleep interval...
>
> sleep(1) while ie.ReadyState != 4
>
> ...to...
>
> sleep(0.1) while ie.ReadyState != 4
>
> Mully