ForceDeclaration
ForceDeclaration State
 
Parameters:

    State = The State variable declaration ON= Explicit declaration, OFF = Implicit (default)
Returns: NONE
 


      ForceDeclaration lets the user change what variable declaration mode that the compiler uses. When enabled (ForceDeclaration ON) PlayBASIC will force the user to declare every variable prior to the variable being used. The beauty of activating ForceDeclaration mode, is that it can help you locate faults in your program that might be due to a misspelled variable name. Such problems are quite common and very frustrating to track down.

      Moreover you can enable/disable ForceDeclaration mode anywhere you like through out your program. (see example)


State Values

      ON = Explicit declaration: Variables must be declared prior to use.

      OFF = Implicit declaration: Variables will dynamically declared for you. This is the default state for PlayBASIC.




FACTS:


      * ForceDeclaration can be turned ON/OFF at any time through a program. Allowing you activate it for some sections and not others.

      * ForceDeclaration parameter is optional. ForceDeclaration defaults to ON when the parameter is left off.

      * ForceDeclaration is obsolete, we recommend using Explicit in the future




Mini Tutorial:


      This example just demos the basic of PlayBASIC Explicit mode.

  
; -------------------------------------------------------
; NOTE: Explicit and ForceDeclaration  are interchangeable
; -------------------------------------------------------
  
; Force PlayBASIC to expect all variable to be
; declared prior to use
  
  Explicit
  
  
; explicitly declare Hello as global
  Global MyGlobalVariable=42
  
; Declare some variables to hold the screen width & height
  Dim Width As Integer
  Dim Height As Integer
  
; Get screen Width + Height
  width     =GetScreenWidth()
  Height=GetScreenHeight()
  
  
; You can also use Declaration Blocks for pure declaration
  Declaration
     MyVariable
     MyFloatVariable#
     MyStringVariable$
  EndDeclaration
  
  MyVariable               =99
  MyFloatVariable#     =123.456
  MyStringVariable$ = "Hello World"
  
  
  
  
; turn off Explicit/forced declaration mode, to allow
; dynamic variable creation again
  Explicit off
  
; Since Explicit mode is OFF, the variable 'a' will
; be dynamically created for us.
  a=a+1
  
; Turn Explicit Variable declaration ON again
  Explicit on
  
; Display the variables
  Print MyVariable
  Print MyFloatVariable#
  Print MyStringVariable$
  
  Print MyGlobalVariable
  Print Width
  Print Height
  Print a
  
; Remove the comment in front of the line bellow
; and try and compile it !.  I won't work, as
; the 'b' variable hasn't been previously
; declared
  
;   Print b
  
  
; Display the screen and wait for the user to press a key
  Sync
  WaitKey
  
  



This example would output.

  
  99
  123.456
  "Hello World"
  42
  800
  600
  1
  

 
Related Info: Byte | Declaration | Dim | EndDeclaration | Explicit | Float | Global | Integer | Local | Pointer | Static | String | Type | Word :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com