Witto
(MM club member)
2006-09-05 10:30 PM
KiX 4.53 RC1, MessageBox: Error Code = Return Value

I would think if MessageBox was used correct, it would give error 0
Code:
If NOT @LOGONMODE
Break ON
EndIf
Dim $SO
$SO = SetOption("Explicit","On")
$SO = SetOption("NoMacrosInStrings","On")
$SO = SetOption("NoVarsInStrings","On")
$SO = SetOption("WrapAtEOL","On")

$SO = MessageBox("Hello World","My First KiX Script")
? "Return Value: " + $SO
? "Error " + @ERROR + ": " + @SERROR
? "Kix Version: " + @KIX

Shows on screen:
Code:
Return Value: 1
Error 1: Onjuiste functie.
Kix Version: 4.53 Release Candidate 1



NTDOCAdministrator
(KiX Master)
2006-09-05 11:05 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Value
Meaning

-1
User did not respond to the dialog box within the specified time-out period.

1
OK button selected.

2
Cancel button selected.

3
Abort button selected.

4
Retry button selected.

5
Ignore button selected.

6
Yes button selected.

7
No button selected


LonkeroAdministrator
(KiX Master Guru)
2006-09-05 11:12 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

witto, you are correct.
it's an oddity and should be fixed.


Witto
(MM club member)
2006-09-05 11:13 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

I know, but I clicked OK. I would expect error value = 0

Witto
(MM club member)
2006-09-05 11:14 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Thanks

Witto
(MM club member)
2006-09-05 11:22 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Jooel,
I did not know if this was "works as designed" or really an issue. Should I repost this in the Beta forum?


LonkeroAdministrator
(KiX Master Guru)
2006-09-05 11:30 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

this was discusses some years back, iirc.
could have been some other function too, though.
but honestly, I think it's a bug, even if it works as designed as it doesn't work as expected.

be my guest and copy your original post to beta.


Les
(KiX Master)
2006-09-06 02:32 AM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Post to suggestions, not beta.

LonkeroAdministrator
(KiX Master Guru)
2006-09-06 09:09 AM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

good point les.
to avoid any flames...


Richard H.Administrator
(KiX Supporter)
2006-09-06 09:20 AM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Interesting one.

The manual doesn't state what @ERROR will be, but I agree that it might be more sensible for it to be used to indicate that KiXtart couldn't raise the window because (say) the PC is out of memory.


Witto
(MM club member)
2006-09-06 09:58 AM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

IMHO, the @Error does not have to be documented for MessageBox seperately. It is all in Appendix B. @Error must just follow the Error codes as listed on the Microsoft Developer Network: System Error Codes .

LonkeroAdministrator
(KiX Master Guru)
2006-09-06 10:29 AM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

I agree with that.

Richard H.Administrator
(KiX Supporter)
2006-09-06 01:00 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Indeed. In that case you will want to be doing something about Get as well

Witto
(MM club member)
2006-09-06 01:58 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Good point. I read it. But this is IMHO a good workaround to catch special keys.

About Get: I think it could be stored in the Return Value, but it should be recognisable. p.e. change the type that is outputted to an Array.
Store in place 0 the Value
Store in place 1 the KeyCode
Code:

Get $SO /A
? "Key: " + $SO[0]
? "KeyCode: " + $SO[1]


If $SO[0] = "" then you know a special key was pressed

$SO[1] p.e. an "A" on a French, Belgian(, Canadian?) keyboard will return the same KeyCode as a "Q" on almost any other keyboard in the world.

/A could be a switch to make Get work in Advanced mode, for downward compatibility

I do not know if that makes sense...

About MessageBox
The Error Code for MessageBox does not give me any added value.
Error Code = Return Value
Return Value = Error Code
It only gave me surprising error values at places in scripts where I did not expect to catch one.


Richard H.Administrator
(KiX Supporter)
2006-09-06 02:53 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

I'm just pulling your leg.

As I said I agree that it would make more sense if @ERROR was actually returning an error rather than the result value.

The problem is that because it has never worked this way changing the @ERROR value will break existing scripts.

Although it has caught you out AFAIK you are the first person, so it is a very rare event. In fact you might be the first person to have ever checked for a (real) error condition following a MessageBox()!

I guess the question becomes "Is it better to change the action to something more compliant and break backwards compatibility, or is it better to leave it as-is and accept that you cannot check for an error"

I'm fairly neutral on this one, though I'd normally advise against introducing unnecessary compatibility issues.


Witto
(MM club member)
2006-09-06 03:14 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

