qbasic tutorial for beginners and newbies

23
By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1 of 23 QB-TUTORIAL B  Y NEO DEUS EX MACHINA HTTP://WWW.BLINDCODING.CJB.NET BEGINNERS & NEWBIES EDITION 1 1

Upload: bay-bunker

Post on 06-Jul-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 1/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1 of 23

QB-TUTORIALB Y NEO DEUS EX MACHINA

HTTP://WWW.BLINDCODING.CJB.NET

BEGINNERS & NEWBIES EDITION

1

1

Page 2: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 2/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 2 of 23

WHY USE QB? (I)

Since B is !e"y !e"sa#i$e, i# is a %us# &no' fo" #o(ay)s *"og"a%%e"s+ $%os# e!e"y#hingcan e (one 'i#h B+ $#hough #o(ay)s fashion isn.# D/S any%o"e, i# can e ui#e usefu$ #o &no'so%e#hing aou# D/S an( aou# B, 'hich is a D/S-o"ien#e( *"og"a%%ing $anguage+

B ce"#ain$y is #he easies# *"og"a%%ing $anguage of a$$ #o $ea"n+ $so, 'hen &no'ing #his$anguage, o#he" *"og"a%%ing $anguages a"e !e"y easy $ea"n, $i&e isua$ Basic, o" e!en o" a!a+$so, eginning 'i#h a D/S-$anguage, o*ens ne' 'ays an( &no'$e(ge 'hen s#e**ing #o 4in(o's-

 ase( $anguages+ Because #he %os# you can use in D/S can a$so e use( in 4in(o's+$#hough B isn.# #oo fas#, a $o# can e (one 'i#h i#, easi$y+

THIS TUTORIAL

n #his #u#o"ia$, s*ecific 'ays of #ex#-(eco"a#ion a"e use( #o &ee* #hings c$ea"+ 'i$$ ex*$ain#he% no'+

his is no"%a$ #ex# (eco"a#ion7 8-9

his is a "e%a"& This is code-decoration

his is an exc$a%a#ion A note

#hin& #ha# 'as e!e"y#hing+ $#hough s#i$$ a no#e: no# a$$ exa%*$es in #his #u#o"ia$ a"e #es#e(+So #he"e %igh# e so%e ugs in #he%+

2

2

Page 3: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 3/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 3 of 23

QB: SOME BASICS (II)

V ARIABLES

a"ia$es a"e #e%*o"a"y s#o"age *$aces of (iffe"en# &in(s of !a$ues+ a"ia$es ha!e a uniuena%e+ he"e a"e (iffe"en# #y*es of !a"ia$es 'hich can a$$ con#ain (iffe"en# !a$ues+ ;o" #he #y*es,see sec#ion .Da#a y*es)9+ o s#o"e so%e#hing in a !a"ia$e, use #he eua$s-cha"ac#e" #he <9+ o ge##he !a$ue #ha# is s#o"e( in #he !a"ia$e, =us# #y*e i#s na%e+

f you s#i$$ (on.# un(e"s#an( #his ex*$ana#ion, #"y #his: a !a"ia$e can e seen as a ("a'e" ine+g+ a c$ose#+ >ou can *u# #hings in #he ("a'e", an( you can $oo& in#o a ("a'e" #o see 'ha#)s in i#,you can "e%o!e #he con#en#s of #he ("a'e", an( you can "e%o!e #he ("a'e" co%*$e#e$y+

D ATA TYPES

he"e a"e 6 (a#a #y*es a!ai$a$e in B, 'hich shou$( e %o"e #han enough+ + hey a"e a$$

ex*$aine( he"e+ 4e$$, he"e #hey co%e:Integer is #he fi"s# an( %os# i%*o"#an# (a#a #y*e+ his (a#a #y*e is #he %os# use( (a#a #y*e of 

a$$+ >ou can s#o"e on$y non-(eci%a$ nu%e"s in an in#ege"+ Since an in#ege" con#ains 16 i#s, youcan on$y s#o"e !a$ues f"o% ?32@6A u* #o 32@6@+

Long integer is #he secon(+ ong in#ege"s a"e no# use( #ha# of#en, since %os#$y in#ege"s'o"& fine+ ong in#ege"s a"e ac#ua$$y #he sa%e as no"%a$ in#ege"s, so on$y non-(eci%a$ nu%e"s+Ho'e!e", a $ong in#ege" con#ains 32 i#s, a$$o'ing you #o s#o"e !a$ues f"o% ?21C@CA36CA #o21C@CA36C@+

Single, 'hich can con#ain (eci%a$ nu%e"s+ Sing$es a"e 32 i# an( you can s#o"e !a$uesf"o% a"oun( eC0 #o e-3+

Double, 'hich can a$so con#ain (eci%a$ nu%e"s+ he on$y (iffe"ence is #ha# (ou$es a"e 6C i#s $a"ge, #hus *"o!i(ing s*ace fo" !a$ues f"o% a"oun( e305 #o e-310+String+ he s#"ing is a s*ecia$ #y*e+ # can con#ain cha"ac#e"s $i&e .) o" .)+ S#"ings a"e

a$'ays no#a#e( 'i#h (ou$e uo#a#ion %a"&s a"oun( #he%+ F9+ he $eng#h of #he cha"ac#e"-$is# can"ange u* #o 6C&+

String * n%, 'hich is a s#"ing 'i#h a se# $eng#h+ iG+: n cha"ac#e"s can fi# in #he s#"ing+

ha# 'e"e #he% a$$+ Each (a#a #y*e a$so has i#s o'n *os#fix-sign+ +e+ #ha# if you ca$$ a!a"ia$e fo" ins#ance .nu%e"), #he !a"ia$e is ca$$e( .nu%e") an( (ec$a"e( as an in#ege"+ f !a"ia$es (on.# ha!e a *os#-fix sign, #hey a"e sing$es, un$ess you sai( #he% no# #o e 8-9+ He"e a"e a$$

 *os#fixes:

n#ege": %ong: &

Sing$e: !

Dou$e: #

S#"ing: $

REMARKS IN CODE

>ou can a$so *u# "e%a"&s in you" co(e, 'hich can %a&e you" co(e %o"e c$ea" #o you"se$f an( o#he" *eo*$e "ea(ing you" *"og"a%+ o %a&e a "e%a"& in co(e, use a sing$e uo#a#ion %a"& .9fo$$o'e( y #he "e%a"&+ >ou can a$so use #he co%%an( ca$$e( .Ie%) 'hich ac#ua$$y (oes no#hingso i#)s sui#a$e fo" "e%a"&ing Ie% is an a"e!ia#ion of "e%a"&9+

3

3

Page 4: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 4/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page C of 23

QB: FIRST CODING (III)

YOUR FIRST PROGRAM

S#a"# u* B, y (ou$e-c$ic&ing on B+EJE+ hen #y*e #he fo$$o'ing co(e:

PRINT “Hello!”

PRINT “This is my first program!”

END

hen "un #he *"og"a% y *"essing #he Shif# &ey an( #he ;5 &ey si%u$#aneous$y+ n(7 he"eyou see you" fi"s# *"og"a%+ $#hough #he *"og"a% 'i$$ e en(e( i%%e(ia#e$y af#e" you *"esse( ;5,#he *"og"a% s#i$$ gi!es so%e ou#*u#+ o ge# use( #o #he co%%an(s use( in a *"og"a%, a$'ays sho'a #a$e 'i#h a$$ co%%an(s you ha!en.# ha( ye#+

PRINT [ar P"in# sho's so%e#hing on #he sc"een+ he co%%an( i#se$f acce*#s e!e"y#hing

f"o% s#"ings #o nu%e"ica$ !a$ues+END S#o*s you" *"og"a% an( "e#u"ns #o #he B-DE if "unning f"o% #he DE9+

>ou (on.# ha!e #o '"i#e #he co%%an(s a$$ in ca*i#a$, #he DE (oes #his au#o%a#ica$$y fo" you+

>ou can a$'ays use #he &eyco%ina#ion K#"$LKB"ea&L #o i%%e(ia#e$y s#o* #he *"og"a%+

LOCATING AND COLOURING SOME TEXT

y*e #his exa%*$e in #he B DE:

"#$#R %

PRINT “This is grey te&t!”"#$#R '

PRINT “This is red te&t! ()”

"#$#R *+

PRINT “,hite te&t!”

"#$#R

PRINT “.o/ can0t see 1lac2 te&t tho/gh! ()“

END

Iun #he *"og"a%+ f you a$"ea(y &ne' 'ha# P"in# (i(, you)$$ *"oa$y no' &no' 'ha# o$o" (oes+

"#$#R fgro/nd3

[4 1gro/nd3Se#s #he cu""en# fo"eg"oun( co$o" #o fg"oun( an( #he ac&g"oun( co$o" #o g"oun( g"oun( is o*#iona$, #hus you (on.# ha!e #o s*ecify one9+No#e #he in#ege"-*os#fix, so nu%e" %us# e an in#ege"9+ ;o" no', 'eon$y use 16 co$o"s:0 < B$ac& 1 < B$ue 2 < "een3 < yan C < Ie( 5 < Magen#a6 < B"o'n @ < "ay A < Da"& g"ay < igh# $ue 10 < igh# g"een 11 < igh# cyan12 < igh# "e( 13 < igh# %agen#a 1C < >e$$o'15 < 4hi#e>ou shou$( &no' #hese !a$ues an( co$o"s y hea"#O

his isn.# #he en(+ >ou)$$ no' 'a#ch ho' you can *osi#ion so%e #ex# on #he sc"een:

C

C

Page 5: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 5/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 5 of 23

"$5

$#"6TE *4 *

PRINT “7pper left”

$#"6TE *4 89

PRINT “7pper right”

$#"6TE *:4 :PRINT “5ome;here in the middle”

$#"6TE <+4 89

PRINT “$o;er right”=

END

sing $oca#e, 'e can #hough *osi#ion #ex# on #he sc"een+ 4i#h *osi#ioning, i# %igh# e han(y#o &no' 'ha# #he nu%e"s ehin( oca#e %ean+ 4e$$, #he fi"s# is #he y-coo"(ina#e, #he secon( is #hex-coo"(ina#e+ he y-coo"(ina#es "ange f"o% 1 #o 25 1 is #he fi"s# $ine, 25 #he $as#9+ he x-coo"(ina#es "ange f"o% 1 #o A0 1 is #he %os# $ef# an( A0 #he %os# "igh#9+

"$5 $ea"s #he sc"een+$#"6TE y-cord34 &-cord3 Se#s #he cu"so" *osi#ion #o #he coo"(ina#es y-co"(, x-co"(9+

he nex# P"in#-co%%an( 'i$$ *u# #he #ex# on #hosecoo"(ina#es+

/f cou"se, oca#e can a$so e use( in con=unc#ion 'i#h o$o" #o c"ea#e co$o"e( an( *osi#ione( #ex#+  Note that Locate only applies to the next Print-command encountered, Color 

applies to all Print-commands until another color is set using another Color-command +

Di( you no#ice #he .8) ehin( #he $as# *"in# co%%an(Q ho*e so7 .8) has een *u# a# #heen( of #he *"in# co%%an( ecause #he $as# #'o $ines of #he sc"een y-co"(s 2C an( 259 a"e a $i##$e'ei"(+ No"%a$$y, 'hen you *u# #ex# #he"e, #he en#i"e sc"een shif#s 1 $ine u*, #hus "e%o!inge!e"y#hing on #he fi"s# $ine+ he .8) a# #he en( of a *"in# co%%an(, *"e!en#s #he sc"een f"o% shif#ingu*+

THE FIRST TIMERS

/f cou"se B has #he *ossii$i#y #o se##ing #he co%%an(s on #i%e+ So he"e 'e)$$ ex*$ain #'oi%*o"#an# func#ion of #he co%%an( ca$$e( .S$ee*)+ S$ee* has #he ai$i#y #o 'ai# a nu%e" of secon(s

 efo"e *"ocee(ing 'i#h #he nex# co%%an(+ he secon( func#ion of S$ee* is 'ai#, #i$$ #he use" *"essesa &ey+ hey a"e o#h (e%ons#"a#e( in #he fo$$o'ing *"og"a%:

"$5

PRINT “Please ;ait : seconds>”

5$EEP :

PRINT “No; press a 2ey to end the program”

5$EEP

END

5$EEP [n/m1er3 f you s*ecify a nu%e" ehin( s$ee*, #he S$ee* co%%an( 'ai#s #ha# %anysecon(s efo"e *"ocee(ing+ f you (on.# s*ecify a nu%e", S$ee* 'ai#sun#i$ a &ey*"ess efo"e *"ocee(ing+

5

5

Page 6: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 6/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 6 of 23

P"essing a on#"o$-&ey (u"ing a S$ee*-co%%an( 'i#h a !a$ue s*ecifie(9, 'i$$ cause #heS$ee* co%%an( #o e s&i**e(+ So if you say .S$ee* 1000) an( so%eone *"esses #he on#"o$-&ey, #heco%*u#e" i%%e(ia#e$y *"ocee(s 'i#h #he nex# co%%an(+

USING V ARIABLES IN YOUR CODE

s sai( efo"e, !a"ia$es can e use( in you" co(e fo" (yna%ic nu%e"s o" cha"ac#e"s+ ;i"s#$oo& a# #his exa%*$e:

"$5

DI? ?yInteger 65 INTE@ER

DI? ?y5tring 65 5TRIN@

?yInteger A %

?y5tring A “?y name is Neo”

PRINT ?y5tring

PRINT “6nd my l/c2y n/m1er is(”= ?yInteger

END

s you cou$( see in #his exa%*$e, fi"s#, 2 !a"ia$es a"e (efine(+ Myn#ege" is (efine( as anin#ege" an( MyS#"ing is (efine( as a s#"ing+ hen, #he !a$ue @ is *u# in#o Myn#ege" assigne( #o79,an( #he #ex# FMy na%e is NeoR is *u# in#"o MyS#"ing+ hen, MyS#"ing is *"in#e( #o #he sc"een+;ina$$y, #he #ex# Fn( %y $uc&y nu%e" is:R is *"in#e( on #he sc"een 'i#h a# en( of #he #ex# a @+

Do no# confuse PIN FMyS#"ingR 'i#h PIN MyS#"ing+ he uo#a#ion %a"&s a"e #he(iffe"ence9+ he "eason is !e"y si%*$e: #he fi"s# *"in# *"in#s #he #ex# FMyS#"ingR $i#e"a$$y #o #hesc"een, an( #he secon( *"in#s #he con#en#s of #he MyS#"ing-!a"ia$e #o #he sc"een+

DI? arname 65 artype his co%%an(s (efines a !a"ia$e ca$$e( .!a"na%e) as

.!a"#y*e)+ a"na%e %ay no# egin 'i#h a nu%e" an( %ay no#con#ain ex#en(e( cha"ac#e"s $i&e o" T+PRINT [te&t= [te&t

PRINT [te&t4 [te&t4e a$"ea(y s*o&e aou# P"in# efo"e, u# #hin& #he .8) nee(sex#"a a##en#ion+ he #hing is, P"in# is no# on$y a$e #o *"in# 1!a$ue #o #he sc"een, i# can a$so *"in# (iffe"en# !a$ues #o #hesc"een+ o gain #his effec#, use a 8 #o se*a"a#e (iffe"en# !a$ues+So if you (o #his: PIN FHe$$oR8 F %y na%e is NeoR you)$$ ge##his on #he sc"een: He$$o %y na%e is Neo+ So #he .8) i#se$f (oesn.# con#ain s*aces, i# =us# *as#es #he fo$$o'ing !a$ue #o #he$as# !a$ue+ his isn.# i#, ecause you can a$so (o #his: PINFHe$$oR, F%y na%e is NeoR 'i#h a co%%a ins#ea( of a

se%ico$on9+ he ou#*u# is (iffe"en# no', ecause #he co%%a(oesn.# *as#e !a$ues #oge#he" 'i#h no#hing e#'een #he%, u# i#

 *as#es !a$ues #oge#he" 'i#h so%e s*aces e#'een #he%, keep

this in mind!

 ASKING THE USER FOR V ALUES

B is a$so a$e #o $e# #he use" en#e" so%e !a$ues 'hich you %ay fin( han(y+ He"e)s anexa%*$e:

"$5

DI? n/m1er 65 INTE@ER4 ans;er 65 INTE@ER4 yo/rname 65 5TRIN@

INP7T “No; enter a n/m1er(”4 n/m1er

INP7T “No; yo/r name(”4 yo/rname

6

6

Page 7: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 7/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page @ of 23

PRINT “5o “= yo/rname= “ yo/ ;anted to 2no; ;hat is”= n/m1er= “

times +B”

ans;er A n/m1er C +

PRINT “,ell4 it is(”= ans;er

END

>ou see, 'hen you "un #his *"og"a%, you a"e as&e( fo" a nu%e" an( you" na%e+ # sho'sso%e #ex# an( #he co""ec# ans'e" of #he nu%e" you en#e"e( #i%es 5+ #he as#e"is& %eans .#i%es)9+

INP7T [te&t4 aria1le

INP7T [te&t= aria1le;i"s#, i# sho's #he #ex# s#o"e( in #ex#U, #hen as&s #he use" #oen#e" a !a$ue fo" !a"ia$e+ f you use a co%%a o" a se%ico$onas se*a"a#ion-%a"& you)$$ ge# a ues#ion %a"& o" no ues#ion%a"& a# #he en(+ co%%a gi!es none, a se%ico$on gi!es onea# #he en( of #he #ex#9+

 Note: you don‘t have to put doule uotation marks "hen entering a string value# $% your 

 program asks you to#

CHAPTER PROGRAM

>ou *"oa$y (on.# &no' ye#, u# a# #he en( of each cha*#e", #he"e is an exa%*$e *"og"a%an( so%e exe"cises aou# e!e"y#hing you &no' so fa"+ >ou a# $eas# shou$( ha!e %a(e a$$ exe"cises

 efo"e *"ocee(ing #o #he nex# cha*#e"+

"$5

DI? faoritecolor 65 INTE@ER

$#"6TE *4 *PRINT “Please enter yo/r faorite color-n/m1er 1eneath(”

$#"6TE **4 *

INP7T “.es here(”4 faoritecolor

"#$#R faoritecolor

PRINT “5o yo/r faorite colorn/m1er is(”= faoritecolor

PRINT “No; press a 2ey to proceed”

5$EEP

PRINT “/itting this program> Please ;ait + seconds”

5$EEP +

END

 No' fo" #he exe"cises7

Exe"cise V1: Sho' a$$ co$o"s on sc"een y sho'ing #he #ex# .#his is 77 #ex#) 'i#h on #he 7)s #heco$o")s na%e+

Exe"cise V2: Sa%e as Exe"cise V1 u# no' sho' i# exac#$y a# #he %os# "igh# of #he sc"een+

Exe"cise V3: s& #he use" fo" his S #hen sho' #he s#a#is#ics in an e%*#ie( sc"een+

Exe"cise VC: Ma&e a &in( of in#e"!ie' 'i#h #he use" 'i#h aou# 10 ues#ions+ # #he en(, sho' a

"e*o"# aou# #he use")s ans'e"s+ E+g+ if #he use" sai( his na%e is .Ha"o$() in #he "e*o"# i# %us# say.His na%e is Ha"o$()9+

@

@

Page 8: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 8/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page A of 23

MODIFIERS & STRUCTURE (IV)

D ATATYPE MODIFIERS

s#"ing 'i#hou# #he *ossii$i#y #o change i# isn.# a s#"ing+ n( #he $anguage in 'hich #ha#isn.# *ossi$e, suc&s+ He"e)s an exa%*$e *"og"a% sho'ing so%e of #he (a#a#y*e-%o(ifie"s:

"$5

DI? yo/rname 65 5TRIN@

INP7T “Please enter yo/r name(”4 yo/rname

PRINT “.o/r name in /pper case( “= 7"65EFyo/rname)

PRINT “In lo;er case( “= $"65EFyo/rname)

PRINT “$ength of yo/r name(”= $ENFyo/rname)

PRINT “Girst letter( “= $EGTFyo/rname4 *)

PRINT “$ast letter( “= RI@HTFyo/rname4 *)

PRINT “5econd letter( “= ?IDFyo/rname4 <4 *)

INP7T “Please enter a lot of spaces4 some letters and again a lot

of spaces(”4 strangestring

PRINT “,itho/t the first spaces( “= $TRI?Fstrangestring)

PRINT “,itho/t the last spaces( “= RTRI?Fstrangestring)

PRINT “/st a co/ple of spaces( “= 5P6"EF*)

INP7T “Please enter a n/m1er(”4 n/m1er3

PRINT “5tringed n/m1er(”= 5TRFn/m1er3)

PRINT “N/mericaled string( “= 6$F5TRFn/m1er3))

INP7T “No; enter * character(”4 char

PRINT “65"II-code of char(”= 65"Fchar)

INP7T “Enter a al/e 1et;een :: and <++(”4 al/e3

PRINT “"orresponding 65"II-char( “= "HRFal/e3)

END

ha# 'e"e %os# of #he% in(ee(+ No', $e#)s ex*$ain+

7"65EFastring) his func#ion con!e"#s as#"ingU #o u**e" case an( "e#u"nsi#+

$"65EFastring) his func#ion "e#u"ns a s#"ing eui!a$en# #o as#"ingU in$o'e" case+

$ENFastring) his func#ion "e#u"ns #he $eng#h of as#"ingU+$EGTFastring4 pos3) his func#ion "e#u"ns #he fi"s# *os cha"ac#e"s of as#"ingU+

RI@HTFastring4 pos3) his func#ion "e#u"ns #he $as# *os cha"ac#e"s of as#"ingU+?IDFastring4 pos34 len3) his func#ion "e#u"ns a s#"ing 'hich is a *a"# of as#"ingU+he s#"ing i# "e#u"ns s#a"#s a# *os an( has a $eng#h of $en+ So if you (o PIN MDUFHE/R, 2, 29 on #hesc"een i#)$$ say E+

$TRI?Fastring) Ie%o!es a$$ s*aces in f"on# of a s#"ing, so if you go#as#"ingU < F he$$oR #hen #"i%U 'i$$ "e#u"nFhe$$oR+

RTRI?Fastring) Ie%o!es a$$ s*aces a# #he en( of a s#"ing+ See #"i%U5P6"EFn/m1er3) Ie#u"ns a s#"ing 'i#h nu%e" s*aces in i#+5TRFn/m1er3) Ie#u"ns #he s#"ing-eui!a$en# of a !a$ue+ So if you)!e go#

a < 56 an( #hen (o %ys#"ingU < SIUa9 you)$$ ge#%ys#"ingU < F 56R

6$Fastring) on!e"#s a nu%e"ica$ s#"ing #o i#s co""es*on(ing !a$ue+

A

A

Page 9: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 9/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page of 23

his is #he in!e"se func#ion of S#"U+65"Fchar) Ie#u"ns #he S-co(e of cha"U+"HRFasciicode3) Ie#u"ns #he cha"ac#e" 'i#h S-co(e asciico(e+

un(e"s#an( if you can.# un(e"s#an( i# a$$ a# once, u# #ha# is no *"o$e%+ he on$y #hing youha!en.# ha( ye# a"e ;unc#ions, S#a#e%en#s, Ex*"essions an( Me#aco%%an(s+ )$$ ex*$ain #he% he"e

exce*# #he %e#aco%%an(s9+

f a co%%an( is a s#a#e%en#, #ha# co%%an( is a %as#e"-#y*e+ 4ha# (o %ean 'i#h #ha#Q4e$$, fo" exa%*$e PIN is a s#a#e%en#+ S#a#e%en#s a"e co%%an(s 'hich (o so%e#hing, u# (o no#"e#u"n any#hing+ hey =us# (o so%e#hing+ i&e PIN, i# *"in#s so%e#hing on #he sc"een, an( i#(oesn.# (o %o"e+

4e$$, #he #hing is, #ha# #he"e a"e ;unc#ions #oo+ ;unc#ions a$'ays "e#u"n a !a$ue o" a s#"ingan( can ne!e" s#an(-a$one+ us# #"y #o #y*e HIU139 in #he DE an( #"y #o "un+ >ou)$$ ge# an e""o"O4hyQ Si%*$y ecause HIU "e#u"ns a !a$ue, u# #he B DE can.# (o any#hing 'i#h i#, (oes #heDE has #o sho' i# on #he sc"eenQ /" (oes i# ha!e #o *u# i# in a !a"ia$eQ ha#)s 'hy func#ions ne!e" a"e s#an(a$one, you a$'ays ha!e #o s*ecify 'ha# #he B DE has #o (o 'i#h #he "e#u"n !a$ue+ >ou

can say: PIN HIU139 o" MyS#"ingU < HIU139+ Because no' #he DE &no's 'ha# i# has#o (o 'i#h i#+ n #he fi"s# case, i# *"in#s #he "e#u"ns !a$ue of h"U139 #o #he sc"een, in #he $a##e", i#s#o"es #he "e#u"n !a$ue of h"U139 in MyS#"ingU+

B a$so &no's #hings #ha# a"e ca$$e( .ex*"essions)+ Ex*"essions a"e so%e &in( of fo"%u$as$i&e 3 1+ >ou ha!e of#en use( ex*"essions a$"ea(y, a$#hough you *"oa$y (i(n.# &no' #ha#+Ex*"essions can a$so con#ain func#ions $i&e #his one: 3 SI59+ he SI func#ion si%*$yca$cu$a#es #he Sua"e Ioo# of, in #his case, 5+ us# $i&e func#ions, ex*"essions a"e no# s#an(a$one+his is !e"y easy #o ex*$ain+ ;o" ins#ance, if you #y*e 3 3 in #he DE #hen #"y #o "un i#, you)$$ ge#e""o"s, 'hyQ Because 'hen #he co%*i$e" sees #he $ine .33) you =us# #y*e(, i# #hin&s .h""%%% 33an( #henQ 33 so 'ha#Q 4ha# (o ha!e #o (o 'i#h 33Q) >ou can fo" ins#ance s*ecify #ha# #heans'e" of 33 %us# e *"in#e( #o #he sc"een, o" #ha# i# %us# e s#o"e( in a !a"ia$e+ By (oing #his:

PRINT : J :

6ns;er3 A : J :

$so, func#ions an( ex*"ession can e nes#e(, #he s#a#e%en#s canno#+ Si%*$y $oo& a# #hefo$$o'ing exa%*$e, i# $oo&s &in(a co%*$ex, u# i# is ac#ua$$y #he B-fo"%u$a Ma#hsOOIe%e%e"Q9+

PRINT “This is the 6K"-Gorm/la "alc/lator”

PRINT “.o/ m/st enter al/es ;ith the corresponding”

PRINT “form/la( y A a C & L < J 1 C & J c”INP7T “Please enter a(”4 a!

INP7T “Please enter 1(”4 1!

INP7T “Please enter c(”4 c!

PRINT

DM A 1! L < ' C a! C c!

PRINT “Discriminant A”= DM

O* A F-1! 5RFDM)) F< C a!)

O< A F-1! J 5RFDM)) F< C a!)

PRINT “Girst Qero-point at & A”= O*

PRINT “5econd Qero-point at & A”= O<

END

ho*e you un(e"s#an( i#7 8-9+

Page 10: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 10/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 10 of 23

STRUCTURE I: CHOICES

B is a$so a$e #o %a&e choices, y a s*ecia$ co%%an( ca$$e( .;)+ >ou %us# s*ecify anex*"ession 'hich %us# "e#u"n a oo$ean9 ehin( #he ;, #hen a .HEN) #hen #y*e 'ha# is going #oha**en if you" ex*"ession is #"ue+ Pe"ha*s i#)$$ e %o"e c$ea" if sho' you an exa%*$e:

PRINT “Please enter a n/m1er”

INP7T “N/m1er(”4 n/m1er3

IG n/m1er3 A THEN PRINT “.o/ entered a Qero”

IG n/m1er3 S THEN PRINT “.o/ didn0t enter a Qero”

4hen you "ea( #his *"og"a%, i# shou$( ha!e een c$ea"e( u* y no', ecause you no' &no'#ha# #he fi"s# f chec&s if nu%e" < 0 an( if so, i# *"in#s .you en#e"e( a Ge"o) on #he sc"een+ he

secon( chec&s fo" nu%e" ≠ 0 an( if so, i# *"in#s .you (i(n.# en#e" a Ge"o) on #he sc"een+

n B, #he cha"ac#e" ≠ (oesn.# exis#+ ns#ea( of #ha#, you shou$( use WX fo" .no# eua$ #o)+

c#ua$$y, #he fi"s# exa%*$e 'as inefficien#, ecause 2 if co%%an(s 'e"e nee(e(+ cou$(ex#en( you" &no'$e(ge no' y sho'ing you #his exa%*$e:

PRINT “Please enter a n/m1er”

INP7T “N/m1er(”4 n/m1er3

IG n/m1er3 A THEN PRINT “ER#!” E$5E PRINT “No ero! (F”

>ou)$$ *"oa$y a$"ea(y un(e"s#an( 'ha# #his *"og"a% (oes, u# $e#)s ex*$ain anyho'+ he f co%%an( no' chec&s if nu%e" is eua$ #o 0, if so, i# *"in#s .Ge"oO) on #he sc"een, if no# i# *"in#s.no Ge"oO) on #he sc"een+

his f-s#"uc#u"e can e %o"e ex#en(e( y s#a"#ing a secon( $ine+ his is !e"y han(y, ecause#hen you can execu#e %o"e co%%an(s 'hen an ex*"ession is #"ue+ 4a#ch #his:

PRINT “Please enter a n/m1er”

INP7T “N/m1er(”4 n/m1er3

IG n/m1er3 A THEN

  PRINT “Diision 1y Qero isn0t allo;edU”

  PRINT “Please try again”

  END

E$5E

  PRINT “This entry ;ill not ca/se an error”

  PRINT “Keca/se there is no diision 1y Qero”  PRINT “The ans;er is(”= * n/m1er3

END IG

#hin& #his exa%*$e shou$( e c$ea" enough+ ;o" #he ones 'ho (on.# un(e"s#an(, #his *"og"a% 'i$$ ca$cu$a#e 1Ynu%e" fo" a nu%e" en#e"e( y #he use"+ f #he use" en#e"s a 0, #he *a"# e#'een #he f an( #he E$se 'i$$ e execu#e(+ f i# isn.# a 0, #he *a"# e#'een #he E$se an( #he En( f is exec#u#e(+

 Note: i% you put the "hole $& statement on one line, "hich is possile, you don‘t have to use

an ‘'nd $%(# )his is only used %or $% statements "hich are not "ritten on one line# )he 'nd $% simply

de%ines "here the piece o% code, "hich elongs to an $%-statement, ends#

he"e)s ac#ua$$y 1 func#ion of f $ef#, 'hich is .E$seif)+ "y #o un(e"s#an( #his exa%*$e:

10

10

Page 11: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 11/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 11 of 23

PRINT “Please enter a n/m1er”

INP7T “N/m1er(”4 n/m1er3

IG n/m1er3 THEN

  PRINT “The n/m1er is smaller than Qero”

E$5EIG n/m1er3 A THEN

  PRINT “The n/m1er is Qero”E$5E

  PRINT “The n/m1er is larger than Qero”

END IG

END

s you can see he"e, #he E$seif-*a"# of an f-s#a#e%en# si%*$y is so%e &in( of ano#he" f s#a#e%en#+ he on$y (iffe"ence e#'een '"i#ing i# $i&e in #he exa%*$e an( '"i#ing i# se*a"a#e( 2(iffe"en# f-s#a#e%en#s9 is #ha#, 'hen you '"i#e #he% se*a"a#e(, #hey can o#h e execu#e(, if you'"i#e #he% as ao!e, on$y 1 of #he choices #ha# a"e *"esen#e( 'i$$ e execu#e(, 'hich usua$$y is #hefi"s# f-*a"#, 'hich has an ex*"ession 'hich is #"ue+

>ou can a(( as %uch E$seif-*a"#s as you 'an#+ $so, #he E$se *a"# is no# necessa"y+ $so,E$seif-*a"#s %ay on$y e use( if an f-s#a#e%en# is no# on 1 $ine, 'i#h E$se #his is *ossi$e+ See 2n(exa%*$e of #his cha*#e"9+

;o" $a"ge se$ec#ions, you shou$(n.# use f, u# Se$ec#, 'hich is #he fo$$o'ing su=ec#+Because '"i#ing 100 E$seif)s is ui#e so%e 'o"& 8-9 9+

STRUCTURE II: CHOICES

he syn#ax of Se$ec# is !e"y easy+ See #his exa%*$e 'hich is #he sa%e as ao!e9:

PRINT “Please enter a n/m1er”

INP7T “N/m1er(”4 n/m1er3

5E$E"T "65E n/m1er3

  "65E *4 <4 :

  PRINT “The n/m1er is either *4 < or :”

  "65E I5 S :

  PRINT “The n/m1er is greater than :”

  "65E I5

  PRINT “The n/m1er is smaller than ”

  "65E E$5E  PRINT “The n/m1er is a n/m1er ;hich I don0t 2no;”

END 5E$E"T

END

Se$ec# no# on$y is $ess #y*ing, i#)s a$so %uch c$ea"e" #han f+ E!e"yone shou$( un(e"s#an('ha# #his *"og"a% (oes+

5E$E"T "65E arname Defines #he eginning of a Se$ec#-*a"#+ a"na%e is #he!a"ia$e 'hich has #o e chec&e( using #his Se$ec#s#"uc#u"e+

"65E option [4 option4 >>"65E I5 e&pression

"65E E$5E

ase (efines a co(e *a"# fo" if a"na%e < one of #heo*#ions s*ecifie(+ >ou can a$so use an ex*"ession incon=unc#ion 'i#h S, ecause7 #"y #his 'i#hou# S:

11

11

Page 12: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 12/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 12 of 23

!a"na%e is s%a$$e" #han 0+ 4i#h o*#ions9+ hen you)$$ ha!e#o en#e" e!e"y !a$ue e$o' 0+ # is %uch han(ie" if you saySE S W 0 ins#ea( of enu%e"a#ing a$$ *ossi$e !a$ues

 e$o' 0+ he co(e e$o' ase E$se 'i$$ on$y e execu#e( if no o#he" s*ecifie( cases a"e #"ue+ $so, #he co(e #ha# 'i$$ eexecu#e( 'hen a ase is #"ue, 'i$$ e e!e"y#hing un#i$ a

nex# ase o" an En( Se$ec# is "eache(+END 5E$E"T Deno#es #he en( of a se$ec# s#"uc#u"e+

STRUCTURE III: JUMPING

u%*ing is no# #oo of#en use(, u# is 'o"#h #a$&ing aou#+ Si%*$y ecause ne'ies an( eginne"s use =u%*ing a $o# 8-9 9+ u%*ing can e achie!e( y 2 co%%an(s, o#o an( osu+ )$$a$so ex*$ain #he% in #ha# o"(e"+ So go#o fi"s#:

6gain(

PRINT “IVll calc/late *n for yo/”

PRINT “Ftype a to end)”

INP7T “Please enter n(”4 n3

IG n3 A THEN @#T# no;end

6ns;erM A *M n3

PRINT “The ans;er is(”= 6ns;erM

PRINT

PRINT “Do yo/ ;ant to enter another nB”

Type6gain(

INP7T “FWn)(”4 yesorno

.esorno A 7"65EFyesorno) 0conert to /ppercase

IG yesorno A “” THEN  @#T# 6gain

E$5EIG yesorno A “N” THEN

  @#T# no;end

E$5E 0/ser typed no N or

  @#T# Type6gain

END IG

no;end(

END

s you cou$( see in #his !e"y exagge"a#e( *"og"a%, o#o is use( #o =u%* ac& in you" co(e$i&e // gain (oes9, o" fo"'a"( $i&e // no'en(9+ o#o %us# e use( in con=unc#ion 'i#ha $ae$+ >ou %us# s*ecify a $ae$ so%e'he"e in you" co(e, y #y*ing you" $ae$)s na%e fo$$o'e( ya co$on F:R+ hen you can use o#o you"$ae$)sna%e #o =u%* #o you" $ae$+ ;"o% #he"e, #he *"og"a%s#a"#s "unning as no"%a$+

$a1el( Defines a $ae$ 'i#h na%e .$ae$)+ >ou can fi$$ you" o'n na%e in fo" .$ae$), $i&e(one in #he exa%*$e+

@#T# la1el u%*s #o #he $ae$ ca$$e( .$ae$)+ ;"o% #he"e, #he *"og"a% 'i$$ con#inue+

f you "efe" #o a $ae$ using o#o9 #ha# (oesn.# exis#, you)$$ ge# an e""o"+

n so%e cases, o#o can e han(y+ Ho'e!e", o!e"use of #he co%%an( 'i$$ "esu$# in 'ha# isca$$e( .s*aghe##i-co(e)+ he co(e 'i$$ #hen e #ha# co%*$ex, #ha# e!en #he es# *"og"a%%e" can.#

12

12

Page 13: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 13/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 13 of 23

un(e"s#an( #he co(e, 'hich is (ue #o #he fac# #ha# 'hen using o#o, #he co(e can e "un onnu%e"ous 'ays+ So use o#o 'i#h cau#ion+

ha#)s 'hy #hey in!en#e( .osu)+ 4hich 'i$$, in so%e cases, 'o"& %o"e efficien# #hano#o+ By (ec$a"ing a %o(u$e-$e!e$ su, #his 'o"&s a$%os# #he sa%e as a *"oce(u"e o" func#ion Suo" ;unc#ion9+ he on$y (iffe"ence e#'een osu an( o#o is #ha# osu "eui"es a .Ie#u"n)

s#a#e%en#+ s you)( a$"ea(y seen in #he exa%*$e ao!e, o#o (oesn.# "eui"e any+ 4e$$, $e#)s =us#sho' you an exa%*$e:

"$5

PRINT “I can calc/late contents”

PRINT “Please enter ;hich contents yo/ ;ant to calc/late”

PRINT “Fc/1e4 cylinder4 1all)”

6gain(

INP7T “Type it here(”4 choice

"hoice A $"65EF$TRI?FRTRI?Fchoice)))

"ont3 A

5E$E"T "65E choice"65E “c/1e”

INP7T “Please enter l(”4 l3

"65E “cylinder”

INP7T “Please enter r(”4 r3

INP7T “Please enter h(”4 h3

"65E “1all”

INP7T “Please enter r(”4 r3

"65E E$5E

@#T# 6gain

END 5E$E"T

IG choice A “c/1e” THEN@#57K calcc/1econt

E$5EIG choice A “cylinder” THEN

@#57K calccylindercont

E$5EIG choice A “1all” THEN

@#57K calc1allcont

END IG

PRINT “ "ontents(”= "ont3

END

"alcc/1econt(

"ont3 A l3 L :RET7RN

"alccylindercont(

"ont3 A :U*'*+! C Fr3 L <) C h3

RET7RN

"alc1allcont(

"ont3 A F' :) C :U*'*+! C Fr3 L :)

RET7RN

#hin& i# is c$ea" y no', u# $e#)s ex*$ain anyho'+ he osu co%%an( on $ine 21, "efe"s #oa $ae$ ca$$e( .ca$ccuecon#)+ n #he *"e!ious sec#ion aou# o#o, )!e a$"ea(y ex*$aine( 'ha# a$ae$ can (o+ he *"og"a% #hen =u%*s #o #ha# $ae$, "unning e!e"y#hing 'ha# is sai( e$o'+ n#i$ #he

13

13

Page 14: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 14/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1C of 23

 *"og"a% a""i!es a# a .Ie#u"n)+ 4hich is use( #o sho' #he *"og"a% #he *iece of co(e #o e "un is o!e" an( #he *"og"a% =u%*s ac& #o #he osu co%%an( i# ca%e f"o%, u# no' igno"ing i# an( #hus,

 *"ocee(ing 'i#h #he co(e af#e" #he osu co%%an(+

@#57K la1el 4o"&s a$%os# #he sa%e as o#o+ Ha!e #he *"og"a% =u%* #o #he s*ecifie($ae$+

RET7RN osu "eui"es #his co%%an(, s*ecifying #he en( of #he .$ae$-co(e)+4hen "eaching #his co%%an(, #he *"og"a% =u%*s ac& #o #he $as# osuco%%an( i# ca%e f"o%+

4hen ei#he" o!e"using #he osu co%%an(, o" nes#ing #he%, #his 'i$$ "esu$# in a %e%o"ye""o"+ So #"y #o a!oi( i#+

 Nesting is conseuently putting commands o% the same purpose in eachother# )his is e#g#

 possile "ith $%-statements *putting an $% inside an $%, "hich also is inside an $%+# $t can also e done

"ith osu or elect# Later on, you(ll learn that it is also possile "ith .o, &or and /hile#

CHAPTER PROGRAM

Iea(yQ ho*e so+

6gain(

"$5

"#$#R *+4 *

PRINT “AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”

PRINT “ AAAAAAAAAAA AAAAAAAAAAA”

PRINT “ AAA Palindromotron AAA”

PRINT “ AAAAAAAAAAA AAAAAAAAAAA”

PRINT “AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”"#$#R %4

PRINT “This program is capa1le of reersing”

PRINT “;ords4 sentences or entire te&tsU”

DI? The5tring 65 5TRIN@4 End5tring 65 5TRIN@

INP7T “Please enter some(”4 The5tring

The5tring A $TRI?FRTRI?FThe5tring))

IG $ENFThe5tring) A THEN @#T# 6gain

@#57K reersestring

PRINT “This is it4 reersed( ”= End5tringPRINT

Enter6gain(

PRINT “Do yo/ ;ant to enter some te&t againB Fyn)”

INP7T “Fyn)(”4 choice

"hoice A $TRI?FRTRI?F7"65EFchoice)))

IG "hoice A “.” THEN @#T# 6gain

IG "hoice A “N” THEN END

0the program ;ill only get here if "hoice ≠ “.” 6ND "hoice ≠ “N”

@#T# Enter6gain

Reersestring(0this f/nction can act/ally 1e made m/ch 1etter /sing G#R or ,HI$E

01/t since yo/ haen0t had them yet4 I do it ;ith @#T#

1C

1C

Page 15: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 15/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 15 of 23

Ne&t"har(

"/rrentPos A $ENFThe5tring)

End5tring A End5tring J ?IDFThe5tring4 "/rrentPos4 *)

"/rrentPos A "/rrentPos * 0decrease "/rrentPos ;ith *

IG "/rrentPos S THEN @#T# Ne&t"har

RET7RN

EXERCISES

Exe"cise V1: Ma&e a &in( of uiG+ Sho' aou# 20 ues#ions an( a# #he en( ho' %any youha( guesse( '"ong+

Exe"cise V2: Ma&e a *"og"a% #ha# coun#s #he nu%e" of e o" E in an en#e"e( s#"ing, an(sho's #ha# nu%e"+

Exe"cise V3: Ma&e a *"og"a% 'hich as&s #he use" #o en#e" as %uch !a$ues #he use" 'ou$($i&e #o, #hen ca$cu$a#es #he a!e"age of #he nu%e"s+

Exe"cise VC HIDO9: Ma&e a #ex# a(!en#u"e+ f you (on.# &no' 'ha# a #ex# a(!en#u"ega%e is, #"y (o'n$oa(ing .Ne*#une a!e"ns) a# '''+ne%esis+co%+

15

15

Page 16: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 16/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 16 of 23

LOOPS & BOOLEAN OPERATORS (V)BOOLEAN OPERATORS

Boo$ean /*e"a#o"s a"e use( #o *as#e #'o o" %o"e ex*"essions #oge#he"+ E+g+ you %a(e a(a#aase *"og"a% aou# you" c$ass%a#es+ >ou sea"ch #h"ough #he (a#aase fo" so%eone 'ho)s ca$$e(.B$ueZeyoa"() an( $i!es in a #o'n ca$$e( .ae#he";ox) an( is 15 yea"s o$(+ >ou cou$( (o #his $i&e

#his:

IG name A “Kl/eXey1oard” THEN

IG city A “aetherGo&” THEN

IG age3 A *+ THEN

0yeah!!! .o/ fo/nd him!

END IG

END IG

END IG

his co(e $oo&s c$ean+ Bu# can you i%agine ho' %uch you ha!e #o #y*e 'hen you ha!e

%o"e c"i#e"iaQ oo& a# #his one:

IG Fname A “Kl/eXey1oard”) 6ND Fcity A “aetherGo&”) 6ND Fage3 A

*+) THEN

0fo/nd!!!!

END IG

f you *"onounce #he co(e =us# $i&e i# says, i# is a$"ea(y c$ea"+ n #his co(e, .ND) is a oo$ean o*e"a#o", 'hich, in #his case, *as#es #'o c"i#e"ia #oge#he"+ He"e)s #he "es#:

 AND   True False   XOR    True False

True Tr/e Galse   True Galse Tr/eFalse Galse Galse   False Tr/e Galse

OR    True False   EQV    True False

True Tr/e Tr/e   True Tr/e Galse

False Tr/e Galse   False Galse Tr/e

IMP   True False True False

True Tr/e Galse   NOT Galse Tr/e

False Tr/e Tr/e

hese sche(u$es a"e ca$$e( .;-#a$es) 'hich s#an(s fo" ."ue-;a$se a$es)+ n #hesesche(u$es you can see 'ha# an o*e"a#o" "e#u"ns 'hen e!a$ua#ing #he c"i#e"ia+ s you a$"ea(y &no',an f-s#a#e%en# is on$y "un if #he c"i#e"ia is IE+ So if #he c"i#e"ia is .5 < 5) #hen #his 'i$$ e IE

 ecause in #his case, fi!e 'i$$ a$'ays e fi!e+ Ho'e!e", 'hen you use 2 o" %o"e c"i#e"ia, you)$$ nee(#o s*ecify #he $in& e#'een #he c"i#e"ia+ E+g+ (oes e!e"y c"i#e"ia has #o e #"ueQ hen use ND+He"e)s so%e co(e #o ge# use( #o i#:

6 A *

K A <

" A :

D A '

IG F6 A *) 6ND FK A <) THEN

0this ;ill only 1e r/n if 6 is eY/al to * 6ND K is eY/al to <U

END IG

16

16

Page 17: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 17/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1@ of 23

IG F6 A <) #R F" A :) THEN

0this code ;ill only 1e r/n if one of 1oth criteria is tr/e4 or

0;hen 1oth are tr/eU 5o this code ;ill 1e r/n ;hen(

06 A < and " S :

06 S < and " A :

06 A < and " A :

0so or is ery fle&i1leUEND IG

IG F" A :) O#R FD A :) THEN

0this code ;ill only 1e r/n if one of 1oth criteria is tr/eU

0if 1oth are tr/e4 this is not r/n Falso ;hen 1oth are false)U

05o this code ;ill 1e r/n ;hen(

0" A : and D S :

0" S : and D A :

END IG

IG FD A ') E F6 A *) THEN0this code ;ill only 1e r/n if 1oth are tr/e4 or 1oth are falseU

05o it ;ill 1e r/n ;hen(

0D A ' and 6 A *

0D S ' and 6 S *

0I seldom /se E tho/gh

END IG

IG FK A :) I?P F6 A *) THEN

0this code ;ill 1e r/n ;hen 1oth are tr/e4 ;hen 1oth are false

0or ;hen only the first one is tr/e Fif the second is tr/e and

0the first is not4 this code is not r/n)U05o ;hen(

0K A : and 6 A *

0K S : and 6 S *

0K A : and 6 S *

0Neer /se it often tho/gh

END IG

f you)( s#u(ie( #he ;-Sche(u$es 'e$$, you 'ou$( ha!e no#ice( one #hing+ ou# #he.N/) o*e"a#o"+ he (iffe"ence is #ha#, ND, /I, J/I, E an( MP a"e ina"y-o*e"a#o"s, an(#ha# N/ is an una"y-o*e"a#o"+ 4ha# (oes #his %eanQ 4e$$ i#)s ac#ua$$y !e"y si%*$e+ he ina"y

o*e"a#o"s $in& 2 c"i#e"ia #oge#he", 'hi$e una"y o*e"a#o"s $in& on$y 1+ So N/ on$y $in&s 1+ Bu# ho'QSi%*$e, N/ #u"ns a"oun( #he !a$ue of a$$ inne" !a$ues+ Exa%*$e:

IG N#TF6 A +) THEN

0this code is only r/n if 6 is not eY/al to +U If 6 A + then the

0e&pression 1et;een the 1rac2ets is tr/e4 1eca/se 6 A +U Then not

0t/rns aro/nd that al/e4 so it is conerted to falseU 6lso4 ;hen

06 A '4 the inner e&pression is false4 1eca/se 6 A + is false

01eca/se 6 A '4 so not conerts false to tr/e4 and the if-cla/s/le

0is r/nU

END IG

IG N#TF6 A * 6ND K A <) THEN

0this code is r/n if the inner e&pression is false Fnot conerts

1@

1@

Page 18: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 18/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1A of 23

0false to tr/e)U In the te&t a1oe a1o/t 6ND yo/ can find o/t ;hen

0the inner e&pression ;ill 1e falseU

END IG

i$$ no', &e*# i# easy+ Bu# you can a$so i%agine #ha# so%e#i%es, *eo*$e nee( !e"y co%*$exs#"uc#u"es+ 4hen using %o"e #han 1 ina"y o*e"a#o", you shou$( a$so a**$y "ac&e#s #o you" co(e so

#he B DE &no's 'hich ina"y o*e"a#o" #o e!a$ua#e fi"s#+ He"e)s a !e"y co%*$ex exa%*$e:

IG FFFscore A <) 6ND Fleel A +)) #R FFdeaths A *) E F/nits S

<))) 6ND FN#TF7 A 9 I?P 2ills *) O#R Fs2ill S +)) THEN

0find o/t yo/rself ;hen this code ;ill 1e r/n!! (-D =C)

END IG

LOOPS I: FOR … NEXT

he"e a"e 5 'ays #o inco"*o"a#e $oo*s insi(e you" *"og"a%, of 'hich $ea"n# you 2 of #he%!iG+ o#o an( osu9+ his su-cha*#e" is aou# #he ;o" $oo*+ ;o" is ac#ua$$y a coun#e"-$oo*+ >ous*ecify a s#a"# !a$ue an( an en( !a$ue+ n( #he in#e"na$ !a"ia$e &ee*s inc"easing un#i$ i# *asse( #heen( !a$ue+ hen a ;o"-$oo* is exi#e(+ "y #his !e"y c$ea" exa%*$e:

G#R internalar A * T# * 5TEP *

PRINT internalar

NEOT internalar

s you can see 'hen you "un #his *"og"a%, #he nu%e"s 1 u* #o an( inc$u(ing 100 a"e *"in#e( on #he sc"een+ Ho')s #ha# *ossi$eQ 4e$$, fi"s# you say #ha# in#e"na$!a" < 1, i# has #o go #oo100 'i#h s#e*s of 1 in siGe+ hus, #he fo" eua$s in#e"na$!a" #o 1, "uns a$$ #he co(e enea#h, un#i$ i#

encoun#e"s a .Nex#) co%%an(+ He"e i# says .Nex# in#e"na$!a") so #he *"og"a% =u%*s ac& #o #he.;o" in#e"na$!a" 7e#c7+) an( inc"eases in#e"na$!a" y s#e*, 'hich he"e is 1+ So #he secon( #i%e #heco(e 'i$$ e "un, in#e"na$!a" 'i$$ eua$ 2+ hen 3, #hen C, 5, 6, @, e#c7 u* #o an( inc$u(ing 100+hen #he *"og"a% sees #he s*ecifie( $i%i# has een "eache( an( no' s&i*s #he .Nex#) co%%an('hen i# a""i!es #he"e+

he fo"-"ou#ine is !e"y f$exi$e an( can a$%os# e use( fo" e!e"y#hing 'ha# is in nee( of acoun#e"+ a&e a $oo& a# #his exa%*$e:

PRINT “Please enter some te&t”

INP7T “Here(”4 somete&t

G#R co/nter A * T# $ENFsomete&t)PRINT ?IDFsomete&t4 co/nter4 *)

NEOT co/nter

0the loop ;ill r/n from * to the length of the te&t yo/ enteredU

0then it prints the co/nterth character of the te&t on a lineU

# (oesn.# %a##e" if you can.# ye# un(e"s#an( #his+ he on$y #hing #ha# %a##e"s is #ha# youun(e"s#an( 'ha# ;o" (oes an( ho' an( 'hen #o use i#+

)he step-%actor is optional, ut "hen le%t a"ay, the *virtual+ step-%actor "ill al"ays e 0#

LOOPS II: DO … LOOP

he secon(, u# =us# as i%*o"#an#, $oo* is #he Do-oo* "ou#ine+ /n #he con#"a"y #o ;o"-Nex#,Do-oo* is no# a coun#e"+ Do-oo* can e 2 (iffe"en# &in( of #hings+ iG+ an en($ess $oo* a$so:

1A

1A

Page 19: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 19/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 1 of 23

.e#e"na$ $oo*)9, o" an ex*"ession-'ai#e" $oo*s a"oun( un#i$ an ex*"ession is #"ue o" 'hi$e anex*"ession is #"ue9+ He"e)s an exa%*$e aou# #he e#e"na$ $oo*:

D#

PRINT “6l;ays the same te&t!!! (C)”

$##P

P"ess K#"$L KB"ea&L si%u$#aneous$y #o i%%e(ia#e$y s#o* #he *"og"a% an( "e#u"n #o #heDE+

s you can see 'hen "unning #his *"og"a%, #he co%%an(s e#'een #he Do-oo* a"e "un fo" e!e" an( #he"efo"e #he *"og"a% 'i$$ ne!e" s#o*+ Ho' i# ac#ua$$y 'o"&s is ui#e si%*$e: #he *"og"a%encoun#e"s a .Do) an( "e%e%e"s 'he"e i# 'as, "uns so%e co%%an(s, #hen encoun#e"s a .oo*) an(#he *"og"a% 'i$$ =u%* ac& #o #he $as# .Do) i# encoun#e"e( ac#ua$$y i# is #he (o 'he"e #he $oo*

 e$ongs #o9+He"e a"e 2 exa%*$es aou# #he ex*"ession-$oo*:

DI? I 65 INTE@ERI A

D#

I A I J *

PRINT I

$##P 7NTI$ FI A *)

PRINT “Girst e&ample endedU”

I A

D# ,HI$E I *

I A I J *PRINT I

$##P

PRINT “$oops endedU”

END

>ou can see #he ex*"ession can e a((e( #o a Do-oo* "ou#ine y a((ing an n#i$ o" a4hi$e+ Bo#h nee( an ex*"ession, o" %o"e $in&e( y using Boo$ean /*e"a#o"s+ s you cou$( ha!ea$"ea(y &no'n y *"onouncing #he co(e9, a Do-oo* "ou#ine 'i#h 4hi$e, 'i$$ "un #he co(e 'hi$eso%e &in( of ex*"ession is #"ue, an( i# 'on.# e "un any%o"e if #ha# ex*"ession is fa$se+ he Do-oo* "ou#ine 'i#h n#i$ 'i$$ "un 'hi$e so%e &in( of ex*"ession is no# #"ue, an( 'i$$ exi# #he $oo*'hen #he ex*"ession is #"ue+ P"onounce: oo* #he $oo* 'hi$e %y sco"e is s%a$$e" #han 100, o" oo*#he $oo* un#i$ %y sco"e is g"ea#e" #han 100, fo" exa%*$e9+

I A *

PRINT “Grom the first loop(”

D#

PRINT I

$##P 7NTI$ I A *

PRINT "HRF*:)= “Grom the second loop(”

D# 7NTI$ I A *

PRINT I

$##P

1

1

Page 20: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 20/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 20 of 23

he exa%*$e ao!e 'as (ea$ing 'i#h #he (iffe"ence e#'een Do n#i$ an( oo* n#i$ 'ha#'i$$ e ex*$aine( no' is #he sa%e fo" Do 4hi$e an( oo* 4hi$e9+ s you cou$( ha!e no#ice( 'hen"unning #he *"og"a%, f"o% #he fi"s# $oo* i# says .1) an( f"o% #he secon( $oo* i# says no#hing+ his

 *heno%enon can easi$y e ex*$aine(, $e#)s =us# s#a"# a# #he fi"s# $oo* sho' you 'ha# #he *"og"a%.#hin&s)9+

ine 1: aah, a ne' !a"ia$e ca$$e( + S#o"e !a$ue 1 in +

ine 2: P"in# F;"o% #he fi"s# $oo*R #o #he sc"een+ine 3: aah, #he s#a"# of a Do-oo*+ine C: P"in# #o #he sc"een+ine 5: h""%%, .oo* un#i$ < 1), 'e$$, is eua$ #o 1 so $e#)s exi# #he $oo*+ine @: P"in# an en#e" an( #he #ex# F;"o% #he secon( $oo*R #o #he sc"een+ine A: S#a"# of a Do-oo*, an( since #he $oo* %us# e exi#e( 'hen eua$s 1, an( since s#i$$

eua$s 1, 'on.# "un #he $oo* an( 'i$$ =u%* i%%e(ia#e$y #o #he oo* #he Do e$ongs #o+ine 10: =u%*e( f"o% ine A #o ine 10+

# shou$( e c$ea" no', if no#, *$ay so%e 'i#h #he Do-oo* :[9+ # 'i$$ e c$ea" #o you in no#i%e+ n(7 if you s#i$$ (on.# un(e"s#an( af#e" *$aying 'i#h i#, he"e)s so%e !e"y sho"# ex*$ana#ion:

/hen the program encounters a .o-Loop 1ntil, the program %irst runs the code, and at the‘Loop 1ntil( it checks i% the expression is true, i% so, exit the loop, else, loop again# 2ut "hen the

 program encounters a .o 1ntil-Loop, it %irst checks i% the expression is true, i% so, exit the loop,

else, loop the loop, and "hen it arrived at the Loop, it 3umps ack to the .o 1ntil and checks again,

i% the expression is true no", the program "ill 3ump %or"ard to the Loop it came %rom and goes on

 %rom there#

LOOPS III: WHILE … WEND

he 3"( an( #he %os# uni%*o"#an# $oo*, is #he 4hi$e-4en(+ his $oo* ac#ua$$y (oes exac#$y

#he sa%e as Do 4hi$e-oo*, so consi(e" using #ha# one ins#ea(+ Ho'e!e", in so%e co(e 4hi$e-4en( is of#en use(, an( is #he"efo"e 'o"#hy #o e ex*$aine( he"e+ s a$"ea(y #o$(, 4hi$e-4en( issi%i$a" #o Do 4hi$e-oo*+ n ex*"ession shou$( e s*ecifie( af#e" #he 4hi$e, an( #he $oo* 'i$$ e"un if #he s*ecifie( ex*"ession is #"ue+ Exa%*$e:

$inesco/nted A

,HI$E $inesco/nted *

PRINT “This is line”= $inesco/nted J *

$inesco/nted A $inesco/nted J *

,END

his exa%*$e (oesn.# nee( %uch ex*$ana#ion+ us# *"onounce: .4hi$e #he $ines coun#e( is enea#h #he 100, (o #his)+

#hin& i#)s no' #i%e fo" an o!e"a$$-!ie'+

D# [,HI$E7NTI$ e&pression

>

$##P [,HI$E7NTI$ e&pression

Iuns co%%an(s e#'een #he Do an(#he oo* un#i$ o" 'hi$e an ex*"essionis #"ue+ 4hen no 4hi$es o" n#i$s a"euse(, #he $oo* 'i$$ "un fo"e!e"+

G#R co/nter A start T# end [5TEP factor

>

NEOT co/nter

Iuns co%%an(s e#'een #he ;o" an(#he Nex# 'hi$e a coun#e" is "unning+he .$oo*) 'i$$ e exi#e( if #he

coun#e" "eaches #he s*ecifie( en(-!a$ue+ he coun#e" s#a"#s a# s#a"# an(en(s a# en(, an( is inc"ease( e!e"y

20

20

Page 21: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 21/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 21 of 23

$oo* y fac#o"+ his .$oo*) is !e"yhan(y, fo" #he coun#e" is a !a"ia$e'hich you can use in you" co(e+

,HI$E [e&pression

>

,END

Han(y so%e#i%es, #his $oo* "unsco%%an(s e#'een #he 4hi$e an(#he 4en( 'hi$e an ex*"ession is #"ue+

he $oo* 'on.# e "un any%o"e9 if #he ex*"ession is fa$se+

once"ning Do-oo*, you can on$y s*ecify 1 ex*"ession *e" "ou#ine, so you can.# %a&e aDo 4hi$e-oo* 4hi$e o" a Do n#i$-oo* 4hi$e fo" exa%*$e9+

F AST EXIT COMMAND

Ho'e!e", you" $oo*s (on.# ha!e #o "un un#i$ so%e ex*"essions a"e #"ue o" fa$se, #hey can a$so e s#o**e( y ano#he" co%%an(, !iG+ .Exi#)+ Behin( #he Exi#-co%%an(, you ha!e #o '"i#e 'ha# has

#o e exi#e(, so you cou$( '"i#e .Exi# Do), #o exi# a Do-oo*+ He"e)s 'ha# you ha!e #o &no' fo" no':Exi# Do ? %%e(ia#e$y exi# a Do-oo*Exi# ;o" ? %%e(ia#e$y exi# a ;o"-Nex#

Exa%*$e:

I A

D#

I A I J *

IG I A * THEN EOIT D#

$##PPRINT “$oop e&ited at I A”= I

I A

G#R I A T# * 5TEP *

IG I A + THEN EOIT G#R

NEOT I

PRINT “Gor e&ited at I A”= I

END

#hin& #his is !e"y easy #o un(e"s#an(+

EOIT D#

EOIT G#R%%e(ia#e$y exi#s #he fi"s# s*ecifie( $oo*+ he $oo* of #ha# &in( is exi#e( if #hisco%%an( 'as in one of #he%+

CHAPTER PROGRAM

D#

"$5

PRINT “Prime n/m1er calc/lator!”

PRINT “Ky ?rU O”

PRINT

PRINT “This program calc/lates all prime n/m1ers /p to”

PRINT “a n/m1er n FN S *)”

N3 A

21

21

Page 22: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 22/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 22 of 23

,HI$E N3 A *

INP7T “Please enter n(”4 N3

,END

PRINT

PRINT “*”

PRINT “<”G#R primec A : T# N3 5TEP < 0step < 1eca/se only odd nrsU

Diida1le A

G#R primed A < T# primec * 5TEP *

IG primec primed A INTFprimec primed) THEN

Diida1le A *

EOIT G#R

END IG

NEOT primed

IG Diida1le A THEN PRINT primec

NEOT primec

PRINTPRINT “That ;ere allU”

PRINT “,ant to see moreB”

X A “a”

D#

INP7T “Fyes or no)(”4 X

$##P 7NTI$ $"65EFX) A “yes” #R $"65EFX) A “no”

IG $"65EFX) A “no” THEN EOIT D#

$##P

EXERCISES

Exe"cise V1: Ma&e a *"og"a% #ha# can ca$cu$a#e #he facu$#a#y of an inse"#e( nu%e"+ f you(on.# &no' 'ha# a facu$#a#y is, e+g+ #he facu$#a#y of 5 is 1 [ 2 [ 3 [ C [ 5 < 120+ he facu$#a#y of 10is 1 [ 2 [ 3 [ C [ 5 [ 6 [ @ [ A [ [ 10 < 362AA00+

Exi"cise V2: Ma&e a *"og"a% #ha# can ca$cu$a#e *e"fec# nu%e"s+ *e"fec# nu%e" is anu%e" of 'hich #he su% of a$$ (i!i(e"s is eua$ #o #ha# nu%e"+ E+g+ 2A is a *e"fec# nu%e",

 ecause #he (i!i(e"s a"e: 1, 2, C, @, 1C+ n( #he su% of #he (i!i(e"s is again 2AO

Exe"cise V3: Ma&e a *"og"a% 'hich can ca$cu$a#e co%ina#ions+ ;o" "ea(e"s 'i#h a i-A3,

#he *ossi$e co%ina#ions can e ca$cu$a#e( 'i#h n" %a#h-*"99+ he use" %us# e a$e #o inse"##he "ange an( #he $eng#h+ E+g+ if #he use" en#e"s a 3 fo" "ange, on$y #he nu%e"s 1, 2 an( 3 'i$$ euse( fo" co%ina#ions+ f #he use" en#e"s a C fo" $eng#h, #he *"og"a% ca$cu$a#es a$$ *ossii$i#ies 'i#h$eng#h C+ So 1111 an( 1321 a"e 2 of #he *ossi$e co%ina#ions+

Exe"cise VC: Easy one+ Ma&e a *"og"a% 'hich can ca$cu$a#e:

n

Σ i+i < 1

4hich %eans #his: 1 2 3 C 5 7 n+ So ca$cu$a#e #he su% of a$$ *osi#i!e in#ege"s u* #o an(inc$u(ing n+

22

22

Page 23: Qbasic Tutorial for Beginners and Newbies

8/16/2019 Qbasic Tutorial for Beginners and Newbies

http://slidepdf.com/reader/full/qbasic-tutorial-for-beginners-and-newbies 23/23

By Neo Deus Ex Machina, 20-05-16, HH:05, Page 23 of 23

C ATALOGUE

E!e"y co%%an(, func#ion, &ey'o"(, si%*$y e!e"y#hing9 'hich '"o#e aou# is in #his $is#+He"e you can fin( e!e"y &ey'o"( 'hich is (ea$# in #his *a"#+

6ND

6565"

"65E

"HR

"$5

"#$#R

DI?

D#

D#7K$E

E$5E

E$5EIG

ENDE

EOIT

G#R

@#57K

@#T#

IG

I?P

INP7T

INTE@ER

I5

$"65E$EGT

$EN

$#"6TE

$#N@

$##P

$TRI??ID

NEOT

N#T

#R

PRINT

RE?

RET7RN

RI@HT

RTRI?

5E$E"T

5IN@$E5$EEP

5P6"E

5TEP

5TR

5TRIN@

THEN

T#

7"65E

7NTI$

6$

,END,HI$E Fe&pression-;aiter)

,HI$E Floop-command)

O#R

 AFTERWORD

uic&BS-u#o"ia$ Pa"# : Beginne"s \ Ne'ies E(i#ionBy Neo Deus Ex MachinaMe%e" of #he B$in( o(ing *"og"a%%ing #ea%h##*:YY'''+$in(co(ing+c=+ne#2002-1@-10

han&s #o a$$ %e%e"s of #he B$in( o(ing *"og"a%%ing #ea%:e#he";oxB$ueZeyoa"(Mofu

 Neo Deus Ex Machina

THANKS FOR READING MY TUTORIAL

23