Interactive PowerBasic Forum

IT-Berater: Theo Gottwald (IT-Consultant) => PowerBasic Adventures => Topic started by: Theo Gottwald on February 18, 2024, 09:49:04 AM

Title: IF THEN and MACROS "Adventure"
Post by: Theo Gottwald on February 18, 2024, 09:49:04 AM
🚀 If you have a subroutine that you often want to jump to at the end of the program, for example during some checks. And then you make a macro because you like macros, like I do, and you use if-then. And here I got a surprising behavior from PowerBasic. This is really another PowerBasic adventure. See below. 🤔

🚀 Wenn du ein Unterprogramm hast, zu dem du oft am Ende des Programms springen möchtest, zum Beispiel während einiger Überprüfungen. Und dann machst du eine Makro, weil du Makros magst, wie ich es tue, und du benutzt if-then. Und hier habe ich ein überraschendes Verhalten von PowerBasic bekommen. Das ist wirklich ein weiteres PowerBasic Abenteuer. Siehe unten. 🤔

✨ #PowerBasic #Makros #Programmieren #Abenteuer

Assume you have defined this MACRO
Macro GoOut()
T01=0:GoTo enx
End Macro

And want to use it like this:
' Will ALWAYS jump out
If (T02<2) Or (T02>50) Then GoOut()


SO you will need to change it to this. Else it will not work as expected.
' Will work as expected
If (T02<2) Or (T02>50) Then
       GoOut()
End If

Title: Re: IF THEN and MACROS "Adventure"
Post by: Charles Pegge on February 18, 2024, 01:05:08 PM
Hi Theo,

Is the colon inside the macro being converted to a line break?

Can you avoid the problem by using a macro function?
Title: Re: IF THEN and MACROS "Adventure"
Post by: Theo Gottwald on February 19, 2024, 03:53:21 PM
I avoided it by not using a Macro in this case.
The effect is possibly what you say, in fact it will always jump out.

If O2 could compile my Powerbasic i would not even use it.
But i have too much Code and -Snippets that can not easily be converted.