Skip to main content

Keine mathematische Operation in IF-Anweisung

More
10 years 5 months ago - 10 years 5 months ago #2 by Eva Mayrhofer
Keine mathematische Operation in IF-Anweisung was created by Eva Mayrhofer
Schon gewusst?

Das folgende Konstrukt im ST-Editor wird als fehlerhaft markiert:
Code:
PROGRAM MyTest VAR X, B : BYTE; END_VAR IF X > 255 - B THEN (* Der Ausdruck "X > 255 - B" verursacht den Fehler. *) X := 0; END_IF; END_PROGRAM

Warum? BYTE-Werte können nicht implizit in numerische Werte konvertiert werden.
Abhilfe: Konvertiert die BYTE-Werte für den ST-Code "X > 255 - B" explizit mit Hilfe einer Convert-Funktion. Zum Beispiel:
Code:
PROGRAM MyTest VAR X, B : BYTE; END_VAR IF TO_INT(X) > 255 - TO_INT(B) THEN X := 0; END_IF; END_PROGRAM
Last edit: 10 years 5 months ago by Eva Mayrhofer.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum