M
Moran, Craig M (BAH)
This is my first post. My apologies if I do something wrong. I am using
Ruby 1.8.0-10 with the Fox GUI on a Windows 2000 box to script Excel. I am
having a problem using the ole_free win32ole command. ole_free is designed
to release the resources that Excel was using when it is called. It works
fine when called from the original procedure. However, if a separate
procedure is called from the original, ole_free does not behave as intended.
I am including code for 3 separate files (TestGUI.rbw, TestGUI.rb, and
TestAPP.rb). Put these files in the same directory and run TestGUI.rbw.
Click the 'Test' button to execute the program. You will see that Excel is
launched twice in two different manners then closed using ole_free; once
from the original procedure and once from a nested procedure. If you check
your Task List before exiting the program, you will see that the instance of
Excel that was launched from the nested procedure still exists in the Task
List even though ole_free was called. Is there a way to make this work
properly?
Here are the files:
Save this as TestGUI.rbw:
#/usr/bin/env ruby
# Title: TestGUI.rbw
require 'win32ole'
require 'TestAPP.rb'
require 'TestGUI.rb'
def run
application = FXApp.new("Test GUI")
application.init(ARGV)
ButtonWindow.new(application)
application.create
application.run
end
run
# end TestGUI.rbw
Save this as TestGUI.rb:
#/usr/bin/env ruby
# Title: TestGUI.rb
require 'fox'
include Fox
class ButtonWindow < FXMainWindow
def initialize(app)
super(app, "Test", nil, nil, DECOR_ALL, 100, 100, 0, 0)
menubar = FXMenubar.new(self, LAYOUT_FILL_X)
filemenu = FXMenuPane.new(self)
FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(),
FXApp::ID_QUIT)
FXMenuTitle.new(menubar, "&File", nil, filemenu)
FXHorizontalSeparator.new(self,
LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X)
matrix = FXMatrix.new(self, 3,
MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y)
statusbar = FXStatusbar.new(self,
LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)
FXVerticalSeparator.new(self,
LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|SEPARATOR_GROOVE)
group1 = FXGroupBox.new(matrix, "Test",
GROUPBOX_TITLE_CENTER|FRAME_RIDGE|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|LAYOUT_
CENTER_X|LAYOUT_CENTER_Y)
testButton = FXButton.new(group1, "&Test", nil, nil, 0,
FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
testButton.connect(SEL_COMMAND, methodonCmdTest))
end
def create
super
show(PLACEMENT_SCREEN)
end
end
# end TestGUI.rb
Save this as TestAPP.rb:
#/usr/bin/env ruby
# Title: TestAPP.rb
require 'win32ole'
def onCmdTest(sender, sel, ptr)
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE
excel.Quit
excel.ole_free
TestExcel()
end
def TestExcel()
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE
excel.Application.Quit
excel.ole_free
end
# end TestAPP.rb
Ruby 1.8.0-10 with the Fox GUI on a Windows 2000 box to script Excel. I am
having a problem using the ole_free win32ole command. ole_free is designed
to release the resources that Excel was using when it is called. It works
fine when called from the original procedure. However, if a separate
procedure is called from the original, ole_free does not behave as intended.
I am including code for 3 separate files (TestGUI.rbw, TestGUI.rb, and
TestAPP.rb). Put these files in the same directory and run TestGUI.rbw.
Click the 'Test' button to execute the program. You will see that Excel is
launched twice in two different manners then closed using ole_free; once
from the original procedure and once from a nested procedure. If you check
your Task List before exiting the program, you will see that the instance of
Excel that was launched from the nested procedure still exists in the Task
List even though ole_free was called. Is there a way to make this work
properly?
Here are the files:
Save this as TestGUI.rbw:
#/usr/bin/env ruby
# Title: TestGUI.rbw
require 'win32ole'
require 'TestAPP.rb'
require 'TestGUI.rb'
def run
application = FXApp.new("Test GUI")
application.init(ARGV)
ButtonWindow.new(application)
application.create
application.run
end
run
# end TestGUI.rbw
Save this as TestGUI.rb:
#/usr/bin/env ruby
# Title: TestGUI.rb
require 'fox'
include Fox
class ButtonWindow < FXMainWindow
def initialize(app)
super(app, "Test", nil, nil, DECOR_ALL, 100, 100, 0, 0)
menubar = FXMenubar.new(self, LAYOUT_FILL_X)
filemenu = FXMenuPane.new(self)
FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(),
FXApp::ID_QUIT)
FXMenuTitle.new(menubar, "&File", nil, filemenu)
FXHorizontalSeparator.new(self,
LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X)
matrix = FXMatrix.new(self, 3,
MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y)
statusbar = FXStatusbar.new(self,
LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)
FXVerticalSeparator.new(self,
LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|SEPARATOR_GROOVE)
group1 = FXGroupBox.new(matrix, "Test",
GROUPBOX_TITLE_CENTER|FRAME_RIDGE|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|LAYOUT_
CENTER_X|LAYOUT_CENTER_Y)
testButton = FXButton.new(group1, "&Test", nil, nil, 0,
FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
testButton.connect(SEL_COMMAND, methodonCmdTest))
end
def create
super
show(PLACEMENT_SCREEN)
end
end
# end TestGUI.rb
Save this as TestAPP.rb:
#/usr/bin/env ruby
# Title: TestAPP.rb
require 'win32ole'
def onCmdTest(sender, sel, ptr)
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE
excel.Quit
excel.ole_free
TestExcel()
end
def TestExcel()
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE
excel.Application.Quit
excel.ole_free
end
# end TestAPP.rb