Is "End" a SpiderBasic keyword?

Just starting out? Need help? Post your questions and find answers here.
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Is "End" a SpiderBasic keyword?

Post by Little John »

Hi,

in PureBasic, this is a valid program:

Code: Select all

Error = 1

If Error <> 0
  Debug "Error"
  End
EndIf
When I write that code in the SpiderBasic IDE 1.02, it looks fine as well.
Especially, "End" is highlighted as I expected, since I assumed that it is a keyword.
But when trying to run that program, SpiderBasic complains and says:
Line 5: Syntax error.
When I put the cursor on "End" and press [F1], then the Spiderbasic help is opened, showing the page "Other Commands".
However, "End" is nowhere mentioned on that page. :-)
All this is a bit confusing, I think there are probably some leftovers from the PB IDE and help.

If "End" actually is not a SpiderBasic keyword, how can I terminate a program, e.g. in case of an error?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Is "End" a SpiderBasic keyword?

Post by Fred »

No, 'End' is is not a SB keyword. You can not "terminate" a program in SB, as it means you will close the browser page (and it's not allowed). Or do you have another use of 'End' in mind ?
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Re: Is "End" a SpiderBasic keyword?

Post by Little John »

Yes, I have another use of 'End' in mind.
I'll try to give better examples of what I mean.

This code works fine in PB and SB as well:

Code: Select all

If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar)
   If CreateImage(0, 320, 200)
      If StartDrawing(ImageOutput(0))
         ; [...]
      Else
         Debug "Can't start drawing."
      EndIf
   Else
      Debug "Can't create image."
   EndIf
   ; [...]
Else
   Debug "Can't open window."
EndIf


Depending on the actual code, sometimes I prefer to write the same stuff in a different way.
The following code is logically equivalent to the first one, but runs only in PB:

Code: Select all

If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar) = 0
   Debug "Can't open window."
   End
EndIf

If CreateImage(0, 320, 200) = 0
   Debug "Can't create image."
   End
EndIf

If StartDrawing(ImageOutput(0)) = 0
   Debug "Can't start drawing."
   End
EndIf

; [...]

; [...]
When I want to run that program in SB, I have to rewrite the code.
I would greatly appreciate it if that code would run in SB, too -- if possible.

I'm aware that I can write it in SB (and PB) like this:

Code: Select all

Procedure Main()
   If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar) = 0
      Debug "Can't open window."
      ProcedureReturn
   EndIf
   
   If CreateImage(0, 320, 200) = 0
      Debug "Can't create image."
      ProcedureReturn
   EndIf
   
   If StartDrawing(ImageOutput(0)) = 0
      Debug "Can't start drawing."
      ProcedureReturn
   EndIf
   
   ; [...]
   
   ; [...]
EndProcedure


Main()
But that would also mean rewriting the original PB code.
c4s
Posts: 9
Joined: Tue Feb 25, 2014 9:29 am
Location: Germany

Re: Is "End" a SpiderBasic keyword?

Post by c4s »

But what should happen when your web app ends? Close the browser tab (as Fred said) or start an endless loop that does nothing? The only thing you could do in your case is to show something like a permanent failure message.
Apart from that "End" simply doesn't make sense in the WWW-world. I think the only problem here is that the SB IDE shouldn't detect it as a valid keyword.
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Re: Is "End" a SpiderBasic keyword?

Post by Little John »

c4s wrote:But what should happen when your web app ends?
What happens in this code, when OpenWindow() returns 0?

Code: Select all

If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar)
   If CreateImage(0, 320, 200)
      ; [...]
   EndIf
EndIf
Whatever happens, I thought the same could happen in the following code, when OpenWindow() returns 0:

Code: Select all

If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar) = 0
   End   
EndIf

If CreateImage(0, 320, 200) = 0
   End
EndIf

; [...]
c4s wrote:[...] show something like a permanent failure message.
That's a good idea IMHO.

Code: Select all

If OpenWindow(0, 100, 200, 320, 200, "Test", #PB_Window_TitleBar) = 0
   End "Fatal error: Can't open main window."
EndIf
Since I cannot use 'End', how am I supposed to handle a fatal error in my code, e.g. when OpenWindow() returns 0?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Is "End" a SpiderBasic keyword?

Post by Fred »

IMHO, you should write your own End() procedure and do appropriate action when you are in PB or SB. In SB, you will probably open a window with a message like "Fatal error occured". We could accept End in SB and close every objects automatically (window, image etc.) but you will end up with a brown empty window and I don't think it's really what you want.

If you don't want to change your PB code, you can also use a Macro
Little John
Posts: 11
Joined: Fri May 15, 2015 8:41 am

Re: Is "End" a SpiderBasic keyword?

Post by Little John »

Fred and c4s, thanks for your answers!
I hope I'll soon learn the principle differences between a PB executable and a SB web app. :-)
Post Reply