Jens Luedicke wrote:
>
> Hi there ....
>
> I have some problems with this sub:
>
> sub Window_Terminate {
> $message = Win32::MsgBox("Do you want to quit?", 4 |
> MB_ICONQUESTION, "Quit?");
> if($message = '6') {
[snip]
> When the user want's to exit he will be asked to confirm. When he
> confirms to
> exit, he will be asked to save. But when I click "No" the window to
> save the file
> will be opened anyway.... Why?
You're if statements are wrong. A single = is an assignment. Double ==
is comparison. So what the line if($message = '6') is doing is assing
the value 6 to the variable $message, and then if the assigment worked
the if returns true. What you need to do is change all those lines to
"if ($message == 6) {".
I would also suggest that you run your programs with warnings enabled.
Either set the first line in your program to "#!perl -w" or from the
command line run them as "perl -w program.pl". This would have caught
this error. Here's a sample program I just wrote to show this.
#!perl -w
$mes = 5;
if ($mes = '6') {
print $mes;
}
__END__
The output of this is:
Found = in conditional, should be == at E:\PROGRAMS\test.pl line 5.
6
So you can see that my variable was being set to 6 when I didn't want it
to, and it also warned me about the possible problem.
Rob Rogers