.comment-link {margin-left:.6em;}

Wednesday, December 19, 2007

 

program control

bcx basic manual home



PROGRAM CONTROL

if ... then ... else ... end if
example
if a% > b! then
function = a%
else
function = b!
end if

$IF/$ELSE/$ELSEIF/$ENDIF metastatements

***************************************************************************' Conditional compilation using: $IF/$ELSE/$ELSEIF/$ENDIF metastatements
***************************************************************************
By un-commenting one of the following CONST statements, the resulting
executable code changes as well. Only the code that is associated
with the true condition is compiled, the rest is disregarded.
***************************************************************************
CONST ENGLISH
CONST SPANISH
CONST GERMAN

$IF ENGLISH
? "Good Day"
? "What's happening?"
$ELSEIF SPANISH
? "Buenas Dias"
? "Como va?"
$ELSEIF GERMAN
? "Guten Tag"
? "Was ist los?"
$ELSE
? "Greetings Earthling"
? "Where is the cafeteria?"
$ENDIF
for to..step... next
example
for k = 0 to 14 (step -1 or 6 or whatever here)
color k
next

While ... Wend
example
while len(a$[counter%]) < 79
a$[counter% = a$[counter%] & *)
Wend

goto ... label:
example
goto here
a$ = "test" 'this command gets skipped
here:

do ... loop
example
do
a++
if a>45 then
exit loop
end if
? a
loop

Function .. End Function
the keyword OPTIONAL can be used before the arguments if they are not required

a$ = there$("hello")
Function There$ (C$)
Function = Ucase(C$) & " There "
End Function


sub ... end sub

SUBS can be invoked with or without using the CALL keyword but
remember that the parenthesis and the correct parameters must be used
the keyword OPTIONAL can be used before the arguments if they are not required

CALL Greeting ("Hello from the World of Programming!")

Greeting ("Hello from the World of Programming!")

sub Greeting(a$)
print a$
end sub

'another way to define subroutines is by using the gosub

label: ... return

example

GOSUB qwerty 'this calls the qwerty sub

QwErTy: ' BCX Subroutine Labels are NOT case sensitive

PRINT " This is instance >>", j, " << of the subroutine call."

RETURN ' Return from subroutine back to main program

Select Case ... End Select
example
Select Case Ucase$(a$)

Case "GoodBye"
? "GoodBye"

Case "12345"
? "12345"

Case "HELLO"
? "It passed the Case string test!"

Case "bombed"
? "bombed"

Case Else

? “case test not found”

End Select

********** example 2

Dim A, B$

Input "Enter A Number ", A


Select Case A

Case >1 And <10
Print ">1 And <10 "

Case >10 And <20
Print ">10 And <20"

Case 31,32,33
Print "31,32,33"

Case Else
Print "No special case found"

End Select


PRINT

input "Type one, two, qwerty, or other ", B$

select case B$

case "one","two"
Print "one, two"

case "qwerty"
Print "qwerty"

end select

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?