any idea as to why in the script below, in sub Button2_Click, TextField1
does not change to "Processing..." prior to running the process_file
sub? A similar call in the process_file sub changes the field to "Done!"
when it finishes, and that call works fine...

TIA

-rob


=============================================================================

use Win32::GUI;



$Window = new Win32::GUI::Window(
                -name   => "Window",
                -title  => "EXCISE",
                -left   => 100,  
                -top    => 100,
                -width  => 430, 
                -height => 200,         
                -menu   => $Menu,
        );

$Window->AddTextfield(
                -name   => "TextField1",
                -left   => 30,
                -top    => 10,
                -width  => 300,
                -height => 20,
                -prompt => "              Input file:",

        ); 

$Window->AddTextfield(
                -name   => "TextField2",
                -left   => 30,
                -top    => 40,
                -width  => 300,
                -height => 20,
                -prompt => "  Output file name:",

        ); 


$Window->AddTextfield(
                -name   => "TextField3",
                -left   => 30,
                -top    => 70,
                -width  => 50,
                -height => 20,
                -prompt => "  Keep this many fields from the beginning of each
record:",

        ); 

$Window->AddTextfield(
                -name   => "TextField4",
                -left   => 30,
                -top    => 100,
                -width  => 50,
                -height => 20,
                -prompt => "  Keep this many fields from the end of each record:",

        ); 

$Window->AddButton( 
                -name   => "Button1",           
                -left   => 150,  
                -top    => 135,
                -width  => 90, 
                -height => 30,
                -text   => "Browse for file",
        );

$Window->AddButton( 
                -name   => "Button2",           
                -left   => 245,  
                -top    => 135,
                -width  => 90, 
                -height => 30,
                -text   => "Process file",
        );
    
$Window->Show();
    


sub Button1_Click {  
        $file = &get_file_name;
        $path = $file;
        $path =~ s/(^.*\\)(.*$)/$1/;
        $Window->TextField1->Text("$file");
        }


sub Button2_Click {  
        
        if ($file) {
                $front = $Window->TextField3->Text;             
                $end = $Window->TextField4->Text;
                $outfile = $Window->TextField2->Text;
                $Window->TextField1->Text("Processing...");
                &process_file($file, $front, $end);             
        }
        else {  $file = $Window->TextField1->Text;
                $path = $file;
                $path =~ s/(^.*\\)(.*$)/$1/;
                $front = $Window->TextField3->Text;             
                $end = $Window->TextField4->Text;
                $outfile = $Window->TextField2->Text;
                $Window->TextField1->Text("Processing...");
                &process_file($file, $front, $end);             
        }       

}


sub Window_Terminate { return -1; }




sub get_file_name {

        $ret = GUI::GetOpenFileName(
           -title  => "File Browser",
           -file   => "\0" . " " x 256,
           -filter => [
                "Text documents (*.txt)" => "*.txt",  
                "All files", "*.*",
                 ],
        );

   return $ret;

}

sub process_file {
        my $file = shift;
        my $front = shift;
        my $end = shift;
##
##begin excise code
##

open (INFILE, "$file");

open (OUTFILE, ">>$outfile");

foreach $line (<INFILE>) {

        @output_front = ();

        @output_end = ();

        $output_string = 0;

        $count_shift = 0;

        $count_pop = 0;

        @array = split (/,/,$line);

        while ($count_shift < $front){

                @shifted = shift @array;

                push (@output_front, @shifted);

                $count_shift++;

                }

        while ($count_pop < $end){

                @popped = pop @array;

                push (@output_end, @popped);

                $count_pop++;

                }

        @rev_output_end = reverse @output_end;

        push (@output_front, @rev_output_end);

        $output_string = join (",", @output_front);

        print OUTFILE ("$output_string");

        }

##
## end excise code
##

        $Window->TextField1->Text("Done!");
        }


Win32::GUI::Dialog();

Reply via email to