-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|392|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Variables


 
HoboBen
Created : 18 February 2007
Edited : 18 February 2007
System : Windows
Language : Cobra

Intelligent Cobra LoadImage



Checks if the image exists at the path specified, and if it does, checks if it loads OK, then passes the element back via the Cobra "result" variable.

On an error, it displays a message box and requests an exit.



|edit|
Ideas for additions:
    "Suppress exit" boolean flag, to replace failed images with a plain grey image, and not close, but settle for just displaying the error message.
    "Suppress error" boolean flag, to stop the function from notifying on error, but instead just carry on.

|edit|

 

Comments


Sunday, 18 February 2007, 17:20
power mousey
ah ha!! seems you have been a busy bee
while I have been contemplating consciousness
during sleep. You have been contemplating code yourself.

I tested out your program. I modified it a litle:



I still ahve the problem of a blank black screen if image wasn't found or image didn't load properly...and also after
you click the specific message box giving you the error message.

I'll definitely work on this next morning when I get home from work. For now, must get some more sleep and settle in low power mode for work tonite

cheers hobo

the power mousey
Sunday, 18 February 2007, 17:57
HoboBen


I changed your "Repeat... Until" so that it paid attention to ExitRequested...
Monday, 19 February 2007, 02:52
power mousey
thank you, hobo

I didn't know there was a command or function
like this. And hey, I've paid attention too.


again, thanks.

cheers
the power mousey
Monday, 19 February 2007, 15:30
JL235
To be honest, this should be built in already. Instead you should have the ability to catch the error and deal with it if you wish. It's far rarer that you don't want an error if an image fails to load, then if do.
Monday, 19 February 2007, 15:55
power mousey
DD,

and for me to be honest, Im relearning coding all over and with Cobra. And taking my time and doing it gradually and not rushing it. true

I'm a Cobra Knight...actually a squire.

I already have the pic image itself catch the error
and flag it down as a NULL....so it will not enter the Repeat...Until loop. Returned from the LoadImagec function.

cheers,
Monday, 19 February 2007, 16:51
Agent
I frown upon the practice of embedding UI code in low-level functions like this. What happens if you want reuse the function, but report or handle the error differently? Perhaps also output it to a log file? Then you're going to have to go through the code and potentially amend several functions.

It's better just to return an error condition and keep the reporting code completely separate.



It's a pity the Cobra language doesn't have built-in support for exception handling - a much more satisfactory solution to handling errors (instead of having to replicate the same error-handling code throughout the program).

Perhaps GrahamK might be persuaded to implement exceptions in a future upgrade.
Monday, 19 February 2007, 21:00
power mousey
sigh

agent,

did you try out the demo of Cobra? and also with the
latest and greatest patch??

the pascal like function within Cobra contains a return variable obviously named Return.
Where in the function you specify the data type of the
return. In this case its element...

anyway,

cheers
Tuesday, 20 February 2007, 03:34
power mousey
ahhhhhhhhhhhh!!!!! I see
what you are trying to do in and
with the modified code.

I think I could add another parameter in hobobens'
LoadImagec function. This will be an error of string variable. So that that the MessageBox(....) will
display the appropriate error message if and only if the image results in a NULL.
Its also making me think more too. Getting the cobwebs out and vaccuming my brain too. true.

took me awhile, agent smith, but I thought and weighed it thru too. thank you.

and hey, by all means and feel free to tell Grahamk about this exception handling. who knows...he might just implement it in Cobra.

real cheers,

power mousey
Tuesday, 20 February 2007, 16:29
HoboBen
Well, this just started out as a demonstration that functions could return elements, and checks could be performed on the result variable before it was returned.

But, er... Yeah, edit it to do what you want. I'm glad people could think and expand from it.

What's interesting is that if you load a non-existent image, Cobra draws the screen instead, using the screen as an image. I did have a nicely worked out way of phrasing that which made sense and explained things, but I can't remember it... so...

Cheers.
Wednesday, 21 February 2007, 08:50
power mousey
hobo,

thank you for sharing your program.
I didn't know you can return an element
in a function. Thank you.

And your last phrasing(phrase) was really good
at explaining some of the program too.

cheers

power mousey