Don't load a file that is not an image

Klaus Major klaus at major-k.de
Tue Feb 28 09:51:11 CST 2006


Hallo Reinhold,

> Hi Klaus!
>
>>>   import paint from file Importpicture
>>       if the result <> empty
>>          ## no succes for whatever reason, maybe that was no image
>> file...
>>          answer "This is not an image. It cannot be loaded."
>
> Sorry, that don't work!
>
> I get this error message:
> - - - -
> Execution Error
> import: can't read file, mask file or display
> Handler: error in statement
> - - - -
>
> May be it cannot work, because I use it in a script on a substack  
> that leads to the mainstack like this:
>
>    go stack "mainstack"
>    import paint ...

No, sorry, my fault, hadn't worked with "import paint from..." for a  
long time and forgot
that this will throw an error in case of no success.
"the result" will only work with setting the filename of images and  
players!


In this case you can use the "try" control structure like this:
...
try
     import paint from file Importpicture
   catch errornum
      answer "This is not an image. It cannot be loaded."
end try
...

the script "tries" to import the file and catches the error, so you  
can react in that case.
Cool, isn't it?! ;-)

> I did it, because I have to change the imageNames to ImgQuestion1,  
> ImgAnswer7, ImgPhoto16 for example. And I have to ensure, that  
> every name is only used one time on a card. The result is only a  
> simple name or a "Cancel", so that it may be possible to realise it  
> by a modal command.
>
> But in the MetaTalk Reference I found this:
>
> If information must be returned to the handler that executed the  
> modal command, set a custom property on the stack and check that  
> value after the modal command...
>
> CUSTOM PROPERTY  Heaven! A new field to dig!
>
> Please read my enquiry to that stage!

Done and already answered, you were soooo close :-D

> Reinhold

Best

Klaus Major
klaus at major-k.de
http://www.major-k.de



More information about the metacard mailing list