Hi all,
 
I'm trying to do something that seems real simple: capture the contents (all
the lines) of a text field and write them to a file. Since I can't see a
more straightforward way of doing this, I wrote an algorithm that gets the
number of lines in the text field, then gets each line (by its number) and
writes it to the file one at a time. However, some lines are being cut off
and only partially written to file. For example, if you copy/paste the
following three lines into the text field, then the middle line gets cut off
for no apparent reason:
 
<tr valign="top">
<td width="45"><img alt="" src="https://www.linvert.com/miscimages/info.gif";
border="0" /></td>
<td>
 
However, if you copy/paste ONLY the middle line into the textfield, then it
doesn't get cut off when written to file! What's even more strange is this:
if I copy/paste more lines above and below those three, then less of the
middle line gets cut off, but it still gets cut off. And I've found that
with some blocks of text, every line gets cut off at the same point.
Needless to say, this is really weird.
 
Below is a slimmed down version of the code that reproduces the problem
every time (at least on my system). Am I doing something wrong, or is there
perhaps a bug in the GetLine() function of Win32::GUI::Textfield?
 
################################
 
use strict;
use Win32::GUI();
 
my $number;
my $line_number = 0;
 
my $w = Win32::GUI::Window->new(
        -size         => [650,650],
        -resizable    => 0,
    -hasmaximize  => 0,
    -dialogui     => 1,
);
 
my $font = Win32::GUI::Font->new(
           -name => "Courier New",
           -size => 8,
);
 
my $textfield = $w->AddTextfield(
                -multiline   => 1,
                -size        => [536,370],
                -pos         => [54,158],
                -font        => $font,
                -tabstop     => 1,
                -background  => [255,255,255],
                -autovscroll => 1,
                -vscroll     => 1,
                -hscroll     => 1,
                -wantreturn  => 1,
);
 
my $OK = $w->AddButton(
         -name    => 'OK',
         -text    => "OK",
         -size    => [80,25],
         -pos     => [447,582],
         -ok      => 1,
         -default => 1,
         -tabstop => 1,
);
 
$w->Center();
$w->Show();
Win32::GUI::Dialog();
 
sub OK_Click {
    my $file = "file.txt";
    open(FILE, ">>".$file);
    select(FILE);
    $number = $textfield->GetLineCount();
    while ( $line_number != $number ) {
        my $line = $textfield->GetLine($line_number);
        if ( $line_number == 0 ) {
            print $line;
        } else {
            print "\n" . $line;
        }
            ++$line_number;
    }
    close(FILE);
    $line_number = 0;
}
 
################################
 
Thanks,
Rob

Reply via email to