Tip: If/Then in PureBasic!

Share your advanced PureBasic knowledge/code with the community.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Everything you say is true.

However, the reasons for being a caveman may differ.

My fingers type THEN, my subconscious has been patterned. My mind is six lines ahead (probably chanting a mantra .. This is Pure, EndIf not End If) .. Press F5. Error. ARGHHHHHHHH! Thump. Shatter.

Go to bed as without a screen, coding is not possible. :)

So in my case, my THEN. :)
@}--`--,-- A rose by any other name ..
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

BTW, I just found two of the old requests for If/Then:

http://www.purebasic.fr/english/viewtopic.php?t=11329
http://www.purebasic.fr/english/viewtopic.php?t=6310

So, hopefully those who asked for it, can enjoy my macro (and expand it). :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hehe. The tribe grows. Ooga Ooga.

Another thing that seems pointless is Select Case.

Why case? Is it just there to trip you up when you switch back to PureBasic? What else can you select? Box? Trunk? BackPack? Container? HandBag?

What deep and meaningful purpose does case have there?

Unfortunately, no macro. Unless ..

Code: Select all

Macro Case
  MacroIf MacroPreceedingWord = "Select"
    MacroIGNORE
  MacroElse
    Case
  MacroEndIf
EndMacro
Reckon I might put this feature into the wishlist!



Then again, maybe not.
@}--`--,-- A rose by any other name ..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

thefool wrote:
Trond wrote:I've never seen that use of then. Where does that interpretation of what then should do come from?
:shock:

How can you even ask..
Because:
Pascal uses then, and it does not equal this macro version.
Rapid-Q (which is a basic) uses then, and it does not equal this macro version.
VB (which is a basic) uses then, and it does not equal this macro version. Although VB's implementation of then is more similar to this macro version than Pascal's and Rapid-Q's implementation of then, VB's then does not equal this macro version.
FreeBASIC (which is a basic) uses then, and it does not equal this macro version.
Modula-2 uses then, and it does not equal this macro version.
BlitzBasic (which is a basic) uses then, and it does not equal this macro version.
Fortran uses then, and it does not equal this macro version.

Now tell me, where did you see an implementation of then which behaves similar to this macro? (Big prize if you can! (Copying and pasting this macro does not count!!))
mike74
User
User
Posts: 60
Joined: Mon Nov 21, 2005 1:44 pm

Post by mike74 »

I like it, PB. Thanks!

Mike
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Wondering, except for the paranthesis why isnt this macro version equal to quickbasic and visual basic?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

thefool wrote:Wondering, except for the paranthesis why isnt this macro version equal to quickbasic and visual basic?
I never said anything about quickbasic.
It's not equal to any language because of the parenthesis.

It's not equal to VB because this is possible in VB and not with this macro version:

Code: Select all

If whatever Then dosomething Else dosomethingelse
Also you can use ElseIf after then in VB.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Trond wrote:
thefool wrote:Wondering, except for the paranthesis why isnt this macro version equal to quickbasic and visual basic?
I never said anything about quickbasic.
It's not equal to any language because of the parenthesis.

It's not equal to VB because this is possible in VB and not with this macro version:

Code: Select all

If whatever Then dosomething Else dosomethingelse
Also you can use ElseIf after then in VB.
You can skip the else too...
Nevermind...
...


here you go:
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> It's not equal to any language because of the parenthesis

That's just nit-picking on PureBasic's macro limitations. :roll:

The functionality and concept is there. I based it on older Basics where Else
is not used. Let all those who replied with "thanks!" enjoy it, as it's obviously
serving their needs. I don't understand why it's being picked on so much.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

I think in QBasic is the "then" equal to

Code: Select all

macro then
:
endmacro
Apart from that Mrs Lincoln, how was the show?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Now tell me, where did you see an implementation of then which behaves
> similar to this macro? Big prize if you can!

Here's two implementations: VB and C64. Now, where's my prize? :twisted:

Code: Select all

Private Sub Command1_Click()
    Dim var As Byte
    var = 1
    If var = 1 Then Debug.Print "Yes, var=1"
End Sub
Image
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

then is ugly then is bad then is the command we should never have had...
but then again, but here and now, then is then and pure is now
please stop thy then then thy will see
the beaty that if else endif will bring to thee!

got carried away, sorry
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

The sense of this discussion escapes me!
User avatar
IceSoft
Addict
Addict
Posts: 1683
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

'THEN' will not improve PureBasic.

The only reason for using any new keywords should be the improvement of PureBasic.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

helpy wrote:The sense of this discussion escapes me!
Good thing - if you thought it made sense then you'd need professional help. :)
@}--`--,-- A rose by any other name ..
Post Reply