how to check data type before assign the value ??

Posted by pisiith on 06-Oct-2008 23:52

In case,

define variable due_date as date.

define variable mynumber as integer.

assign due_date = mynumber.

the condition above will cause error in progress editor

" ** Incompatible data types in expression or assignment."

but I need to handle this statement by myself to tell the which data is incompatible with which data.

the message should show

"cannot assign mynumber(integer) to due_date(date)".

I don't know how to capture compiler error message and use my own error message.

All Replies

Posted by Matt Baker on 07-Oct-2008 08:55

Removed since the suggestion was invalid since I misunderstood the question.

Message was edited by:

Matthew Baker

Posted by Tim Kuehn on 07-Oct-2008 08:56

The closest you can get is to do a

COMPILE ... NO-ERROR.

followed by a traversal of the ERROR-STATUS:GET-MESSAGE() list.

Even then, there's no way to figure out what caused the error and replacing it with the kind of error detail you're describing. What makes it even more fun is that the compiler doesn't always report the line # where the error happened, but the "first" line number of the compiled statement. For instance:

IF logical-value THEN

assign due-date = mynumber.

would report the "IF" statement as the line # where the error happened, not the ASSIGN statement.

Posted by pisiith on 07-Oct-2008 10:17

thank you for suggestion.

Posted by Thomas Mercer-Hursh on 07-Oct-2008 12:03

From your description, you are trying to catch this at compile time. I am wondering why since the code can't compile until you fix the type mismatch and the error message you are already getting is telling you that the type mismatch exists. To really give a message with more detail ... and we have all wanted that from time to time ... would require meddling with the innards of the compiler, to which we have no access.

Posted by Thomas Mercer-Hursh on 07-Oct-2008 12:10

From your description, you are trying to catch this at compile time. I am wondering why since the code can't compile until you fix the type mismatch and the error message you are already getting is telling you that the type mismatch exists. To really give a message with more detail ... and we have all wanted that from time to time ... would require meddling with the innards of the compiler, to which we have no access.

This thread is closed