PDA

View Full Version : Conditionals



Charles Pegge
18-03-2009, 08:32
'CONDITIONALS
'

uses "oxygen","file"
dim src as string

src = "

dim a,b,c,i,j as long, s as string

a=1 : b=2

'SINGLE LINE FORMAT

if a>b then s=`A>B` else s=`A<=B`

'MULTI-LINE FORMAT

if a>b then
s=`A>B`
elseif a=b then
s=`A=B`
else
s=`A<B`
end if

print s

"
o2_basic src

'msgbox 0, o2_view "o2h "+src

if len(o2_error) then
msgbox 0, o2_error : stop
end if

o2_exec

Charles Pegge
21-07-2009, 13:34
'-------------------
'BOOLEAN CONDITIONAL
'===================

uses "oxygen"
dim src as string

src ="
#basic

'----------------
'True non zero
'False zero
'----------------

dim a=1

if a then
print `True`
else
print `False`
end if

if not a then
print `True`
else
print `False`
end if

"

'msgbox 0,o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec

Charles Pegge
21-07-2009, 13:48
You can easily check whether a string is null/empty or not and act accordingly.

Oxygen Update http://community.thinbasic.com/index.php?topic=2517




'--------------------------
'BOOLEAN STRING CONDITIONAL
'==========================

uses "oxygen"
dim src as string

src ="
#basic

'--------------------
'True length >0
'False null or empty
'--------------------

dim as string s

if s then
print `True`
else
print `False`
end if

s=``

if s then
print `True`
else
print `False`
end if

s=` `

if s then
print `True`
else
print `False`
end if

s=`x`

if s then
print `True`
else
print `False`
end if

"

'msgbox 0,o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec

Petr Schreiber
21-07-2009, 13:51
I like it Charles, especially the string one is very handy :occasion: