I post this message in google groups for help as well. Here is what I want to achieve: Have the GUI up, use thread to process the data (read from file) and Excel OLE to output the data. I don't want my GUI to freeze up when it's running. I got the script going but I got couple of errors below. Any help would be great. Thanks a lot.
Attempt to free non-existent shared string '_TK_RESULT_', Perl interpreter: 0x2e e14dc at C:\Documents and Settings\slickuser\Desktop\thread3.pl line 22. Tk::Error: Can't call method "Call" on an undefined value at C:/Perl/ site/lib/Tk /After.pm line 89. [once,[{},after#7,idle,once,[ConfigChanged,{},{}]]] ("after" script) Tk::Error: Can't call method "Call" on an undefined value at C:/Perl/ site/lib/Tk /After.pm line 89. [once,[{},after#8,idle,once,[ConfigChanged,{},{}]]] ("after" script) Attempt to free non-existent shared string 'Value', Perl interpreter: 0x22485c a t (eval 9) line 1. Free to wrong pool 222da8 not 2ed3ec8 at (eval 9) line 1.
Here is my code:
use strict; use warnings; use Tk; use threads; my $thr; my $mainWindow = MainWindow->new; my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7, -scrollbars=>"ose", -wrap=>"word")->pack(); my $goBut = $mainWindow->Button(-foreground=>"blue", -text=>"Click", -command=>sub { $thr = threads->new(\&excecute) } ) +- >pack(); my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Exit", -command=>sub{ if(defined($thr)){ $thr->detach; } exit; })->pack(); MainLoop; sub excecute { $goBut->configure(-state=>"disabled"); $textBox->configure(-state=>"normal"); open(FILE,"C:/file.txt") or die "Can't open file.\n"; while(<FILE>) { my $message = $_; $textBox->insert('end', $message); } close(FILE); $textBox->configure(-state=>"disabled"); $textBox->see('end'); use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my ($Excel,$Workbook,$fileOutput,$CurrentSheet,$Range); $fileOutput = "C:/test.xls"; $Excel = Win32::OLE->new('Excel.Application', 'Quit') || die " +Can't create Excel object. \n"; $Excel->{'Visible'} = 1; #0 is hidden, 1 i +s visible $Excel->{DisplayAlerts} = 0; #0 is hide alerts + $Excel->{SheetsInNewWorkbook} = 1; $Workbook = $Excel->Workbooks->Add(); $Workbook->SaveAs($fileOutput) or die "Can't save Excel.\n"; $CurrentSheet = $Workbook->Worksheets(1); $CurrentSheet->Select; for (my $i=1; $i<=65356; $i++) { $Range = $CurrentSheet->Range("A$i"); $Range->{Value} = $i; sleep(0.01); } $Workbook->Save(); $Workbook->Close(); $Excel->Quit(); Win32::OLE->FreeUnusedLibraries(); $goBut->configure(-state=>"normal"); return;

In reply to Tk & threads & Excel OLE?? by Slickuser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.