About MessageBox:
  • I think checking @ERROR or checking the Return Value for totally the same *value* does not require big recoding.
  • I would also think that most coders would use the return value to check what key is pressed in MessageBox. Just as it is documented.

Or wait, maybe this:
MESSAGEBOX ("message", "title", style, time-out, 1)
A fifth optional parameter to indicate you want real Error Codes? Default = 0?

About Get:
It is just because you came up with it that I just started thinking about a suggestion with downwards compatibility.


Witto
(MM club member)
2006-09-06 03:16 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

BTW, Thanks for pulling my leg, I liked it.

Les
(KiX Master)
2006-09-06 03:47 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Quote:

The problem is that because it has never worked this way changing the @ERROR value will break existing scripts.

Although it has caught you out AFAIK you are the first person, so it is a very rare event. In fact you might be the first person to have ever checked for a (real) error condition following a MessageBox()!




"Will" sounds so certain. I would prefer to say "might" since I doubt may people actually work with the @Error returned by MessageBox().

THis is not the first known case of being caught off guard by the @Error returned by MessageBox(). It has been discussed several times and I often use it in examples of overly optimistic coding where @Error is assumed. In fact, my examples include a short UDF that uses EXIT to clear @Error.


LonkeroAdministrator
(KiX Master Guru)
2006-09-06 04:04 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

hmm...
what is wrong with get?
and isn't there a @result macro?


Richard H.Administrator
(KiX Supporter)
2006-09-06 04:35 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Quote:

"Will" sounds so certain. I would prefer to say "might" since I doubt may people actually work with the @Error returned by MessageBox()




I actually had "could" at first but "could" or "might" implies a very small chance that any script will break. However given the amount of scripts that are out there it is actually very likely that a change is going to break a number. It's also very likely that it will be a very small number.


Witto
(MM club member)
2006-09-06 04:36 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Jooel,
Get works as described in the manual.
Richard just referred to the fact that Get handles p.e. function keys with error codes. That is why I just suggested that these *return* values could be put in the Return Value. I did not say it is a must.

I do not get the suggestion about the @RESULT macro
Code:

Dim $SO
Get $SO
? "Key: " + $SO
? "Error " + @ERROR + ": " + @SERROR
? "Result: " + @RESULT
? "KiX: " + @KIX


When pressing F1 I get
Code:

Key:
Error 59: Er is een onverwachte netwerkfout opgetreden.
Result:
KiX: 4.53 Release Candidate 1



LonkeroAdministrator
(KiX Master Guru)
2006-09-06 04:39 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

the suggestion was that instead of using incorrectly the error macro, result macro should be used for the function keys.

that is, ruud should change the manual and kixtart to use it.
for backwards compatibility setting the error could be left there.


Witto
(MM club member)
2006-09-06 05:01 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Jooel,
I have been reading through the manual and have been searching this board. I am sorry to tell I do not get your suggestion about @RESULT.
Could you give a little script that shows how @RESULT resolves F1?
How can I catch and evaluate the Return Value the F1 key will give me with @RESULT?
Thanks,


Witto
(MM club member)
2006-09-06 05:02 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

Oh, you edited your reply. Do I have to understand you made a suggestion about how it could be?

Witto
(MM club member)
2006-09-06 05:07 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

What about the suggestion returning an array in advanced mode?
Code:

Get $SO /A


A keystroke can return
- Key
- KeyCode
- Ascii value
all in different dimension


LonkeroAdministrator
(KiX Master Guru)
2006-09-06 05:14 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

returning array would break all current scripts using get.
can't even consider that.

and yes, my post about result macro was a suggestion...
and I did edit it before you posted your reply


Witto
(MM club member)
2006-09-06 05:19 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

An array would only be returned if using /A as optional switch.

LonkeroAdministrator
(KiX Master Guru)
2006-09-06 05:25 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

k...
so, what's different with ascii value and keycode?


Witto
(MM club member)
2006-09-06 05:35 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

I was just thinking about what someone would want to verify
  • Key, just as now, press "a" and catch "a", Press {TAB} and catch Chr(9)
  • KeyCode, My A is next to the TAB-key, where most probably your Q is. Press it evt. with Shift, Ctrl or Alt and we should get the same value
  • Ascii, maybe redundant, Key maybe does the trick, p.e. the enter key would return "13"


Les
(KiX Master)
2006-09-06 05:56 PM
Re: KiX 4.53 RC1, MessageBox: Error Code = Return Value

OOps... NM.. wrong forum.