├── LICENSE ├── README.md ├── code ├── 14 │ ├── 14a.pb │ ├── 14b.pb │ └── 14c.pb ├── 15 │ ├── 15a.pb │ ├── 15b.pb │ └── 15c.pb ├── 16 │ ├── 16a.pb │ ├── 16b.pb │ └── 16c.pb ├── 17 │ ├── 17a.pb │ ├── 17b.pb │ └── 17c.pb ├── 18 │ ├── 18a.pb │ └── 18b.pb ├── 19 │ ├── 19a.pb │ ├── 19b.pb │ ├── 19c.pb │ ├── 19d.pb │ ├── 19e.pb │ └── 19f.pb ├── 20 │ ├── 20a.pb │ ├── 20b.pb │ ├── 20c.pb │ └── 20d.pb ├── 21 │ ├── 21a.pb │ └── 21b.pb ├── 22 │ ├── 22a.pb │ └── 22b.pb ├── 23 │ ├── 23a.pb │ └── 23b.pb ├── 25 │ ├── 25a.pb │ └── 25b.pb ├── 26 │ ├── 26a.pb │ └── 26b.pb ├── 27 │ └── 27a.pb ├── 28 │ ├── 28a.pb │ ├── 28b.pb │ └── 28c.pb ├── 29 │ ├── 29a.pb │ ├── 29b.pb │ └── 29c.pb ├── 30 │ ├── 30a.pb │ ├── 30b.pb │ ├── 30c.pb │ └── 30d.pb ├── 31 │ ├── 31a.pb │ └── 31b.pb ├── 32 │ ├── 32a.pb │ └── 32b.pb ├── 33 │ ├── 33a.pb │ ├── 33b.pb │ └── 33c.pb ├── 34 │ ├── 34a.pb │ └── 34b.pb ├── 38 │ └── 38a.pb ├── 39 │ ├── 39a.pb │ └── 39b.pb ├── 40 │ ├── 40a.pb │ └── 40b.pb ├── 41 │ ├── 41a.pb │ └── 41b.pb ├── 42 │ └── 42a.pb ├── 43 │ ├── 43a.pb │ └── 43b.pb ├── 44 │ ├── 44a.pb │ ├── 44b.pb │ └── 44c.pb ├── 45 │ ├── 45a.pb │ └── 45b.pb ├── 46 │ ├── 46a.pb │ ├── 46b.pb │ └── 46c.pb ├── 47 │ ├── 47a.pb │ └── 47b.pb ├── 48 │ ├── 48a.pb │ └── 48b.pb ├── 49 │ └── 49a.pb ├── 50 │ ├── 50a.pb │ ├── 50b.pb │ └── 50c.pb ├── 51 │ ├── 51a.pb │ └── 51b.pb ├── 52 │ └── 52a.pb ├── 53 │ ├── 53a.pb │ └── 53b.pb ├── 54 │ ├── 54a.pb │ └── 54b.pb ├── 56 │ └── 56a.pb ├── 58 │ └── 58a.pb ├── 59 │ └── 59a.pb ├── 60 │ └── 60a.pb ├── 61 │ └── 61a.pb ├── 62 │ └── 62a.pb ├── 63 │ ├── 63a.pb │ └── 63b.pb ├── 64 │ └── 64a.pb ├── 65 │ └── 65a.pb ├── 67 │ └── 67a.pb ├── 68 │ └── 68a.pb ├── 69 │ └── 69a.pb ├── 70 │ └── 70a.pb ├── 72 │ └── 72a.pb ├── 73 │ └── 73a.pb ├── 74 │ └── 74a.pb ├── 75 │ ├── 75a.pb │ ├── 75b.pb │ └── 75c.pb ├── 76 │ └── 76a.pb ├── 77 │ ├── 77a.pb │ ├── 77b.pb │ └── 77c.pb ├── 78 │ ├── 78a.pb │ └── 78b.pb ├── 79 │ ├── 79a.pb │ └── 79b.pb ├── 80 │ ├── 80a.pb │ └── 80b.pb ├── 81 │ ├── 81a.pb │ ├── 81b.pb │ └── 81c.pb ├── 82 │ ├── 82a.pb │ └── 82b.pb ├── 83 │ ├── 83a.pb │ └── 83b.pb ├── 84 │ ├── 84a.pb │ └── 84b.pb ├── 85 │ └── 85a.pb ├── 86 │ └── 86a.pb ├── 87 │ └── 87a.pb ├── 88 │ └── 88a.pb ├── 89 │ ├── 89a.pb │ └── 89b.pb ├── 91 │ ├── 91a.pb │ └── 91b.pb ├── 92 │ ├── 92a.pb │ └── 92b.pb ├── 96 │ └── 96a.pb ├── 98 │ └── 98a.pb ├── 99 │ ├── 99a.pb │ ├── 99b.pb │ └── 99c.pb ├── 100 │ └── 100a.pb ├── 101 │ ├── 101a.pb │ └── 101b.pb ├── 102 │ └── 102a.pb ├── 103 │ ├── 103a.pb │ └── 103b.pb ├── 104 │ ├── 104a.pb │ └── 104b.pb ├── 107 │ └── 107a.pb ├── 109 │ └── 109a.pb ├── 112 │ └── 112a.pb ├── 114 │ └── 114a.pb ├── 115 │ ├── 115a.pb │ └── 115b.pb ├── 117 │ └── 117a.pb ├── 118 │ └── 118a.pb ├── 119 │ └── 119a.pb ├── 120 │ └── 120a.pb ├── 123 │ ├── 123a.pb │ └── 123b.pb ├── 125 │ └── 125a.pb ├── 127 │ └── 127a.pb ├── 131 │ └── 131a.pb ├── 132 │ └── 132a.pb ├── 134 │ └── 134a.pb ├── 137 │ └── 137a.pb ├── 140 │ ├── 140a.pb │ └── 140b.pb ├── 143 │ └── 143a.pb ├── 145 │ └── 145a.pb ├── 148 │ └── 148a.pb ├── 150 │ └── 150a.pb ├── 151 │ └── 151a.pb ├── 154 │ └── 154a.pb ├── 156 │ └── 156a.pb ├── 157 │ ├── 157a.pb │ └── image.bmp ├── 159 │ ├── 159a.pb │ └── image.bmp ├── 161 │ ├── 161a.pb │ └── image.jpg ├── 168 │ └── 168a.pb ├── 171 │ ├── 171a.pb │ └── 171b.pb ├── 173 │ └── 173a.pb ├── 176 │ ├── 176a.pb │ ├── Ball.ico │ └── Gears.bmp ├── 178 │ ├── 178a.pb │ ├── Ball.ico │ └── Gears.bmp ├── 182 │ └── 182a.pb ├── 184 │ └── 184a.pb ├── 186 │ └── 186a.pb ├── 188 │ └── 188a.pb ├── 190 │ └── 190a.pb ├── 196 │ └── 196a.pb ├── 198 │ ├── 198a.pb │ └── Flower.png ├── 206 │ ├── 206a.pb │ └── Data │ │ ├── Invader.mesh │ │ └── Invader.png ├── 215 │ ├── 215a.pb │ └── Data │ │ ├── Detail.png │ │ ├── Global.png │ │ └── Terrain.png ├── 221 │ ├── 221a.pb │ └── Data │ │ ├── SphereMap.png │ │ ├── Statue.material │ │ ├── Statue.mesh │ │ └── flame.png ├── 227 │ ├── 227a.pb │ └── Intro.wav ├── 228 │ ├── 228a.pb │ └── Intro.wav ├── 229 │ ├── 229a.pb │ └── Intro.wav ├── 232 │ ├── 232a.pb │ └── Eighth.mod ├── 234 │ ├── 234a.pb │ └── Ride the Wind.mp3 ├── 237 │ └── 237a.pb ├── 247 │ └── 247a.pb ├── 248 │ ├── 248a.pb │ └── 248b.pb ├── 249 │ └── 249a.pb ├── 250 │ └── 250a.pb ├── 251 │ └── 251a.pb ├── 252 │ └── 252a.pb ├── 260 │ └── 260a.pb ├── 261 │ └── 261a.pb ├── 269 │ └── 269a.pb ├── 270 │ └── 270a.pb ├── 271 │ └── 271a.pb ├── 273 │ ├── 273a.pb │ └── 273b.pb ├── 274 │ └── 274a.pb ├── 275 │ ├── 275a.pb │ └── 275b.pb ├── 277 │ ├── 277a.pb │ ├── 277b.pb │ └── 277c.pb ├── 278 │ └── 278a.pb ├── 280 │ └── 280a.pb ├── 281 │ └── 281a.pb ├── 283 │ └── 283a.pb ├── 284 │ └── 284a.pb ├── 285 │ └── 285a.pb ├── 288 │ └── 288a.pb ├── 290 │ └── 290a.pb ├── 291 │ ├── 291a.pb │ ├── 291b.pb │ └── 291c.pb ├── 292 │ ├── 292a.pb │ ├── 292b.pb │ └── 292c.pb ├── 294 │ ├── 294a.pb │ ├── 294b.pb │ └── 294c.pb ├── 295 │ └── 295a.pb ├── 298 │ └── 298a.pb ├── 299 │ └── 299a.pb ├── 300 │ └── 300a.pb └── 301 │ └── 301a.pb ├── pdf └── PureBasic - A Beginners Guide.pdf ├── quarkxpress ├── book.qxd └── images │ ├── Back Cover (7.5 x 9.25).eps │ ├── Front Cover (7.5 x 9.25).eps │ ├── Gary.tif │ ├── InnerTitle.eps │ ├── SectionBacker.eps │ ├── cc-logo.tif │ ├── fig1.eps │ ├── fig10.eps │ ├── fig11.eps │ ├── fig12.eps │ ├── fig13.eps │ ├── fig14.eps │ ├── fig15.eps │ ├── fig16.eps │ ├── fig17.eps │ ├── fig18.eps │ ├── fig19.eps │ ├── fig2.eps │ ├── fig20.eps │ ├── fig21.eps │ ├── fig22.eps │ ├── fig23.eps │ ├── fig24.eps │ ├── fig25.eps │ ├── fig26.eps │ ├── fig27.eps │ ├── fig28.eps │ ├── fig29.eps │ ├── fig3.eps │ ├── fig30.eps │ ├── fig31.eps │ ├── fig32.eps │ ├── fig33.eps │ ├── fig34.eps │ ├── fig35.eps │ ├── fig36.eps │ ├── fig37.eps │ ├── fig38.eps │ ├── fig39.eps │ ├── fig4.eps │ ├── fig40.eps │ ├── fig41.eps │ ├── fig42.eps │ ├── fig43.eps │ ├── fig44.eps │ ├── fig45.eps │ ├── fig46.eps │ ├── fig47.eps │ ├── fig48.eps │ ├── fig49.eps │ ├── fig5.eps │ ├── fig50.eps │ ├── fig51.eps │ ├── fig52.eps │ ├── fig53.eps │ ├── fig54.eps │ ├── fig55.eps │ ├── fig56.eps │ ├── fig6.eps │ ├── fig7.eps │ ├── fig8.eps │ └── fig9.eps └── text ├── About The Author.txt ├── Appendix A.txt ├── Appendix B.txt ├── Appendix C.txt ├── Box 1.txt ├── Box 10.txt ├── Box 11.txt ├── Box 12.txt ├── Box 13.txt ├── Box 14.txt ├── Box 15.txt ├── Box 16.txt ├── Box 17.txt ├── Box 18.txt ├── Box 19.txt ├── Box 2.txt ├── Box 20.txt ├── Box 21.txt ├── Box 22.txt ├── Box 23.txt ├── Box 24.txt ├── Box 25.txt ├── Box 26.txt ├── Box 27.txt ├── Box 28.txt ├── Box 3.txt ├── Box 4.txt ├── Box 5.txt ├── Box 6.txt ├── Box 7.txt ├── Box 8.txt ├── Box 9.txt ├── Chapter 1.txt ├── Chapter 10.txt ├── Chapter 11.txt ├── Chapter 12.txt ├── Chapter 13.txt ├── Chapter 2.txt ├── Chapter 3.txt ├── Chapter 4.txt ├── Chapter 5.txt ├── Chapter 6.txt ├── Chapter 7.txt ├── Chapter 8.txt ├── Chapter 9.txt ├── Contents.txt ├── Index.txt ├── Inside Front Cover.txt ├── Preface.txt ├── Section 1.txt ├── Section 2.txt ├── Section 3.txt ├── Section 4.txt └── Section 5.txt /README.md: -------------------------------------------------------------------------------- 1 | # Purebasic - A beginner's guide to computer programming 2 | **(2006)** 3 | 4 | --- 5 | 6 | ## Overview 7 | 8 | This is a book I wrote in 2006 to teach new programmers the [Purebasic](https://www.purebasic.com/) language. Github seemed a fitting place to let it live out the rest of its life. 9 | 10 | Purebasic - A Beginner's Guide To Computer Programming (2006) is an essential guide for newcomers to Purebasic or computer programming in general. If you are an experienced programmer looking for a quick reference on Purebasic or somebody wishing to learn how to program computers from scratch, this book is for you. Purebasic makes a great first language for anyone wishing to learn to program computers and this book is designed to guide them through their first steps. Written in a no-nonsense style, this book aims to simplify complicated topics making sure that everything is explained fully in a straightforward and helpful way. 11 | 12 | ### Highlights 13 | 14 | * A history of the Purebasic programming language 15 | * A complete reference for all core language features 16 | * A primer on how to use the Purebasic helpfile, IDE and visual designer 17 | * Guidelines on writing good code 18 | * Tutorials on creating graphical user interfaces 19 | * Examples of 2D & 3D graphics 20 | * A whole section devoted to simplifing advanced topics 21 | * Extensive Appendices containing Internet Links and helpful charts 22 | * A full computer science glossary to educate new programmers 23 | 24 | ## License 25 | 26 | [![License](https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png)](http://creativecommons.org/licenses/by-nc-sa/3.0/) 27 | 28 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 29 | -------------------------------------------------------------------------------- /code/100/100a.pb: -------------------------------------------------------------------------------- 1 | String.s = "I like to go fishing and catch lots of fish" 2 | StringToFind.s = "fish" 3 | 4 | FirstOccurrence.l = FindString(String, StringToFind, 1) 5 | SecondOccurrence.l = FindString(String, StringToFind, FirstOccurrence + 1) 6 | Debug "Index of the first occurrence: " + Str(FirstOccurrence) 7 | Debug "Index of the second occurrence: " + Str(SecondOccurrence) 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/101/101a.pb: -------------------------------------------------------------------------------- 1 | Alphabet.s = "abcdefghijklmnopqrstuvwxyz" 2 | LengthOfString.l = Len(Alphabet) 3 | 4 | Debug LengthOfString 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/101/101b.pb: -------------------------------------------------------------------------------- 1 | Title.s = "Information" 2 | Message.s = "This is the default style message requester" 3 | MessageRequester(Title, Message, #PB_MessageRequester_Ok) 4 | 5 | Message.s = "In this style you can choose 'Yes' or 'No'." 6 | Result.l = MessageRequester(Title, Message, #PB_MessageRequester_YesNo) 7 | 8 | If Result = #PB_MessageRequester_Yes 9 | Debug "You pressed 'Yes'" 10 | Else 11 | Debug "You pressed 'No'" 12 | EndIf 13 | Message.s = "In this style you can choose 'Yes' or 'No' or 'Cancel'." 14 | Result.l = MessageRequester(Title, Message, #PB_MessageRequester_YesNoCancel) 15 | 16 | Select Result 17 | Case #PB_MessageRequester_Yes 18 | Debug "You pressed 'Yes'" 19 | Case #PB_MessageRequester_No 20 | Debug "You pressed 'No'" 21 | Case #PB_MessageRequester_Cancel 22 | Debug "You pressed 'Cancel'" 23 | EndSelect 24 | ; IDE Options = PureBasic v4.00 (Windows - x86) 25 | ; HideErrorLog -------------------------------------------------------------------------------- /code/102/102a.pb: -------------------------------------------------------------------------------- 1 | StartingString.s = "Hickory Dickory Dock" 2 | ExtractedString.s = Mid(StartingString, 17, 4) 3 | Debug ExtractedString 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/103/103a.pb: -------------------------------------------------------------------------------- 1 | Debug Random(100) 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/103/103b.pb: -------------------------------------------------------------------------------- 1 | Debug "Long converted to a String: " + Str(2147483647) 2 | Debug "Float converted to a String: " +StrF(12.05643564333454646, 7) 3 | Debug "Quad converted to a String: " +StrQ(9223372036854775807) 4 | Debug "Double converted to a String: " +StrD(12.05643564333454646, 14) 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/104/104a.pb: -------------------------------------------------------------------------------- 1 | LongTypeVar.l = Val("2147483647") 2 | FloatTypeVar.f = ValF("12.05643564333454646") 3 | QuadTypeVar.q = ValQ("9223372036854775807") 4 | DoubleTypeVar.d = ValD("12.05643564333454646") 5 | 6 | Debug LongTypeVar 7 | Debug FloatTypeVar 8 | Debug QuadTypeVar 9 | Debug DoubleTypeVar 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/104/104b.pb: -------------------------------------------------------------------------------- 1 | #FILE_RHYME = 1 2 | 3 | Dim Rhyme.s(3) 4 | 5 | Rhyme(0) = "Baa baa black sheep, have you any wool?" 6 | Rhyme(1) = "Yes sir, yes sir, three bags full!" 7 | Rhyme(2) = "One for the master, one for the dame," 8 | Rhyme(3) = "And one for the little boy who lives down the lane." 9 | 10 | If CreateFile(#FILE_RHYME, "Baa baa.txt") 11 | For x.l = 0 To 3 12 | WriteStringN(#FILE_RHYME, Rhyme(x)) 13 | Next x 14 | CloseFile(#FILE_RHYME) 15 | EndIf 16 | ; IDE Options = PureBasic v4.00 (Windows - x86) 17 | ; HideErrorLog -------------------------------------------------------------------------------- /code/107/107a.pb: -------------------------------------------------------------------------------- 1 | #FILE_REPORT = 1 2 | 3 | NewList FileContents.s() 4 | 5 | If ReadFile(#FILE_REPORT, "Report.txt") 6 | While Eof(#FILE_REPORT) = #False 7 | AddElement(FileContents()) 8 | FileContents() = ReadString(#FILE_REPORT) 9 | Wend 10 | CloseFile(#FILE_REPORT) 11 | EndIf 12 | 13 | ForEach FileContents() 14 | Debug FileContents() 15 | Next 16 | ; IDE Options = PureBasic v4.00 (Windows - x86) 17 | ; HideErrorLog -------------------------------------------------------------------------------- /code/109/109a.pb: -------------------------------------------------------------------------------- 1 | #FILE_MP3 = 1 2 | 3 | ; Change this to the location of a MP3 file of your own: 4 | MP3File.s = "Test.mp3" 5 | 6 | If ReadFile(#FILE_MP3, MP3File) 7 | FileSeek(#FILE_MP3, Lof(#FILE_MP3) - 128) 8 | For x.l = 1 To 3 9 | Text.s + Chr(ReadByte(#FILE_MP3)) 10 | Next x 11 | CloseFile(#FILE_MP3) 12 | If Text = "TAG" 13 | Debug "'" + MP3File + "' has an ID3v1 tag embedded within it." 14 | Else 15 | Debug "'" + MP3File + "' does not have an ID3v1 tag embedded within it." 16 | EndIf 17 | EndIf 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/112/112a.pb: -------------------------------------------------------------------------------- 1 | ;The procedure Pi() is called to return the value of Pi. 2 | ;This calculation is only accurate to six decimal places. 3 | 4 | Procedure.f Pi() 5 | ProcedureReturn 4 * (4 * ATan(1/5) - ATan(1/239)) 6 | EndProcedure 7 | 8 | CircleDiameter.l = 150 9 | 10 | Debug "A circle which has a diameter of " + Str(CircleDiameter) + "mm" 11 | Debug "has a circumference of " + StrF(CircleDiameter * Pi()) + "mm." 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/114/114a.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/114/114a.pb -------------------------------------------------------------------------------- /code/115/115a.pb: -------------------------------------------------------------------------------- 1 | For x = 0 To 2 2 | For y = 0 To 2 3 | z.l = 0 4 | While z =< 10 5 | Debug x * y + z 6 | z + 1 7 | Wend 8 | Next y 9 | Next x 10 | 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/115/115b.pb: -------------------------------------------------------------------------------- 1 | Dim Birds.s(3) 2 | Birds(0)="Sparrow" : Birds(1)="Wren" : Birds(2)="Cuckoo" : Birds(3)="Owl" 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/117/117a.pb: -------------------------------------------------------------------------------- 1 | #TEXTFILE = 1 2 | 3 | If ReadFile(#TEXTFILE, "TextFile.txt") 4 | Debug ReadString(#TEXTFILE) 5 | CloseFile(#TEXTFILE) 6 | Else 7 | MessageRequester("Error", "Could not open the file: 'TextFile.txt'.") 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/118/118a.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/118/118a.pb -------------------------------------------------------------------------------- /code/119/119a.pb: -------------------------------------------------------------------------------- 1 | WeeklyAmount.l = 1024 2 | 3 | Procedure CalculateYearlyAmount(Value.l) 4 | YearlyAmount.l = Value * 52 5 | ProcedureReturn YearlyAmount 6 | EndProcedure 7 | 8 | Debug CalculateYearlyAmount(WeaklyAmount) 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/120/120a.pb: -------------------------------------------------------------------------------- 1 | EnableExplicit 2 | 3 | Define WeeklyAmount.l = 1024 4 | 5 | Procedure CalculateYearlyAmount(Value.l) 6 | Protected YearlyAmount.l = Value * 52 7 | ProcedureReturn YearlyAmount 8 | EndProcedure 9 | 10 | Debug CalculateYearlyAmount(WeeklyAmount) 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/123/123a.pb: -------------------------------------------------------------------------------- 1 | CallDebugger 2 | For x.l = 1 To 10 3 | Debug x 4 | Next x 5 | End 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/123/123b.pb: -------------------------------------------------------------------------------- 1 | ;Run this program with the Debugger off! 2 | 3 | ;Set the error handler 4 | OnErrorGoto(?ErrorHandler) 5 | 6 | ;Trigger a classic 'divide by zero' error. 7 | Null.l = 0 8 | TestVariable.l = 100 / Null 9 | 10 | ;Handle any system error that occurs 11 | ErrorHandler: 12 | Text.s = "Error count:" + #TAB$ + #TAB$ + Str(GetErrorCounter()) + #CRLF$ 13 | Text.s + "Error ID number:" + #TAB$ + #TAB$ + Str(GetErrorNumber()) + #CRLF$ 14 | Text.s + "Error description:" + #TAB$ + #TAB$ + GetErrorDescription() + #CRLF$ 15 | Text.s + "Error occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$ 16 | Text.s + "Error occurred in module:" + #TAB$ + GetErrorModuleName() + #CRLF$ 17 | MessageRequester("ERROR", Text) 18 | End 19 | ; IDE Options = PureBasic v4.00 (Windows - x86) 20 | ; DisableDebugger 21 | ; HideErrorLog -------------------------------------------------------------------------------- /code/125/125a.pb: -------------------------------------------------------------------------------- 1 | ;Run this program with the Debugger off! 2 | 3 | ;Handle any system error that occurs 4 | Procedure ErrorHandler() 5 | Text.s = "Error count:" + #TAB$ + Str(GetErrorCounter()) + #CRLF$ 6 | Text.s + "Error ID number:" + #TAB$ + Str(GetErrorNumber()) + #CRLF$ 7 | Text.s + "Error description:" + #TAB$ + GetErrorDescription() + #CRLF$ 8 | Text.s + "Occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$ 9 | Text.s + "Occurred in module:" + #TAB$ + GetErrorModuleName() + #CRLF$+#CRLF$ 10 | Text.s + "Would you like to continue execution of the program?" 11 | ReturnValue.l = MessageRequester("ERROR", Text, #PB_MessageRequester_YesNo) 12 | If ReturnValue = #PB_MessageRequester_No 13 | End 14 | EndIf 15 | EndProcedure 16 | 17 | ;Set the error handler 18 | OnErrorGosub(@ErrorHandler()) 19 | 20 | ;Trigger a classic 'divide by zero' error. 21 | Null.l = 0 22 | TestVariable.l = 100 / Null 23 | 24 | ;If the program reaches here then the program was resumed 25 | MessageRequester("STATUS", "The program was allowed to continue running.") 26 | End 27 | ; IDE Options = PureBasic v4.00 (Windows - x86) 28 | ; DisableDebugger 29 | ; HideErrorLog -------------------------------------------------------------------------------- /code/127/127a.pb: -------------------------------------------------------------------------------- 1 | ;Run this program with the Debugger off! 2 | 3 | #ERROR_READFILE = 1 4 | #ERROR_WRITEFILE = 2 5 | #FILE_TEXT = 1 6 | 7 | ;Set the error handler 8 | OnErrorGoto(?ErrorHandler) 9 | 10 | If ReadFile(#FILE_TEXT, "Report.txt") = #False 11 | ;If the file read fails then fire an error 12 | SetErrorNumber(#ERROR_READFILE) 13 | EndIf 14 | End 15 | 16 | ;Handle any custom error that occurs 17 | ErrorHandler: 18 | Text.s = "Error count:" + #TAB$ + #TAB$ + Str(GetErrorCounter()) + #CRLF$ 19 | Text.s + "Error ID number:" + #TAB$ + #TAB$ + Str(GetErrorNumber()) + #CRLF$ 20 | Select GetErrorNumber() 21 | Case #ERROR_READFILE 22 | Description.s = "The file could not be read." 23 | Case #ERROR_WRITEFILE 24 | Description.s = "The file could not be written." 25 | EndSelect 26 | Text.s + "Error description:" + #TAB$ + #TAB$ + Description + #CRLF$ 27 | Text.s + "Error occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$ 28 | Text.s + "Error occurred in module:" + #TAB$ + GetErrorModuleName() + #CRLF$ 29 | MessageRequester("ERROR", Text) 30 | End 31 | ; IDE Options = PureBasic v4.00 (Windows - x86) 32 | ; DisableDebugger 33 | ; HideErrorLog -------------------------------------------------------------------------------- /code/131/131a.pb: -------------------------------------------------------------------------------- 1 | If OpenConsole() 2 | Print("This is a test console program, press return to exit...") 3 | Input() 4 | CloseConsole() 5 | EndIf 6 | End 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/132/132a.pb: -------------------------------------------------------------------------------- 1 | If OpenConsole() 2 | 3 | EnableGraphicalConsole(#True) 4 | 5 | Repeat 6 | 7 | ConsoleColor(10, 0) 8 | PrintN("TIMES TABLES GENERATOR") 9 | PrintN("") 10 | ConsoleColor(7, 0) 11 | PrintN("Please enter a number, then press Return...") 12 | PrintN("") 13 | 14 | Number.q = ValQ(Input()) 15 | If Number = 0 16 | ClearConsole() 17 | Continue 18 | Else 19 | Break 20 | EndIf 21 | 22 | ForEver 23 | PrintN("") 24 | 25 | For x.l = 1 To 10 26 | PrintN(Str(x) + " x " + StrQ(Number) + " = " + StrQ(x * Number)) 27 | Next x 28 | PrintN("") 29 | 30 | Print("Press Return to exit...") 31 | Input() 32 | CloseConsole() 33 | EndIf 34 | End 35 | ; IDE Options = PureBasic v4.00 (Windows - x86) 36 | ; HideErrorLog -------------------------------------------------------------------------------- /code/134/134a.pb: -------------------------------------------------------------------------------- 1 | Procedure DisplayTitle() 2 | ConsoleColor(10, 0) 3 | PrintN("KEY CODE FINDER") 4 | PrintN("") 5 | ConsoleColor(7, 0) 6 | EndProcedure 7 | 8 | Procedure DisplayEscapeText() 9 | PrintN("") 10 | ConsoleColor(8, 0) 11 | PrintN("Press another key or press Escape to exit") 12 | ConsoleColor(7, 0) 13 | EndProcedure 14 | 15 | If OpenConsole() 16 | 17 | EnableGraphicalConsole(#True) 18 | DisplayTitle() 19 | PrintN("Press a key...") 20 | Repeat 21 | KeyPressed.s = Inkey() 22 | RawKeyCode.l = RawKey() 23 | 24 | If KeyPressed <> "" 25 | 26 | ClearConsole() 27 | DisplayTitle() 28 | PrintN("Key Pressed: " + KeyPressed) 29 | PrintN("Key Code: " + Str(RawKeyCode)) 30 | DisplayEscapeText() 31 | 32 | ElseIf RawKeyCode 33 | 34 | 35 | ClearConsole() 36 | DisplayTitle() 37 | PrintN("Key Pressed: " + "Non-ASCII") 38 | PrintN("Key Code: " + Str(RawKeyCode)) 39 | DisplayEscapeText() 40 | 41 | Else 42 | 43 | Delay(1) 44 | 45 | EndIf 46 | 47 | Until KeyPressed = #ESC$ 48 | CloseConsole() 49 | EndIf 50 | End 51 | ; IDE Options = PureBasic v4.00 (Windows - x86) 52 | ; HideErrorLog -------------------------------------------------------------------------------- /code/137/137a.pb: -------------------------------------------------------------------------------- 1 | #WINDOW_MAIN = 1 2 | 3 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 4 | If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 200, "Hello World", #FLAGS) 5 | Repeat 6 | Event.l = WaitWindowEvent() 7 | Until Event = #PB_Event_CloseWindow 8 | EndIf 9 | End 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/14/14a.pb: -------------------------------------------------------------------------------- 1 | ByteVariable.b = 123 2 | CharVariable.c = 222 3 | WordVariable.w = 4567 4 | LongVariable.l = 891011 5 | QuadVariable.q = 9223372036854775807 6 | FloatVariable.f = 3.1415927 7 | DoubleVariable.d = 12.53456776674545 8 | StringVariableOne.s = "Test String One" 9 | StringVariableTwo$ = "Test String Two" 10 | StringVariableThree.s{6} = "abcdef" 11 | StringVariableFour${3} = "abc" 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/14/14b.pb: -------------------------------------------------------------------------------- 1 | StringVariable.s = "Test String One" 2 | StringVariable$ = "Test String Two" 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/14/14c.pb: -------------------------------------------------------------------------------- 1 | StringVariable.s = "Test String One" 2 | StringVariable$ = "Test String Two" 3 | Debug StringVariable.s 4 | Debug StringVariable$ 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/140/140a.pb: -------------------------------------------------------------------------------- 1 | #WINDOW_MAIN = 1 2 | 3 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 4 | If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 200, "Hello World", #FLAGS) 5 | Repeat 6 | Event.l = WaitWindowEvent() 7 | Debug Event 8 | Until Event = #PB_Event_CloseWindow 9 | EndIf 10 | End 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/140/140b.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #BUTTON_INTERACT 4 | #BUTTON_CLOSE 5 | EndEnumeration 6 | 7 | Global Quit.b = #False 8 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 9 | 10 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Interaction", #FLAGS) 11 | If CreateGadgetList(WindowID(#WIN_MAIN)) 12 | 13 | ButtonGadget(#BUTTON_INTERACT, 10, 170, 100, 20, "Click me") 14 | ButtonGadget(#BUTTON_CLOSE, 190, 170, 100, 20, "Close window") 15 | Repeat 16 | 17 | Event.l = WaitWindowEvent() 18 | Select Event 19 | Case #PB_Event_Gadget 20 | Select EventGadget() 21 | 22 | Case #BUTTON_INTERACT 23 | Debug "The button was pressed." 24 | Case #BUTTON_CLOSE 25 | Quit = #True 26 | EndSelect 27 | EndSelect 28 | 29 | Until Event = #PB_Event_CloseWindow Or Quit = #True 30 | 31 | EndIf 32 | EndIf 33 | End 34 | ; IDE Options = PureBasic v4.00 (Windows - x86) 35 | ; HideErrorLog -------------------------------------------------------------------------------- /code/143/143a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #TEXT_INPUT 4 | #STRING_INPUT 5 | #BUTTON_INTERACT 6 | #BUTTON_CLOSE 7 | EndEnumeration 8 | 9 | Global Quit.b = #False 10 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 11 | 12 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Interaction", #FLAGS) 13 | If CreateGadgetList(WindowID(#WIN_MAIN)) 14 | 15 | TextGadget(#TEXT_INPUT, 10, 10, 280, 20, "Enter text here:") 16 | StringGadget(#STRING_INPUT, 10, 30, 280, 20, "") 17 | ButtonGadget(#BUTTON_INTERACT, 10, 170, 120, 20, "Echo text") 18 | ButtonGadget(#BUTTON_CLOSE, 190, 170, 100, 20, "Close window") 19 | SetActiveGadget(#STRING_INPUT) 20 | Repeat 21 | 22 | Event.l = WaitWindowEvent() 23 | Select Event 24 | Case #PB_Event_Gadget 25 | Select EventGadget() 26 | Case #BUTTON_INTERACT 27 | Debug GetGadgetText(#STRING_INPUT) 28 | Case #BUTTON_CLOSE 29 | Quit = #True 30 | EndSelect 31 | EndSelect 32 | 33 | Until Event = #PB_Event_CloseWindow Or Quit = #True 34 | 35 | EndIf 36 | EndIf 37 | End 38 | ; IDE Options = PureBasic v4.00 (Windows - x86) 39 | ; HideErrorLog -------------------------------------------------------------------------------- /code/145/145a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #TEXT_INPUT 4 | #STRING_INPUT 5 | #LIST_INPUT 6 | #BUTTON_INTERACT 7 | #BUTTON_CLOSE 8 | EndEnumeration 9 | 10 | Global Quit.b = #False 11 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 12 | 13 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Interaction", #FLAGS) 14 | If CreateGadgetList(WindowID(#WIN_MAIN)) 15 | 16 | TextGadget(#TEXT_INPUT, 10, 10, 280, 20, "Enter text here:") 17 | StringGadget(#STRING_INPUT, 10, 30, 280, 20, "") 18 | ListViewGadget(#LIST_INPUT, 10, 60, 280, 100) 19 | ButtonGadget(#BUTTON_INTERACT, 10, 170, 120, 20, "Enter text") 20 | ButtonGadget(#BUTTON_CLOSE, 190, 170, 100, 20, "Close window") 21 | SetActiveGadget(#STRING_INPUT) 22 | Repeat 23 | 24 | Event.l = WaitWindowEvent() 25 | Select Event 26 | Case #PB_Event_Gadget 27 | Select EventGadget() 28 | Case #BUTTON_INTERACT 29 | AddGadgetItem(#LIST_INPUT, -1, GetGadgetText(#STRING_INPUT)) 30 | SetGadgetText(#STRING_INPUT, "") 31 | SetActiveGadget(#STRING_INPUT) 32 | Case #BUTTON_CLOSE 33 | Quit = #True 34 | EndSelect 35 | EndSelect 36 | 37 | Until Event = #PB_Event_CloseWindow Or Quit = #True 38 | 39 | EndIf 40 | EndIf 41 | End 42 | ; IDE Options = PureBasic v4.00 (Windows - x86) 43 | ; HideErrorLog -------------------------------------------------------------------------------- /code/148/148a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #MENU_MAIN 4 | #MENU_QUIT 5 | #MENU_ABOUT 6 | EndEnumeration 7 | 8 | Global Quit.b = #False 9 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 10 | 11 | If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 200, "Menu Example", #FLAGS) 12 | If CreateMenu(#MENU_MAIN, WindowID(#WINDOW_MAIN)) 13 | 14 | MenuTitle("File") 15 | MenuItem(#MENU_QUIT, "Quit") 16 | MenuTitle("Help") 17 | MenuItem(#MENU_ABOUT, "About...") 18 | Repeat 19 | 20 | Event.l = WaitWindowEvent() 21 | Select Event 22 | Case #PB_Event_Menu 23 | Select EventMenu() 24 | Case #MENU_QUIT 25 | Quit = #True 26 | Case #MENU_ABOUT 27 | MessageRequester("About", "This is where you describe your program.") 28 | EndSelect 29 | EndSelect 30 | 31 | Until Event = #PB_Event_CloseWindow Or Quit = #True 32 | 33 | EndIf 34 | EndIf 35 | End 36 | ; IDE Options = PureBasic v4.00 (Windows - x86) 37 | ; HideErrorLog -------------------------------------------------------------------------------- /code/15/15a.pb: -------------------------------------------------------------------------------- 1 | TestVariable.s = "Test String One" 2 | testvariable = "Test String Two" 3 | TeStVaRiAbLe = "Test String Three" 4 | Debug tEsTvArIaBlE 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/15/15b.pb: -------------------------------------------------------------------------------- 1 | StringVariable.s = "Test String One" 2 | StringVariable = 100 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/15/15c.pb: -------------------------------------------------------------------------------- 1 | StringVariable.s = "Test String One" 2 | StringVariable = "One Hundred" 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/150/150a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #MENU_MAIN 4 | #MENU_CHILD 5 | #MENU_QUIT 6 | #MENU_ABOUT 7 | EndEnumeration 8 | 9 | Global Quit.b = #False 10 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 11 | 12 | If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 200, "Menu Example", #FLAGS) 13 | If CreateMenu(#MENU_MAIN, WindowID(#WINDOW_MAIN)) 14 | MenuTitle("File") 15 | OpenSubMenu("Parent Menu Item") 16 | MenuItem(#MENU_CHILD, "Sub Menu Item") 17 | CloseSubMenu() 18 | MenuBar() 19 | MenuItem(#MENU_QUIT, "Quit") 20 | MenuTitle("Help") 21 | MenuItem(#MENU_ABOUT, "About...") 22 | Repeat 23 | Event.l = WaitWindowEvent() 24 | Select Event 25 | Case #PB_Event_Menu 26 | Select EventMenu() 27 | Case #MENU_CHILD 28 | Debug "Sub menu item selected." 29 | Case #MENU_QUIT 30 | Quit = #True 31 | Case #MENU_ABOUT 32 | MessageRequester("About", "This is where you describe your program.") 33 | EndSelect 34 | EndSelect 35 | Until Event = #PB_Event_CloseWindow Or Quit = #True 36 | EndIf 37 | EndIf 38 | End 39 | ; IDE Options = PureBasic v4.00 (Windows - x86) 40 | ; HideErrorLog -------------------------------------------------------------------------------- /code/151/151a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #MENU_MAIN 4 | #MENU_QUIT 5 | #MENU_ABOUT 6 | #TEXT_INPUT 7 | #STRING_INPUT 8 | #LIST_INPUT 9 | #BUTTON_INTERACT 10 | #BUTTON_CLOSE 11 | EndEnumeration 12 | 13 | Global Quit.b = #False 14 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 15 | 16 | If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 222, "Interaction", #FLAGS) 17 | If CreateMenu(#MENU_MAIN, WindowID(#WINDOW_MAIN)) 18 | MenuTitle("File") 19 | MenuItem(#MENU_QUIT, "Quit") 20 | MenuTitle("Help") 21 | MenuItem(#MENU_ABOUT, "About...") 22 | If CreateGadgetList(WindowID(#WINDOW_MAIN)) 23 | TextGadget(#TEXT_INPUT, 10, 10, 280, 20, "Enter text here:") 24 | StringGadget(#STRING_INPUT, 10, 30, 280, 20, "") 25 | ListViewGadget(#LIST_INPUT, 10, 60, 280, 100) 26 | ButtonGadget(#BUTTON_INTERACT, 10, 170, 120, 20, "Enter text") 27 | ButtonGadget(#BUTTON_CLOSE, 190, 170, 100, 20, "Close window") 28 | SetActiveGadget(#STRING_INPUT) 29 | Repeat 30 | Event.l = WaitWindowEvent() 31 | Select Event 32 | Case #PB_Event_Menu 33 | Select EventMenu() 34 | Case #MENU_QUIT 35 | Quit = #True 36 | Case #MENU_ABOUT 37 | MessageRequester("About", "This is your program description.") 38 | EndSelect 39 | Case #PB_Event_Gadget 40 | Select EventGadget() 41 | Case #BUTTON_INTERACT 42 | AddGadgetItem(#LIST_INPUT, -1, GetGadgetText(#STRING_INPUT)) 43 | SetGadgetText(#STRING_INPUT, "") 44 | SetActiveGadget(#STRING_INPUT) 45 | Case #BUTTON_CLOSE 46 | Quit = #True 47 | EndSelect 48 | EndSelect 49 | Until Event = #PB_Event_CloseWindow Or Quit = #True 50 | EndIf 51 | EndIf 52 | EndIf 53 | End 54 | ; IDE Options = PureBasic v4.00 (Windows - x86) 55 | ; HideErrorLog -------------------------------------------------------------------------------- /code/154/154a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #MENU_MAIN 4 | #M_QUIT 5 | #M_ABOUT 6 | EndEnumeration 7 | 8 | Global Quit.b = #False 9 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 10 | 11 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Menu Example", #FLAGS) 12 | If CreateMenu(#MENU_MAIN, WindowID(#WIN_MAIN)) 13 | 14 | MenuTitle("File") 15 | MenuItem(#M_QUIT, "Quit" + #TAB$ + "Ctrl+Q") 16 | MenuTitle("Help") 17 | MenuItem(#M_ABOUT, "About..." + #TAB$ + "Ctrl+A") 18 | 19 | AddKeyboardShortcut(#WIN_MAIN,#PB_Shortcut_Control|#PB_Shortcut_Q,#M_QUIT) 20 | AddKeyboardShortcut(#WIN_MAIN,#PB_Shortcut_Control|#PB_Shortcut_A,#M_ABOUT) 21 | 22 | Repeat 23 | 24 | Event.l = WaitWindowEvent() 25 | Select Event 26 | Case #PB_Event_Menu 27 | Select EventMenu() 28 | Case #M_QUIT 29 | Quit = #True 30 | Case #M_ABOUT 31 | MessageRequester("About", "This is where you describe your program.") 32 | EndSelect 33 | EndSelect 34 | 35 | Until Event = #PB_Event_CloseWindow Or Quit = #True 36 | 37 | EndIf 38 | EndIf 39 | End 40 | ; IDE Options = PureBasic v4.00 (Windows - x86) 41 | ; HideErrorLog -------------------------------------------------------------------------------- /code/156/156a.pb: -------------------------------------------------------------------------------- 1 | #WIN_MAIN = 1 2 | #SC_EVENT = 2 3 | 4 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 5 | 6 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Hello World", #FLAGS) 7 | AddKeyboardShortcut(#WIN_MAIN,#PB_Shortcut_Control|#PB_Shortcut_Z, #SC_EVENT) 8 | Repeat 9 | Event.l = WaitWindowEvent() 10 | Select Event 11 | Case #PB_Event_Menu 12 | Select EventMenu() 13 | Case #SC_EVENT 14 | Debug "The shortcut was pressed" 15 | EndSelect 16 | EndSelect 17 | Until Event = #PB_Event_CloseWindow 18 | EndIf 19 | End 20 | ; IDE Options = PureBasic v4.00 (Windows - x86) 21 | ; HideErrorLog -------------------------------------------------------------------------------- /code/157/157a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #IMAGE_FILE 4 | #IMAGE_DISPLAY 5 | #BUTTON_CLOSE 6 | EndEnumeration 7 | 8 | Global Quit.b = #False 9 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 10 | 11 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Image Example", #FLAGS) 12 | If CreateGadgetList(WindowID(#WIN_MAIN)) 13 | If LoadImage(#IMAGE_FILE, "image.bmp") 14 | 15 | ImageGadget(#IMAGE_DISPLAY, 10, 10, 280, 150, ImageID(#IMAGE_FILE)) 16 | ButtonGadget(#BUTTON_CLOSE, 100, 170, 100, 20, "Close window") 17 | Repeat 18 | 19 | Event.l = WaitWindowEvent() 20 | Select Event 21 | Case #PB_Event_Gadget 22 | Select EventGadget() 23 | Case #BUTTON_CLOSE 24 | Quit = #True 25 | EndSelect 26 | EndSelect 27 | 28 | Until Event = #PB_Event_CloseWindow Or Quit = #True 29 | 30 | EndIf 31 | EndIf 32 | EndIf 33 | End 34 | ; IDE Options = PureBasic v4.00 (Windows - x86) 35 | ; HideErrorLog -------------------------------------------------------------------------------- /code/157/image.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/157/image.bmp -------------------------------------------------------------------------------- /code/159/159a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WIN_MAIN 3 | #IMAGE_MEMORY 4 | #IMAGE_DISPLAY 5 | #BUTTON_CLOSE 6 | EndEnumeration 7 | 8 | Global Quit.b = #False 9 | 10 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 11 | 12 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Image Example", #FLAGS) 13 | If CreateGadgetList(WindowID(#WIN_MAIN)) 14 | If CatchImage(#IMAGE_MEMORY, ?Image) 15 | ImageGadget(#IMAGE_DISPLAY, 10, 10, 280, 150, ImageID(#IMAGE_MEMORY)) 16 | ButtonGadget(#BUTTON_CLOSE, 100, 170, 100, 20, "Close window") 17 | Repeat 18 | Event.l = WaitWindowEvent() 19 | Select Event 20 | Case #PB_Event_Gadget 21 | Select EventGadget() 22 | Case #BUTTON_CLOSE 23 | Quit = #True 24 | EndSelect 25 | EndSelect 26 | Until Event = #PB_Event_CloseWindow Or Quit = #True 27 | EndIf 28 | EndIf 29 | EndIf 30 | End 31 | 32 | DataSection 33 | Image: 34 | IncludeBinary "image.bmp" 35 | EndDataSection 36 | ; IDE Options = PureBasic v4.00 (Windows - x86) 37 | ; HideErrorLog -------------------------------------------------------------------------------- /code/159/image.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/159/image.bmp -------------------------------------------------------------------------------- /code/16/16a.pb: -------------------------------------------------------------------------------- 1 | #DAYS_IN_THE_YEAR = "365" 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/16/16b.pb: -------------------------------------------------------------------------------- 1 | #DAYS_IN_THE_YEAR = "365" 2 | Debug "There are " + #DAYS_IN_THE_YEAR + " days in the year." 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/16/16c.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #ZERO 3 | #ONE 4 | #TWO 5 | #THREE 6 | EndEnumeration 7 | 8 | Debug #ZERO 9 | Debug #ONE 10 | Debug #TWO 11 | Debug #THREE 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/161/161a.pb: -------------------------------------------------------------------------------- 1 | UseJPEGImageDecoder() 2 | 3 | Enumeration 4 | #WIN_MAIN 5 | #IMAGE_MEMORY 6 | #IMAGE_DISPLAY 7 | #BUTTON_CLOSE 8 | EndEnumeration 9 | 10 | Global Quit.b = #False 11 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 12 | 13 | If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Image Example", #FLAGS) 14 | If CreateGadgetList(WindowID(#WIN_MAIN)) 15 | If CatchImage(#IMAGE_MEMORY, ?Image) 16 | 17 | ImageGadget(#IMAGE_DISPLAY, 10, 10, 280, 150, ImageID(#IMAGE_MEMORY)) 18 | ButtonGadget(#BUTTON_CLOSE, 100, 170, 100, 20, "Close window") 19 | Repeat 20 | 21 | Event.l = WaitWindowEvent() 22 | Select Event 23 | Case #PB_Event_Gadget 24 | Select EventGadget() 25 | Case #BUTTON_CLOSE 26 | Quit = #True 27 | EndSelect 28 | EndSelect 29 | 30 | Until Event = #PB_Event_CloseWindow Or Quit = #True 31 | 32 | 33 | EndIf 34 | EndIf 35 | EndIf 36 | End 37 | 38 | DataSection 39 | Image: 40 | IncludeBinary "image.jpg" 41 | EndDataSection 42 | ; IDE Options = PureBasic v4.00 (Windows - x86) 43 | ; HideErrorLog -------------------------------------------------------------------------------- /code/161/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/161/image.jpg -------------------------------------------------------------------------------- /code/168/168a.pb: -------------------------------------------------------------------------------- 1 | #WINDOW_MAIN = 1 2 | 3 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 4 | If OpenWindow(#WINDOW_MAIN, 0, 0, 200, 240, "Window Drawing", #FLAGS) 5 | 6 | If StartDrawing(WindowOutput(#WINDOW_MAIN)) 7 | Box(15, 15, 75, 75, RGB(255, 0, 0)) 8 | Circle(140, 125, 45, RGB(35, 158, 70)) 9 | ;The next 2D drawing commands draw a triangle 10 | LineXY(62, 140, 112, 220, RGB(0, 0, 255)) 11 | LineXY(112, 220, 12, 220, RGB(0, 0, 255)) 12 | LineXY(12, 220, 62, 140, RGB(0, 0, 255)) 13 | FillArea(62, 180, RGB(0, 0, 255), RGB(0, 0, 255)) 14 | StopDrawing() 15 | EndIf 16 | 17 | Repeat 18 | Event.l = WaitWindowEvent() 19 | Until Event = #PB_Event_CloseWindow 20 | EndIf 21 | End 22 | ; IDE Options = PureBasic v4.00 (Windows - x86) 23 | ; HideErrorLog -------------------------------------------------------------------------------- /code/17/17a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 10 2 | #TEN 3 | #ELEVEN 4 | #TWELVE 5 | EndEnumeration 6 | 7 | Debug #TEN 8 | Debug #ELEVEN 9 | Debug #TWELVE 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/17/17b.pb: -------------------------------------------------------------------------------- 1 | Enumeration 10 Step 5 2 | #TEN 3 | #FIFTEEN 4 | #TWENTY 5 | EndEnumeration 6 | 7 | Debug #TEN 8 | Debug #FIFTEEN 9 | Debug #TWENTY 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/17/17c.pb: -------------------------------------------------------------------------------- 1 | Enumeration 5 2 | #FIVE 3 | #ONE_HUNDRED = 100 4 | #ONE_HUNDRED_AND_ONE 5 | #ONE_HUNDRED_AND_TWO 6 | EndEnumeration 7 | 8 | Debug #FIVE 9 | Debug #ONE_HUNDRED 10 | Debug #ONE_HUNDRED_AND_ONE 11 | Debug #ONE_HUNDRED_AND_TWO 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/171/171a.pb: -------------------------------------------------------------------------------- 1 | ColorValue.l = RGB(35, 158, 70) 2 | 3 | Debug "The 24 bit color value is made up of: " 4 | Debug "Red: " + Str(Red(ColorValue)) 5 | Debug "Green: " + Str(Green(ColorValue)) 6 | Debug "Blue: " + Str(Blue(ColorValue)) 7 | 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/171/171b.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #IMAGE_GADGET 4 | #IMAGE_MAIN 5 | EndEnumeration 6 | 7 | If CreateImage(#IMAGE_MAIN, 180, 220) 8 | If StartDrawing(ImageOutput(#IMAGE_MAIN)) 9 | ;Because a new image has a Black background, draw a white one instead: 10 | Box(0, 0, 180, 220, RGB(255, 255, 255)) 11 | ;Now, continue drawing the shapes: 12 | Box(5, 5, 75, 75, RGB(255, 0, 0)) 13 | Circle(130, 115, 45, RGB(35, 158, 70)) 14 | LineXY(52, 130, 102, 210, RGB(0, 0, 255)) 15 | LineXY(102, 210, 2, 210, RGB(0, 0, 255)) 16 | LineXY(2, 210, 52, 130, RGB(0, 0, 255)) 17 | FillArea(52, 170, RGB(0, 0, 255), RGB(0, 0, 255)) 18 | StopDrawing() 19 | EndIf 20 | EndIf 21 | 22 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 23 | 24 | If OpenWindow(#WINDOW_MAIN, 0, 0, 200, 240, "Drawing On A New Image", #FLAGS) 25 | If CreateGadgetList(WindowID(#WINDOW_MAIN)) 26 | ImageGadget(#IMAGE_GADGET, 10, 10, 180, 220, ImageID(#IMAGE_MAIN)) 27 | Repeat 28 | Event.l = WaitWindowEvent() 29 | Until Event = #PB_Event_CloseWindow 30 | EndIf 31 | EndIf 32 | End 33 | ; IDE Options = PureBasic v4.00 (Windows - x86) 34 | ; HideErrorLog -------------------------------------------------------------------------------- /code/173/173a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #IMAGE_GADGET 4 | #IMAGE_MAIN 5 | #FONT_MAIN 6 | EndEnumeration 7 | 8 | Global ImageWidth = 401 9 | Global ImageHeight = 201 10 | Global XPos.l, YPos.l, Width.l, Height.l, Red.l, Green.l, Blue.l 11 | Global Text.s = "Purebasic - 2D Drawing Example" 12 | 13 | 14 | 15 | Procedure.l MyRandom(Maximum.l) 16 | Repeat 17 | Number.l = Random(Maximum) 18 | Until (Number % 10) = 0 19 | ProcedureReturn Number 20 | EndProcedure 21 | 22 | If CreateImage(#IMAGE_MAIN, ImageWidth, ImageHeight) 23 | If StartDrawing(ImageOutput(#IMAGE_MAIN)) 24 | For x.l = 0 To 1500 25 | XPos.l = MyRandom(ImageWidth) + 1 26 | YPos.l = MyRandom(ImageHeight) + 1 27 | Width.l = (MyRandom(100) - 1) + 10 28 | Height.l = (MyRandom(100) - 1) + 10 29 | Red.l = Random(255) 30 | Green.l = Random(255) 31 | Blue.l = Random(255) 32 | Box(XPos, YPos, Width, Height, RGB(Red, Green, Blue)) 33 | DrawingMode(#PB_2DDrawing_Outlined) 34 | Box(XPos - 1, YPos - 1, Width + 2, Height + 2, RGB(0, 0, 0)) 35 | DrawingMode(#PB_2DDrawing_Default) 36 | Next x 37 | LineXY(ImageWidth - 1, 0, ImageWidth - 1, ImageHeight, RGB(0, 0, 0)) 38 | LineXY(0, ImageHeight - 1, ImageWidth, ImageHeight - 1, RGB(0, 0, 0)) 39 | Box(10, 10, 230, 30, RGB(90, 105, 134)) 40 | DrawingMode(#PB_2DDrawing_Outlined) 41 | Box(10, 10, 231, 31, RGB(0, 0, 0)) 42 | DrawingMode(#PB_2DDrawing_Transparent) 43 | DrawText(21, 18, Text, RGB(0, 0, 0)) 44 | DrawText(19, 18, Text, RGB(0, 0, 0)) 45 | DrawText(21, 16, Text, RGB(0, 0, 0)) 46 | DrawText(19, 16, Text, RGB(0, 0, 0)) 47 | DrawText(20, 17, Text, RGB(255, 255, 255)) 48 | StopDrawing() 49 | EndIf 50 | EndIf 51 | 52 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 53 | If OpenWindow(#WINDOW_MAIN,0,0,ImageWidth+20,ImageHeight+20,"Abstract",#FLAGS) 54 | If CreateGadgetList(WindowID(#WINDOW_MAIN)) 55 | ImageGadget(#IMAGE_GADGET,10,10,ImageWidth,ImageHeight,ImageID(#IMAGE_MAIN)) 56 | EndIf 57 | Repeat 58 | Event.l = WaitWindowEvent() 59 | Until Event = #PB_Event_CloseWindow 60 | EndIf 61 | End 62 | ; IDE Options = PureBasic v4.00 (Windows - x86) 63 | ; HideErrorLog -------------------------------------------------------------------------------- /code/176/176a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_MAIN 3 | #IMAGE_GADGET 4 | #IMAGE_SMALL 5 | #IMAGE_MAIN 6 | #FONT_MAIN 7 | EndEnumeration 8 | 9 | Global ImageWidth = 400 10 | Global ImageHeight = 200 11 | Global XPos.l, YPos.l, LoadedImageWidth.l, LoadedImageHeight.l 12 | 13 | Global File.s 14 | Global RequesterText.s = "Choose an image" 15 | Global DefaultFile.s = "" 16 | Global Pattern.s = "Bitmap (*.bmp)|*.bmp|Icon (*.ico)|*.ico" 17 | File = OpenFileRequester(RequesterText, DefaultFile, Pattern, 0) 18 | 19 | If File 20 | LoadImage(#IMAGE_SMALL, File) 21 | LoadedImageWidth = ImageWidth(#IMAGE_SMALL) 22 | LoadedImageHeight = ImageHeight(#IMAGE_SMALL) 23 | If CreateImage(#IMAGE_MAIN, ImageWidth,ImageHeight) 24 | If StartDrawing(ImageOutput(#IMAGE_MAIN)) 25 | Box(0, 0,ImageWidth, ImageHeight, RGB(255, 255, 255)) 26 | For x.l = 1 To 1000 27 | XPos = Random(ImageWidth) - (ImageWidth(#IMAGE_SMALL) / 2) 28 | YPos = Random(ImageHeight) - (ImageHeight(#IMAGE_SMALL) / 2) 29 | DrawImage(ImageID(#IMAGE_SMALL), XPos, YPos) 30 | Next x 31 | DrawingMode(#PB_2DDrawing_Outlined) 32 | Box(0, 0, ImageWidth, ImageHeight, RGB(0, 0, 0)) 33 | StopDrawing() 34 | EndIf 35 | EndIf 36 | #TEXT = "Drawing Using Images" 37 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 38 | If OpenWindow(#WINDOW_MAIN,0,0,ImageWidth+20,ImageHeight+20,#TEXT,#FLAGS) 39 | If CreateGadgetList(WindowID(#WINDOW_MAIN)) 40 | ImageGadget(#IMAGE_GADGET,10,10,ImageWidth,ImageHeight,ImageID(#IMAGE_MAIN)) 41 | EndIf 42 | Repeat 43 | Event.l = WaitWindowEvent() 44 | Until Event = #PB_Event_CloseWindow 45 | EndIf 46 | End 47 | EndIf 48 | ; IDE Options = PureBasic v4.00 (Windows - x86) 49 | ; HideErrorLog -------------------------------------------------------------------------------- /code/176/Ball.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/176/Ball.ico -------------------------------------------------------------------------------- /code/176/Gears.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/176/Gears.bmp -------------------------------------------------------------------------------- /code/178/178a.pb: -------------------------------------------------------------------------------- 1 | Global File.s 2 | Global RequesterText.s = "Choose an image" 3 | Global DefaultFile.s = "" 4 | Global Pattern.s = "Bitmap (*.bmp)|*.bmp|Icon (*.ico)|*.ico" 5 | File = OpenFileRequester(RequesterText, DefaultFile, Pattern, 0) 6 | Debug File 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/178/Ball.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/178/Ball.ico -------------------------------------------------------------------------------- /code/178/Gears.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/178/Gears.bmp -------------------------------------------------------------------------------- /code/18/18a.pb: -------------------------------------------------------------------------------- 1 | LongVariable.l = 1 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/18/18b.pb: -------------------------------------------------------------------------------- 1 | LongVariable.l = 1 2 | If LongVariable = 1 3 | Debug "Yes, LongVariable does equal 1" 4 | EndIf 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/182/182a.pb: -------------------------------------------------------------------------------- 1 | Global Quit.b = #False 2 | 3 | ;Simple error checking procedure 4 | Procedure HandleError(Result.l, Text.s) 5 | If Result = 0 6 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 7 | End 8 | EndIf 9 | EndProcedure 10 | 11 | HandleError(InitSprite(), "InitSprite() command failed.") 12 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 13 | HandleError(OpenScreen(1024, 768, 32, "Fullscreen"), "Could not open screen.") 14 | 15 | Repeat 16 | ClearScreen(RGB(0, 0, 0)) 17 | 18 | ;Drawing operations go here 19 | 20 | FlipBuffers(2) 21 | ExamineKeyboard() 22 | If KeyboardReleased(#PB_Key_Escape) 23 | Quit = #True 24 | EndIf 25 | Until Quit = #True 26 | End 27 | 28 | ; IDE Options = PureBasic v4.00 (Windows - x86) 29 | ; HideErrorLog -------------------------------------------------------------------------------- /code/184/184a.pb: -------------------------------------------------------------------------------- 1 | InitSprite() 2 | If ExamineScreenModes() 3 | While NextScreenMode() 4 | Width.l = ScreenModeWidth() 5 | Height.l = ScreenModeHeight() 6 | BitDepth.l = ScreenModeDepth() 7 | Debug Str(Width)+" x "+Str(Height)+" x "+Str(BitDepth) 8 | Wend 9 | EndIf 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/186/186a.pb: -------------------------------------------------------------------------------- 1 | #IMAGE_MAIN = 1 2 | ;Set the width, height and bit depth of the screen 3 | ;Abbreviated variables are used here due to page width constraints :( 4 | Global ScrW.l = 1024 5 | Global ScrH.l = 768 6 | Global ScrD.l = 32 7 | Global Quit.b = #False 8 | XOrigin.f = (ScrW / 2) - 64 : YOrigin.f = (ScrH / 2) - 64 9 | 10 | ;Simple error checking procedure 11 | Procedure HandleError(Result.l, Text.s) 12 | If Result = 0 13 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 14 | End 15 | EndIf 16 | EndProcedure 17 | 18 | ;Initialize environment 19 | HandleError(InitSprite(), "InitSprite() command failed.") 20 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 21 | HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.") 22 | SetFrameRate(60) 23 | 24 | ;Create an image 25 | If CreateImage(#IMAGE_MAIN, 128, 128) 26 | If StartDrawing(ImageOutput(#IMAGE_MAIN)) 27 | For x.l = 255 To 0 Step -1 28 | Circle(64, 64, x / 4, RGB(0, 0, 255 - x)) 29 | Next x 30 | StopDrawing() 31 | EndIf 32 | EndIf 33 | 34 | ;Convert Degrees to Radians 35 | Procedure.f DegToRad(Angle.f) 36 | ProcedureReturn Angle.f * #PI / 180 37 | EndProcedure 38 | 39 | ;Main loop 40 | Repeat 41 | ClearScreen(RGB(0, 0, 0)) 42 | Angle.f + 2.0 43 | Radius.f = ((ScrH / 2) - 100) * Sin(DegToRad(Angle)) 44 | 45 | StartDrawing(ScreenOutput()) 46 | For x.l = 0 To 359 Step 45 47 | XPos.f = XOrigin + (Radius * Cos(DegToRad(Angle + x))) 48 | YPos.f = YOrigin + (Radius * Sin(DegToRad(Angle + x))) 49 | DrawImage(ImageID(#IMAGE_MAIN), XPos, YPos) 50 | Next x 51 | StopDrawing() 52 | 53 | FlipBuffers() 54 | ExamineKeyboard() 55 | If KeyboardReleased(#PB_Key_Escape) 56 | Quit = #True 57 | EndIf 58 | Until Quit = #True 59 | End 60 | ; IDE Options = PureBasic v4.00 (Windows - x86) 61 | ; HideErrorLog -------------------------------------------------------------------------------- /code/188/188a.pb: -------------------------------------------------------------------------------- 1 | #APP_NAME = "Stars v1.0" 2 | #NUMBER_OF_STARS = 10000 3 | ;Set the width, height and bit depth of the screen 4 | ;Abbreviated variables are used here due to page width constraints :( 5 | Global ScrW.l = 1024 6 | Global ScrH.l = 768 7 | Global ScrD.l = 32 8 | Global Quit.b = #False 9 | 10 | Structure STAR 11 | xPos.f 12 | yPos.f 13 | xStep.f 14 | Color.l 15 | EndStructure 16 | Global Dim Stars.STAR(#NUMBER_OF_STARS) 17 | 18 | ;Simple error checking procedure 19 | Procedure HandleError(Result.l, Text.s) 20 | If Result = 0 21 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 22 | End 23 | EndIf 24 | EndProcedure 25 | 26 | ;init stars 27 | Procedure InitializeStars() 28 | For x = 0 To #NUMBER_OF_STARS 29 | Stars(x)\xPos = Random(ScrW - 1) 30 | Stars(x)\yPos = Random(ScrH - 1) 31 | If x < #NUMBER_OF_STARS / 3 32 | Stars(x)\xStep = (Random(10) / 100) + 0.2 33 | Stars(x)\Color = RGB(40, 40, 40) 34 | ElseIf x >= #NUMBER_OF_STARS / 3 And x < (#NUMBER_OF_STARS / 3) * 2 35 | Stars(x)\xStep = (Random(10) / 100) + 0.6 36 | Stars(x)\Color = RGB(100, 100, 100) 37 | Else 38 | Stars(x)\xStep = (Random(10) / 100) + 1.2 39 | Stars(x)\Color = RGB(255, 255, 255) 40 | EndIf 41 | Next x 42 | EndProcedure 43 | 44 | ;move stars on the 'x' axis 45 | Procedure MoveStarsX() 46 | For x = 0 To #NUMBER_OF_STARS 47 | Stars(x)\xPos - Stars(x)\xStep 48 | If Stars(x)\xPos < 0 49 | Stars(x)\xPos = ScrW - 1 50 | Stars(x)\yPos = Random(ScrH - 1) 51 | EndIf 52 | Next x 53 | EndProcedure 54 | 55 | ;Initialize environment 56 | HandleError(InitSprite(), "InitSprite() command failed.") 57 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 58 | HandleError(OpenScreen(ScrW, ScrH, ScrD, #APP_NAME), "Could not open screen.") 59 | SetFrameRate(60) 60 | InitializeStars() 61 | 62 | Repeat 63 | ClearScreen(RGB(0, 0, 0)) 64 | StartDrawing(ScreenOutput()) 65 | For x = 0 To #NUMBER_OF_STARS 66 | Plot(Stars(x)\xPos, Stars(x)\yPos, Stars(x)\Color) 67 | Next x 68 | DrawingMode(#PB_2DDrawing_Transparent) 69 | DrawText(20, 20, #APP_NAME, #White) 70 | DrawText(20, 40, Str(#NUMBER_OF_STARS)+" Animated stars", #White) 71 | DrawText(20, 60, "Screen Resolution: "+Str(ScrW)+" x "+Str(ScrH), #White) 72 | DrawText(20, 80, "Screen Bit depth: "+Str(ScrD)+"bit", #White) 73 | StopDrawing() 74 | FlipBuffers() 75 | MoveStarsX() 76 | 77 | ExamineKeyboard() 78 | If KeyboardReleased(#PB_Key_Escape) 79 | Quit = 1 80 | EndIf 81 | 82 | Until Quit = 1 83 | End 84 | ; IDE Options = PureBasic v4.00 (Windows - x86) 85 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberTwo.l = 25 3 | NumberThree.l = NumberOne + NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 + 25 2 | Debug NumberOne 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberOne + 25 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19d.pb: -------------------------------------------------------------------------------- 1 | StringOne.s = "Mary had a" 2 | StringTwo.s = " little lamb" 3 | StringThree.s = StringOne + StringTwo 4 | Debug StringThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19e.pb: -------------------------------------------------------------------------------- 1 | StringOne.s = "Mary had a" + " little lamb" 2 | Debug StringOne 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/19/19f.pb: -------------------------------------------------------------------------------- 1 | StringOne.s = "Mary had a" 2 | StringOne + " little lamb" 3 | Debug StringOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/190/190a.pb: -------------------------------------------------------------------------------- 1 | #WINDOW_MAIN = 1 2 | #IMAGE_MAIN = 1 3 | 4 | ;Set the width, height and bit depth of the screen 5 | ;Abbreviated variables are used here due to page width constraints :( 6 | Global ScrW.l = 800 7 | Global ScrH.l = 600 8 | Global ScrD.l = 32 9 | Global Quit.b = #False 10 | Global XOrigin.f = (ScrW / 2) - 64 11 | Global YOrigin.f = (ScrH / 2) - 64 12 | 13 | ;Simple error checking procedure 14 | Procedure HandleError(Result.l, Text.s) 15 | If Result = 0 16 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 17 | End 18 | EndIf 19 | EndProcedure 20 | 21 | ;Convert Degrees to Radians 22 | Procedure.f DegToRad(Angle.f) 23 | ProcedureReturn Angle.f * #PI / 180 24 | EndProcedure 25 | 26 | ;Initialize environment 27 | HandleError(InitSprite(), "InitSprite() command failed.") 28 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 29 | 30 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 31 | If OpenWindow(#WINDOW_MAIN, 0, 0, ScrW, ScrH, "Windowed Screen", #FLAGS) 32 | If OpenWindowedScreen(WindowID(#WINDOW_MAIN), 0, 0, ScrW, ScrH, 0, 0, 0) 33 | SetFrameRate(60) 34 | 35 | ;Create an image 36 | If CreateImage(#IMAGE_MAIN, 128, 128) 37 | If StartDrawing(ImageOutput(#IMAGE_MAIN)) 38 | For x.l = 255 To 0 Step -1 39 | Circle(64, 64, x / 4, RGB(255 - x, 0, 0)) 40 | Next x 41 | StopDrawing() 42 | EndIf 43 | EndIf 44 | 45 | ;Main loop 46 | Repeat 47 | Event.l = WindowEvent() 48 | ClearScreen(RGB(0, 0, 0)) 49 | 50 | Angle.f + 2.0 51 | Radius.f = ((ScrH / 2) - 100) * Sin(DegToRad(Angle)) 52 | 53 | StartDrawing(ScreenOutput()) 54 | For x.l = 0 To 359 Step 45 55 | XPos.f = XOrigin + (Radius * Cos(DegToRad(Angle + x))) 56 | YPos.f = YOrigin + (Radius * Sin(DegToRad(Angle + x))) 57 | DrawImage(ImageID(#IMAGE_MAIN), XPos, YPos) 58 | Next x 59 | StopDrawing() 60 | 61 | FlipBuffers() 62 | ExamineKeyboard() 63 | If KeyboardReleased(#PB_Key_Escape) 64 | Quit = #True 65 | EndIf 66 | 67 | Until Event = #PB_Event_CloseWindow Or Quit = #True 68 | EndIf 69 | EndIf 70 | End 71 | ; IDE Options = PureBasic v4.00 (Windows - x86) 72 | ; HideErrorLog -------------------------------------------------------------------------------- /code/196/196a.pb: -------------------------------------------------------------------------------- 1 | #SPRITE_MAIN = 1 2 | #NUMBER_OF_BALLS = 500 3 | 4 | ;Set the width, height and bit depth of the screen 5 | ;Abbreviated variables are used here due to page width constraints :( 6 | Global ScrW.l = 1024 7 | Global ScrH.l = 768 8 | Global ScrD.l = 32 9 | Global Quit.b = #False 10 | 11 | Structure BALL 12 | x.f 13 | y.f 14 | XOrigin.l 15 | YOrigin.l 16 | Radius.l 17 | Angle.f 18 | Speed.f 19 | EndStructure 20 | Global Dim Balls.BALL(#NUMBER_OF_BALLS) 21 | 22 | ;Simple error checking procedure 23 | Procedure HandleError(Result.l, Text.s) 24 | If Result = 0 25 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 26 | End 27 | EndIf 28 | EndProcedure 29 | 30 | ;Convert Degrees to Radians 31 | Procedure.f DegToRad(Angle.f) 32 | ProcedureReturn Angle.f * #PI / 180 33 | EndProcedure 34 | 35 | ;Initialize all ball data 36 | Procedure InitialiseBalls() 37 | For x.l = 0 To #NUMBER_OF_BALLS 38 | Balls(x)\XOrigin = Random(ScrW) - 32 39 | Balls(x)\YOrigin = Random(ScrH) - 32 40 | Balls(x)\Radius = Random(190) + 10 41 | Balls(x)\Angle = Random(360) 42 | Balls(x)\Speed = Random(2) + 1 43 | Next x 44 | EndProcedure 45 | 46 | ;Initialize environment 47 | HandleError(InitSprite(), "InitSprite() command failed.") 48 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 49 | HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.") 50 | SetFrameRate(60) 51 | 52 | ;Create an image 53 | Global Offset.f = 32 54 | If CreateSprite(#SPRITE_MAIN, 64, 64) 55 | If StartDrawing(SpriteOutput(#SPRITE_MAIN)) 56 | Box(0, 0, 64, 64, RGB(255, 255, 255)) 57 | For x.l = 220 To 1 Step -1 58 | Offset + 0.025 59 | Circle(Offset, 64 - Offset, x / 8, RGB(0, 255 - x, 0)) 60 | Next x 61 | StopDrawing() 62 | EndIf 63 | EndIf 64 | TransparentSpriteColor(#SPRITE_MAIN, RGB(255, 255, 255)) 65 | InitialiseBalls() 66 | 67 | ;Main loop 68 | Repeat 69 | ClearScreen(RGB(56, 76, 104)) 70 | For x.l = 0 To #NUMBER_OF_BALLS 71 | Balls(x)\x=Balls(x)\XOrigin+(Balls(x)\Radius*Cos(DegToRad(Balls(x)\Angle))) 72 | Balls(x)\y=Balls(x)\YOrigin+(Balls(x)\Radius*Sin(DegToRad(Balls(x)\Angle))) 73 | Balls(x)\Angle + Balls(x)\Speed 74 | DisplayTransparentSprite(#SPRITE_MAIN, Balls(x)\x, Balls(x)\y) 75 | Next x 76 | FlipBuffers() 77 | 78 | ExamineKeyboard() 79 | If KeyboardReleased(#PB_Key_Escape) 80 | Quit = #True 81 | EndIf 82 | 83 | Until Quit = #True 84 | End 85 | ; IDE Options = PureBasic v4.00 (Windows - x86) 86 | ; HideErrorLog -------------------------------------------------------------------------------- /code/198/198a.pb: -------------------------------------------------------------------------------- 1 | UsePNGImageDecoder() 2 | 3 | Enumeration 4 | #SPRITE_2D 5 | #SPRITE_3D 6 | EndEnumeration 7 | 8 | #NUMBER_OF_FLOWERS = 150 9 | 10 | ;Set the width, height and bit depth of the screen 11 | ;Abbreviated variables are used here due to page width constraints :( 12 | Global ScrW.l = 1024 13 | Global ScrH.l = 768 14 | Global ScrD.l = 32 15 | ;Other global variables 16 | Global Quit.b = #False 17 | Global XOrigin.l = ScrW / 2 18 | Global YOrigin.l = ScrH / 2 19 | 20 | Structure FLOWER 21 | XPos.f 22 | YPos.f 23 | Width.f 24 | Height.f 25 | Angle.f 26 | Radius.f 27 | RadiusStep.f 28 | EndStructure 29 | Global Dim Flowers.FLOWER(#NUMBER_OF_FLOWERS) 30 | 31 | ;Simple error checking procedure 32 | Procedure HandleError(Result.l, Text.s) 33 | If Result = 0 34 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 35 | End 36 | EndIf 37 | EndProcedure 38 | 39 | ;Convert Degrees to Radians 40 | Procedure.f DegToRad(Angle.f) 41 | ProcedureReturn Angle.f * #PI / 180 42 | EndProcedure 43 | 44 | ;Initialize all flowers 45 | Procedure InitialiseAllFlowers() 46 | For x.l = 0 To #NUMBER_OF_FLOWERS 47 | Flowers(x)\Width = 0 48 | Flowers(x)\Height = 0 49 | Flowers(x)\Angle = Random(360) 50 | Flowers(x)\Radius = 1.0 51 | Flowers(x)\RadiusStep = (Random(30) / 10) + 1.0 52 | Next x 53 | EndProcedure 54 | 55 | ;Reset a flower 56 | Procedure ResetFlower(Index.l) 57 | Flowers(Index)\Width = 0 58 | Flowers(Index)\Height = 0 59 | Flowers(Index)\Angle = Random(360) 60 | Flowers(Index)\Radius = 1.0 61 | Flowers(Index)\RadiusStep = (Random(30) / 10) + 1.0 62 | ProcedureReturn 63 | EndProcedure 64 | 65 | ;Initialize environment 66 | HandleError(InitSprite(), "InitSprite() command failed.") 67 | HandleError(InitSprite3D(), "InitSprite3D() command failed.") 68 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 69 | HandleError(OpenScreen(ScrW, ScrH, ScrD, "Flowers"), "Could not open screen.") 70 | SetFrameRate(60) 71 | Sprite3DQuality(1) 72 | 73 | ;Load sprite 74 | LoadSprite(#SPRITE_2D,"Flower.png",#PB_Sprite_Texture|#PB_Sprite_AlphaBlending) 75 | CreateSprite3D(#SPRITE_3D, #SPRITE_2D) 76 | 77 | InitialiseAllFlowers() 78 | 79 | ;Main loop 80 | Repeat 81 | 82 | ClearScreen(RGB(200, 100, 100)) 83 | 84 | HandleError(Start3D(), "Start3D() command failed.") 85 | For x.l = 0 To #NUMBER_OF_FLOWERS 86 | Flowers(x)\Width + 1.5 87 | Flowers(x)\Height + 1.5 88 | Flowers(x)\Angle + 1.0 89 | If Flowers(x)\Width > 512.0 Or Flowers(x)\Height > 512.0 90 | Flowers(x)\Width = 512.0 91 | Flowers(x)\Height = 512.0 92 | EndIf 93 | If Flowers(x)\Radius > ScrW 94 | ResetFlower(x) 95 | EndIf 96 | Flowers(x)\Radius + Flowers(x)\RadiusStep 97 | Flowers(x)\XPos=XOrigin+(Flowers(x)\Radius*Cos(DegToRad(Flowers(x)\Angle))) 98 | Flowers(x)\YPos=YOrigin+(Flowers(x)\Radius*Sin(DegToRad(Flowers(x)\Angle))) 99 | Flowers(x)\XPos - Flowers(x)\Radius / 3.5 100 | Flowers(x)\YPos - Flowers(x)\Radius / 3.5 101 | ZoomSprite3D(#SPRITE_3D, Flowers(x)\Width, Flowers(x)\Height) 102 | RotateSprite3D(#SPRITE_3D, Flowers(x)\Angle, 0) 103 | DisplaySprite3D(#SPRITE_3D, Flowers(x)\XPos, Flowers(x)\YPos) 104 | Next x 105 | Stop3D() 106 | 107 | FlipBuffers() 108 | 109 | ExamineKeyboard() 110 | If KeyboardReleased(#PB_Key_Escape) 111 | Quit = #True 112 | EndIf 113 | 114 | Until Quit = #True 115 | End 116 | ; IDE Options = PureBasic v4.00 (Windows - x86) 117 | ; HideErrorLog -------------------------------------------------------------------------------- /code/198/Flower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/198/Flower.png -------------------------------------------------------------------------------- /code/20/20a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberTwo.l = 25 3 | NumberThree.l = NumberOne - NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/20/20b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberOne - 10 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/20/20c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 5 2 | NumberTwo.l = 25 3 | NumberThree.l = NumberOne * NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/20/20d.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberOne * 3 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/206/206a.pb: -------------------------------------------------------------------------------- 1 | ; NOTE 2 | ; Due to a bug in Purebasic regarding the 3d rotation commands using 3 | ; the wrong axis when performing rotations, this code may not perform 4 | ; as it should. To work around this bug, to make this code behave as 5 | ; normal please follow these instructions: 6 | ; 7 | ; Change line 62 to read: 8 | ; 'RotateCamera(#CAMERA_ONE, 0, -15, 0)' 9 | ; 10 | ; Change line 68 to read: 11 | ; 'RotateEntity(#ENTITY_INVADER, y, 0, 0)' 12 | ; 13 | ; I have spoken to Fred about this and he has assured me that this 14 | ; error will be fixed in the next update. 15 | ; 16 | ; Once the new update is released this will be fixed and the above 17 | ; steps will not be necessary. 18 | ; 19 | 20 | Enumeration 21 | #MESH 22 | #TEX 23 | #MAT 24 | #ENTITY_INVADER 25 | #LIGHT 26 | #CAMERA_ONE 27 | EndEnumeration 28 | 29 | ;Set the width, height and bit depth of the screen 30 | ;Abbreviated variables are used here due to page width constraints :( 31 | Global ScrW.l = 1024 32 | Global ScrH.l = 768 33 | Global ScrD.l = 32 34 | ;Other global variables 35 | Global Quit.b = #False 36 | 37 | ;Simple error checking procedure 38 | Procedure HandleError(Result.l, Text.s) 39 | If Result = 0 40 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 41 | End 42 | EndIf 43 | EndProcedure 44 | 45 | ;Initialize environment 46 | HandleError(InitEngine3D(), "InitEngine3D() command failed.") 47 | HandleError(InitSprite(), "InitSprite() command failed.") 48 | HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.") 49 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 50 | SetFrameRate(60) 51 | 52 | Add3DArchive("Data\", #PB_3DArchive_FileSystem) 53 | 54 | HandleError(LoadMesh(#MESH, "Invader.mesh"), "Can't load mesh") 55 | HandleError(LoadTexture(#TEX, "Invader.png"), "Can't load texture") 56 | HandleError(CreateMaterial(#MAT, TextureID(#TEX)), "Can't create Material") 57 | CreateEntity(#ENTITY_INVADER, MeshID(#MESH), MaterialID(#MAT)) 58 | 59 | CreateLight(#LIGHT, RGB(255,255,255), 0, 5, 0) 60 | 61 | CreateCamera(#CAMERA_ONE, 0, 0, 100, 100) 62 | CameraLocate(#CAMERA_ONE, 0, 1, 2.5) 63 | RotateCamera(#CAMERA_ONE, -15, 0, 0) 64 | 65 | ;Main loop 66 | Repeat 67 | 68 | y.l + 2 69 | RotateEntity(#ENTITY_INVADER, 0, y, 0) 70 | 71 | RenderWorld() 72 | FlipBuffers() 73 | 74 | ExamineKeyboard() 75 | If KeyboardReleased(#PB_Key_Escape) 76 | Quit = #True 77 | EndIf 78 | 79 | Until Quit = #True 80 | End 81 | ; IDE Options = PureBasic v4.00 (Windows - x86) 82 | ; HideErrorLog -------------------------------------------------------------------------------- /code/206/Data/Invader.mesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/206/Data/Invader.mesh -------------------------------------------------------------------------------- /code/206/Data/Invader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/206/Data/Invader.png -------------------------------------------------------------------------------- /code/21/21a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 100 2 | NumberTwo.l = 2 3 | NumberThree.l = NumberOne / NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/21/21b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 50 2 | NumberOne / 5 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/215/215a.pb: -------------------------------------------------------------------------------- 1 | ; NOTE 2 | ; Due to a bug in Purebasic regarding the 3d rotation commands using 3 | ; the wrong axis when performing rotations, this code may not perform 4 | ; as it should. To work around this bug, to make this code behave as 5 | ; normal please follow these instructions: 6 | ; 7 | ; Change line 77 to read: 8 | ; 'RotateCamera(#CAMERA_ONE, MouseYRotation, MouseXRotation, 0)' 9 | ; 10 | ; I have spoken to Fred about this and he has assured me that this 11 | ; error will be fixed in the next update. 12 | ; 13 | ; Once the new update is released this will be fixed and the above 14 | ; steps will not be necessary. 15 | ; 16 | 17 | Enumeration 18 | #TEXTURE_GLOBAL 19 | #TEXTURE_DETAIL 20 | #MATERIAL_TERRAIN 21 | #CAMERA_ONE 22 | EndEnumeration 23 | 24 | #MOVEMENT_SPEED = 1 25 | 26 | ;Set the width, height and bit depth of the screen 27 | ;Abbreviated variables are used here due to page width constraints :( 28 | Global ScrW.l = 1024 29 | Global ScrH.l = 768 30 | Global ScrD.l = 32 31 | 32 | ;Other global variables 33 | Global Quit.b = #False 34 | Global MouseXRotation.f,MouseYRotation.f,KeyX.f,KeyZ.f,DesiredCameraHeight.f 35 | Global CurrentCamXPos.f = 545 36 | Global CurrentCamZPos.f = 280 37 | 38 | ;Simple error checking procedure 39 | Procedure HandleError(Result.l, Text.s) 40 | If Result = 0 41 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 42 | End 43 | EndIf 44 | EndProcedure 45 | 46 | ;Initialize environment 47 | HandleError(InitEngine3D(), "InitEngine3D() command failed.") 48 | HandleError(InitSprite(), "InitSprite() command failed.") 49 | HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.") 50 | HandleError(InitMouse(), "InitMouse() command failed.") 51 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 52 | SetFrameRate(60) 53 | 54 | ;Set 3D Archive 55 | Add3DArchive("Data\", #PB_3DArchive_FileSystem) 56 | 57 | ;Create Terrain 58 | HandleError(LoadTexture(#TEXTURE_GLOBAL, "Global.png"), "Can't load texture") 59 | HandleError(LoadTexture(#TEXTURE_DETAIL, "Detail.png"), "Can't load texture") 60 | CreateMaterial(#MATERIAL_TERRAIN, TextureID(#TEXTURE_GLOBAL)) 61 | AddMaterialLayer(#MATERIAL_TERRAIN,TextureID(#TEXTURE_DETAIL),#PB_Material_Add) 62 | CreateTerrain("Terrain.png", MaterialID(#MATERIAL_TERRAIN), 1, 2, 1) 63 | 64 | ;Create Viewport and 3D Camera 65 | CreateCamera(#CAMERA_ONE, 0, 0, 100, 100) 66 | DesiredCameraHeight.f = TerrainHeight(CurrentCamXPos, CurrentCamZPos) + 10 67 | CameraLocate(#CAMERA_ONE,CurrentCamXPos,DesiredCameraHeight,CurrentCamZPos) 68 | 69 | ;Main loop 70 | Repeat 71 | 72 | ;Update Mouse 73 | If ExamineMouse() 74 | MouseYRotation = -MouseDeltaX() / 10 75 | MouseXRotation = MouseDeltaY() / 10 76 | EndIf 77 | RotateCamera(#CAMERA_ONE, MouseXRotation, MouseYRotation, 0) 78 | ;Update Key Presses and position the Camera accordingly 79 | If ExamineKeyboard() 80 | If KeyboardPushed(#PB_Key_Left) : KeyX = -#MOVEMENT_SPEED : EndIf 81 | If KeyboardPushed(#PB_Key_Right) : KeyX = #MOVEMENT_SPEED : EndIf 82 | If KeyboardPushed(#PB_Key_Up) : KeyZ = -#MOVEMENT_SPEED : EndIf 83 | If KeyboardPushed(#PB_Key_Down) : KeyZ = #MOVEMENT_SPEED : EndIf 84 | MoveCamera(#CAMERA_ONE, KeyX, 0, KeyZ) 85 | KeyX = 0 86 | KeyZ = 0 87 | CurrentCamXPos.f = CameraX(#CAMERA_ONE) 88 | CurrentCamZPos.f = CameraZ(#CAMERA_ONE) 89 | DesiredCameraHeight.f = TerrainHeight(CurrentCamXPos, CurrentCamZPos) + 10 90 | CameraLocate(#CAMERA_ONE,CurrentCamXPos,DesiredCameraHeight,CurrentCamZPos) 91 | EndIf 92 | 93 | RenderWorld() 94 | FlipBuffers() 95 | 96 | If KeyboardReleased(#PB_Key_Escape) 97 | Quit = #True 98 | EndIf 99 | 100 | Until Quit = #True 101 | End 102 | ; IDE Options = PureBasic v4.00 (Windows - x86) 103 | ; HideErrorLog -------------------------------------------------------------------------------- /code/215/Data/Detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/215/Data/Detail.png -------------------------------------------------------------------------------- /code/215/Data/Global.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/215/Data/Global.png -------------------------------------------------------------------------------- /code/215/Data/Terrain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/215/Data/Terrain.png -------------------------------------------------------------------------------- /code/22/22a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 77 2 | NumberTwo.b = 117 3 | NumberThree.b = NumberOne & NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/22/22b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 77 2 | NumberOne & 117 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/221/221a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #MESH 3 | #TEXTURE 4 | #MATERIAL 5 | #ENTITY 6 | #CAMERA_ONE 7 | #LIGHT_ONE 8 | #LIGHT_TWO 9 | #PARTICLE_ONE 10 | EndEnumeration 11 | 12 | ;Set the width, height and bit depth of the screen 13 | ;Abbreviated variables are used here due to page width constraints :( 14 | Global ScrW.l = 1024 15 | Global ScrH.l = 768 16 | Global ScrD.l = 32 17 | ;Other global variables 18 | Global Quit.b = #False 19 | 20 | ;Simple error checking procedure 21 | Procedure HandleError(Result.l, Text.s) 22 | If Result = 0 23 | MessageRequester("Error", Text, #PB_MessageRequester_Ok) 24 | End 25 | EndIf 26 | EndProcedure 27 | 28 | ;Convert Degrees to Radians 29 | Procedure.f DegToRad(Angle.f) 30 | ProcedureReturn Angle.f * #PI / 180 31 | EndProcedure 32 | 33 | ;Initialize environment 34 | HandleError(InitEngine3D(), "InitEngine3D() command failed.") 35 | HandleError(InitSprite(), "InitSprite() command failed.") 36 | HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.") 37 | HandleError(InitKeyboard(), "InitKeyboard() command failed.") 38 | SetFrameRate(60) 39 | 40 | Add3DArchive("Data\", #PB_3DArchive_FileSystem) 41 | Parse3DScripts() 42 | CreateEntity(#ENTITY, LoadMesh(#MESH, "Statue.mesh"), #PB_Material_None) 43 | 44 | LoadTexture(#TEXTURE, "Flame.png") 45 | CreateMaterial(#MATERIAL, TextureID(#TEXTURE)) 46 | DisableMaterialLighting(#MATERIAL, 1) 47 | MaterialBlendingMode(#MATERIAL, #PB_Material_Add) 48 | 49 | CreateParticleEmitter(#PARTICLE_ONE, 2, 2, 0,#PB_Particle_Point,12.9, 69, 15.7) 50 | ParticleSize(#PARTICLE_ONE, 5, 5) 51 | ParticleMaterial(#PARTICLE_ONE, MaterialID(#MATERIAL)) 52 | ParticleEmissionRate(#PARTICLE_ONE, 50) 53 | ParticleTimeToLive(#PARTICLE_ONE, 0.25, 0.25) 54 | ParticleColorRange(#PARTICLE_ONE, RGB(255, 0, 0), RGB(255, 200, 0)) 55 | ParticleVelocity(#PARTICLE_ONE, 1, 10) 56 | 57 | CreateLight(#LIGHT_ONE, RGB(255,255,255)) 58 | CreateLight(#LIGHT_TWO, RGB(255, 200, 0), 12.9, 72, 15.7) 59 | CreateCamera(#CAMERA_ONE, 0, 0, 100, 100) 60 | 61 | ;Main loop 62 | Repeat 63 | 64 | Angle.f + 0.5 65 | PosX.f = 75 * Sin(DegToRad(Angle)) 66 | PosY.f = (50 * Sin(DegToRad(Angle / 2))) + 65 67 | PosZ.f = 75 * Cos(DegToRad(Angle)) 68 | LightLocate(#LIGHT_ONE, PosX, PosY + 100, PosZ) 69 | LightColor(#LIGHT_TWO, RGB(255, Random(200), 0)) 70 | CameraLocate(#CAMERA_ONE, PosX, PosY, PosZ) 71 | CameraLookAt(#CAMERA_ONE, 0, 60, 0) 72 | RenderWorld() 73 | FlipBuffers() 74 | 75 | ExamineKeyboard() 76 | If KeyboardReleased(#PB_Key_Escape) 77 | Quit = #True 78 | EndIf 79 | Until Quit = #True 80 | End 81 | 82 | ; IDE Options = PureBasic 4.40 Beta 5 (Windows - x64) 83 | ; HideErrorLog -------------------------------------------------------------------------------- /code/221/Data/SphereMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/221/Data/SphereMap.png -------------------------------------------------------------------------------- /code/221/Data/Statue.material: -------------------------------------------------------------------------------- 1 | material Statue 2 | { 3 | technique 4 | { 5 | pass 6 | { 7 | texture_unit 8 | { 9 | texture SphereMap.png 10 | env_map spherical 11 | filtering trilinear 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /code/221/Data/Statue.mesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/221/Data/Statue.mesh -------------------------------------------------------------------------------- /code/221/Data/flame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/221/Data/flame.png -------------------------------------------------------------------------------- /code/227/227a.pb: -------------------------------------------------------------------------------- 1 | #SOUND_FILE = 1 2 | If InitSound() 3 | 4 | LoadSound(#SOUND_FILE, "Intro.wav") 5 | PlaySound(#SOUND_FILE) 6 | 7 | StartTime.l = ElapsedMilliseconds() 8 | Repeat 9 | Delay(1) 10 | Until ElapsedMilliseconds() > StartTime + 8000 11 | End 12 | EndIf 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/227/Intro.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/227/Intro.wav -------------------------------------------------------------------------------- /code/228/228a.pb: -------------------------------------------------------------------------------- 1 | #SOUND_FILE = 1 2 | If InitSound() 3 | 4 | CatchSound(#SOUND_FILE, ?SoundFile) 5 | PlaySound(#SOUND_FILE) 6 | 7 | StartTime.l = ElapsedMilliseconds() 8 | Repeat 9 | Delay(1) 10 | Until ElapsedMilliseconds() > StartTime + 8000 11 | End 12 | EndIf 13 | 14 | DataSection 15 | SoundFile: 16 | IncludeBinary "Intro.wav" 17 | EndDataSection 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/228/Intro.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/228/Intro.wav -------------------------------------------------------------------------------- /code/229/229a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_ROOT 3 | #SOUND_FILE 4 | #TEXT_FILE 5 | #BUTTON_CHOOSE_FILE 6 | #TEXT_VOLUME 7 | #TRACKBAR_VOLUME 8 | #TEXT_PAN 9 | #TRACKBAR_PAN 10 | #TEXT_FREQUENCY 11 | #TRACKBAR_FREQUENCY 12 | #BUTTON_PLAY_FILE 13 | #BUTTON_STOP_FILE 14 | EndEnumeration 15 | 16 | Global FileName.s = "" 17 | 18 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 19 | If OpenWindow(#WINDOW_ROOT, 0, 0, 500, 250, "Sound Player", #FLAGS) 20 | If CreateGadgetList(WindowID(#WINDOW_ROOT)) 21 | TextGadget(#TEXT_FILE, 10, 10, 480, 20, "", #PB_Text_Border) 22 | ButtonGadget(#BUTTON_CHOOSE_FILE, 10, 40, 150, 20, "Choose Wave File...") 23 | 24 | TextGadget(#TEXT_VOLUME, 10, 70, 480, 20, "Volume") 25 | TrackBarGadget(#TRACKBAR_VOLUME, 10, 90, 480, 20, 0, 100) 26 | SetGadgetState(#TRACKBAR_VOLUME, 100) 27 | 28 | TextGadget(#TEXT_PAN, 10, 120, 480, 20, "Pan") 29 | TrackBarGadget(#TRACKBAR_PAN, 10, 140, 480, 20, 0, 200) 30 | SetGadgetState(#TRACKBAR_PAN, 100) 31 | 32 | TextGadget(#TEXT_FREQUENCY, 10, 170, 480, 20, "Frequency") 33 | TrackBarGadget(#TRACKBAR_FREQUENCY, 10, 190, 480, 20, 100, 10000) 34 | SetGadgetState(#TRACKBAR_FREQUENCY, 4400) 35 | 36 | ButtonGadget(#BUTTON_PLAY_FILE, 10, 220, 100, 20, "Play File") 37 | ButtonGadget(#BUTTON_STOP_FILE, 130, 220, 100, 20, "Stop Sound") 38 | 39 | If InitSound() 40 | Repeat 41 | Event.l = WaitWindowEvent() 42 | Select Event 43 | Case #PB_Event_Gadget 44 | 45 | Select EventGadget() 46 | Case #BUTTON_CHOOSE_FILE 47 | FileName=OpenFileRequester("Choose","","Wave File (*.wav)|*.wav",0) 48 | If filename <> "" 49 | SetGadgetText(#TEXT_FILE, GetFilePart(FileName)) 50 | LoadSound(#SOUND_FILE, filename) 51 | EndIf 52 | 53 | Case #TRACKBAR_VOLUME 54 | If filename <> "" 55 | SoundVolume(#SOUND_FILE, GetGadgetState(#TRACKBAR_VOLUME)) 56 | EndIf 57 | 58 | Case #TRACKBAR_PAN 59 | If filename <> "" 60 | SoundPan(#SOUND_FILE, GetGadgetState(#TRACKBAR_PAN) - 100) 61 | EndIf 62 | 63 | Case #TRACKBAR_FREQUENCY 64 | If filename <> "" 65 | SoundFrequency(#SOUND_FILE,GetGadgetState(#TRACKBAR_FREQUENCY) * 10) 66 | EndIf 67 | 68 | Case #BUTTON_PLAY_FILE 69 | If filename <> "" 70 | PlaySound(#SOUND_FILE) 71 | EndIf 72 | 73 | Case #BUTTON_STOP_FILE 74 | If filename <> "" 75 | StopSound(#SOUND_FILE) 76 | EndIf 77 | EndSelect 78 | 79 | EndSelect 80 | Until Event = #PB_Event_CloseWindow 81 | EndIf 82 | EndIf 83 | EndIf 84 | End 85 | ; IDE Options = PureBasic v4.00 (Windows - x86) 86 | ; HideErrorLog -------------------------------------------------------------------------------- /code/229/Intro.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/229/Intro.wav -------------------------------------------------------------------------------- /code/23/23a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 54 2 | NumberTwo.b = 102 3 | NumberThree.b = NumberOne & NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/23/23b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 54 2 | NumberOne | 102 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/232/232a.pb: -------------------------------------------------------------------------------- 1 | #MODULE_FILE = 1 2 | 3 | If InitSound() 4 | If InitModule() 5 | 6 | LoadModule(#MODULE_FILE, "Eighth.mod") 7 | PlayModule(#MODULE_FILE) 8 | 9 | StartTime.l = ElapsedMilliseconds() 10 | Repeat 11 | Delay(1) 12 | Until ElapsedMilliseconds() > StartTime + 15000 13 | 14 | StopModule(#MODULE_FILE) 15 | 16 | End 17 | EndIf 18 | EndIf 19 | ; IDE Options = PureBasic v4.00 (Windows - x86) 20 | ; HideErrorLog -------------------------------------------------------------------------------- /code/232/Eighth.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/232/Eighth.mod -------------------------------------------------------------------------------- /code/234/234a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_ROOT 3 | #SOUND_FILE 4 | #TEXT_FILE 5 | #BUTTON_CHOOSE_FILE 6 | #TEXT_VOLUME 7 | #TRACKBAR_VOLUME 8 | #TEXT_PAN 9 | #TRACKBAR_PAN 10 | #BUTTON_PLAY_FILE 11 | #BUTTON_PAUSE_FILE 12 | #BUTTON_STOP_FILE 13 | EndEnumeration 14 | 15 | Global FileName.s = "" 16 | Global FilePaused.b = #False 17 | 18 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 19 | If OpenWindow(#WINDOW_ROOT, 0, 0, 500, 215, "MP3 Player", #FLAGS) 20 | If CreateGadgetList(WindowID(#WINDOW_ROOT)) 21 | TextGadget(#TEXT_FILE, 10, 10, 480, 20, "", #PB_Text_Border) 22 | ButtonGadget(#BUTTON_CHOOSE_FILE, 10, 40, 150, 20, "Choose MP3 File...") 23 | TextGadget(#TEXT_VOLUME, 10, 70, 480, 20, "Volume") 24 | TrackBarGadget(#TRACKBAR_VOLUME, 10, 90, 480, 20, 0, 100) 25 | SetGadgetState(#TRACKBAR_VOLUME, 100) 26 | TextGadget(#TEXT_PAN, 10, 120, 480, 20, "Pan") 27 | TrackBarGadget(#TRACKBAR_PAN, 10, 140, 480, 20, 0, 200) 28 | SetGadgetState(#TRACKBAR_PAN, 100) 29 | ButtonGadget(#BUTTON_PLAY_FILE, 10, 180, 100, 20, "Play") 30 | ButtonGadget(#BUTTON_PAUSE_FILE, 130, 180, 100, 20, "Pause") 31 | ButtonGadget(#BUTTON_STOP_FILE, 250, 180, 100, 20, "Stop") 32 | 33 | If InitMovie() 34 | Repeat 35 | Event.l = WaitWindowEvent() 36 | Select Event 37 | Case #PB_Event_Gadget 38 | 39 | Select EventGadget() 40 | Case #BUTTON_CHOOSE_FILE 41 | FileName=OpenFileRequester("Choose","","MP3 File (*.mp3)|*.mp3",0) 42 | If filename <> "" 43 | SetGadgetText(#TEXT_FILE, GetFilePart(FileName)) 44 | LoadMovie(#SOUND_FILE, filename) 45 | EndIf 46 | 47 | Case #TRACKBAR_VOLUME, #TRACKBAR_PAN 48 | If filename <> "" 49 | Volume.l = GetGadgetState(#TRACKBAR_VOLUME) 50 | Balance.l = GetGadgetState(#TRACKBAR_PAN) - 100 51 | MovieAudio(#SOUND_FILE, Volume, Balance) 52 | EndIf 53 | 54 | Case #BUTTON_PLAY_FILE 55 | If filename <> "" 56 | PlayMovie(#SOUND_FILE, #Null) 57 | FilePaused = #False 58 | SetGadgetText(#BUTTON_PAUSE_FILE, "Pause") 59 | EndIf 60 | 61 | Case #BUTTON_PAUSE_FILE 62 | If filename <> "" 63 | If FilePaused = #False 64 | PauseMovie(#SOUND_FILE) 65 | FilePaused = #True 66 | SetGadgetText(#BUTTON_PAUSE_FILE, "Resume") 67 | Else 68 | ResumeMovie(#SOUND_FILE) 69 | FilePaused = #False 70 | SetGadgetText(#BUTTON_PAUSE_FILE, "Pause") 71 | EndIf 72 | EndIf 73 | 74 | Case #BUTTON_STOP_FILE 75 | If filename <> "" 76 | StopMovie(#SOUND_FILE) 77 | FilePaused = #False 78 | SetGadgetText(#BUTTON_PAUSE_FILE, "Pause") 79 | EndIf 80 | EndSelect 81 | 82 | EndSelect 83 | Until Event = #PB_Event_CloseWindow 84 | EndIf 85 | EndIf 86 | EndIf 87 | End 88 | ; IDE Options = PureBasic v4.00 (Windows - x86) 89 | ; HideErrorLog -------------------------------------------------------------------------------- /code/234/Ride the Wind.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/code/234/Ride the Wind.mp3 -------------------------------------------------------------------------------- /code/247/247a.pb: -------------------------------------------------------------------------------- 1 | CompilerIf #PB_Compiler_OS = #PB_OS_Windows 2 | MessageRequester("Info", "This compiler is running on Microsoft Windows") 3 | CompilerElse 4 | MessageRequester("Info", "This compiler is NOT running on Microsoft Windows") 5 | CompilerEndIf 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/248/248a.pb: -------------------------------------------------------------------------------- 1 | #DEMO = #True 2 | 3 | CompilerIf #DEMO 4 | 5 | ;Demo code 6 | MessageRequester("Info", "This is a demo, You must buy the full version.") 7 | 8 | CompilerElse 9 | 10 | ;Full version code 11 | Procedure.d MyPI() 12 | ProcedureReturn ACos(-1) 13 | EndProcedure 14 | 15 | Test.s = "This is the full version." + #LF$ + #LF$ 16 | Test.s + "The value of Pi is: " + StrD(MyPI(), 16) 17 | MessageRequester("Info", Test) 18 | 19 | CompilerEndIf 20 | ; IDE Options = PureBasic v4.00 (Windows - x86) 21 | ; HideErrorLog -------------------------------------------------------------------------------- /code/248/248b.pb: -------------------------------------------------------------------------------- 1 | CompilerSelect #PB_Compiler_OS 2 | 3 | CompilerCase #PB_OS_Windows 4 | ;Windows specific code 5 | MessageRequester("Info", "This is being compiled on Microsoft Windows.") 6 | 7 | CompilerCase #PB_OS_Linux 8 | ;Linux specific code 9 | MessageRequester("Info", "This is being compiled on Linux.") 10 | 11 | CompilerCase #PB_OS_MacOS 12 | ;MacOS specific code 13 | MessageRequester("Info", "This is being compiled on MacOS X") 14 | 15 | CompilerCase #PB_OS_AmigaOS 16 | ;AmigaOS specific code 17 | MessageRequester("Info", "This is being compiled on Amiga OS.") 18 | 19 | CompilerEndSelect 20 | ; IDE Options = PureBasic v4.00 (Windows - x86) 21 | ; HideErrorLog -------------------------------------------------------------------------------- /code/249/249a.pb: -------------------------------------------------------------------------------- 1 | CompilerSelect #PB_Compiler_OS 2 | 3 | CompilerCase #PB_OS_AmigaOS 4 | ;AmigaOS specific code 5 | MessageRequester("Error", "This source code does not support Amiga OS.") 6 | 7 | CompilerDefault 8 | ;This code will compile on all other operating systems. 9 | MessageRequester("Info", "This is code will compile fine on this OS.") 10 | 11 | CompilerEndSelect 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/25/25a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 38 2 | NumberTwo.b = 74 3 | NumberThree.b = NumberOne ! NumberTwo 4 | Debug NumberThree 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/25/25b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 38 2 | NumberOne ! 74 3 | Debug NumberOne 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/250/250a.pb: -------------------------------------------------------------------------------- 1 | CompilerSelect #PB_Compiler_OS 2 | 3 | CompilerCase #PB_OS_MacOS 4 | CompilerError "This source code does not support MacOS." 5 | 6 | CompilerDefault 7 | MessageRequester("Info", "This is code will compile fine on this OS.") 8 | 9 | CompilerEndSelect 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/251/251a.pb: -------------------------------------------------------------------------------- 1 | If Subsystem("OpenGL") 2 | Debug "The OpenGL subsystem is being used." 3 | EndIf 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/252/252a.pb: -------------------------------------------------------------------------------- 1 | Global Name.s = "Name 1" 2 | 3 | If Not Defined(Name, #PB_Variable) 4 | ;This will only define this variable if it hasn't been defined before 5 | Global Name.s = "Name 2" 6 | EndIf 7 | 8 | Debug Name 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/26/26a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 43 2 | NumberTwo.b = ~NumberOne 3 | Debug NumberTwo 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/26/26b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 50 2 | NumberTwo.b = NumberOne << 1 3 | Debug NumberTwo 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/260/260a.pb: -------------------------------------------------------------------------------- 1 | NumberOfParameters.l = CountProgramParameters() 2 | Text.s = "List of parameters passed:" + #LF$ + #LF$ 3 | 4 | If NumberOfParameters > 0 5 | For x.l = 1 To NumberOfParameters 6 | Text.s + ProgramParameter() + #LF$ 7 | Next x 8 | Else 9 | Text.s + "None" 10 | EndIf 11 | 12 | MessageRequester("Info", Text) 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/261/261a.pb: -------------------------------------------------------------------------------- 1 | ;Count parameters 2 | NumberOfParameters.l = CountProgramParameters() 3 | 4 | ;Add all command line parameters to a linked list 5 | Global NewList Parameters.s() 6 | If NumberOfParameters > 0 7 | For x.l = 1 To NumberOfParameters 8 | AddElement(Parameters()) 9 | Parameters() = UCase(ProgramParameter()) 10 | Next x 11 | EndIf 12 | 13 | ;Check to see if a particular parameter was passed 14 | Procedure ParameterPassed(Parameter.s) 15 | ForEach Parameters() 16 | If Parameter = Parameters() 17 | ProcedureReturn #True 18 | EndIf 19 | Next 20 | ProcedureReturn #False 21 | EndProcedure 22 | 23 | ;Check to see if the parameter 'Mouse' was passed 24 | If ParameterPassed("MOUSE") 25 | MessageRequester("Info", "'Mouse' was specified as a parameter.") 26 | EndIf 27 | ;Check to see if the parameter 'Cat' was passed 28 | If ParameterPassed("CAT") 29 | MessageRequester("Info", "'Cat' was specified as a parameter.") 30 | EndIf 31 | ;Check to see if the parameter 'Dog' was passed 32 | If ParameterPassed("DOG") 33 | MessageRequester("Info", "'Dog' was specified as a parameter.") 34 | EndIf 35 | ; IDE Options = PureBasic v4.00 (Windows - x86) 36 | ; HideErrorLog -------------------------------------------------------------------------------- /code/269/269a.pb: -------------------------------------------------------------------------------- 1 | BinaryVariable.b = %01101101 2 | Debug BinaryVariable 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/27/27a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.b = 50 2 | NumberTwo.b = NumberOne >> 1 3 | Debug NumberTwo 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/270/270a.pb: -------------------------------------------------------------------------------- 1 | MyByteVar.b = 100 2 | Debug MyByteVar 3 | Debug @MyByteVar 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/271/271a.pb: -------------------------------------------------------------------------------- 1 | MyByteVar.b = 1 2 | MyWordVar.w = 2 3 | MyLongVar.l = 3 4 | MyQuadVar.q = 4 5 | MyFloatVar.f = 5 6 | MyDoubleVar.d = 6 7 | MyStringVar.s = "Seven" 8 | Dim MyLongArray.l(8) 9 | 10 | Procedure MyProcedure(Test.l) 11 | Debug "Testing my procedure." 12 | EndProcedure 13 | 14 | Debug "Byte variable address: " + Str(@MyByteVar) 15 | Debug "Word variable address: " + Str(@MyWordVar) 16 | Debug "Long variable address: " + Str(@MyLongVar) 17 | Debug "Quad variable address: " + Str(@MyQuadVar) 18 | Debug "Float variable address: " + Str(@MyFloatVar) 19 | Debug "Double variable address: " + Str(@MyDoubleVar) 20 | Debug "String variable address: " + Str(@MyStringVar) 21 | Debug "Array address: " + Str(@MyLongArray()) 22 | Debug "Procedure address: " + Str(@MyProcedure()) 23 | Debug "Label address: " + Str(?Label) 24 | 25 | DataSection 26 | Label: 27 | Data.s "Testing" 28 | EndDataSection 29 | ; IDE Options = PureBasic v4.00 (Windows - x86) 30 | ; HideErrorLog -------------------------------------------------------------------------------- /code/273/273a.pb: -------------------------------------------------------------------------------- 1 | MyByteVar.b = 100 2 | *MemoryAddress = @MyByteVar 3 | Debug MyByteVar 4 | Debug *MemoryAddress 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/273/273b.pb: -------------------------------------------------------------------------------- 1 | Structure DETAILS 2 | Age.l 3 | Height.l 4 | EndStructure 5 | 6 | My.DETAILS 7 | My\Age = 32 8 | My\Height = 168 9 | 10 | *Pointer.DETAILS = @My 11 | 12 | Debug *Pointer\Age 13 | Debug *Pointer\Height 14 | ; IDE Options = PureBasic v4.00 (Windows - x86) 15 | ; HideErrorLog -------------------------------------------------------------------------------- /code/274/274a.pb: -------------------------------------------------------------------------------- 1 | Structure MEALS 2 | Breakfast.s 3 | Dinner.s 4 | Tea.s 5 | EndStructure 6 | 7 | Procedure.l GetMeals() 8 | Static Gary.MEALS 9 | Gary\Breakfast = "Cornflakes" 10 | Gary\Dinner = "Cheese Sandwiches" 11 | Gary\Tea = "Spaghetti bolognese" 12 | ProcedureReturn @Gary 13 | EndProcedure 14 | 15 | *Gary.MEALS = GetMeals() 16 | 17 | Debug *Gary\Breakfast 18 | Debug *Gary\Dinner 19 | Debug *Gary\Tea 20 | ; IDE Options = PureBasic v4.00 (Windows - x86) 21 | ; HideErrorLog -------------------------------------------------------------------------------- /code/275/275a.pb: -------------------------------------------------------------------------------- 1 | Structure SCREENCOORDS 2 | x.w 3 | y.w 4 | EndStructure 5 | 6 | Coordinates.l = %00000011000000000000010000000000 7 | *Screen.SCREENCOORDS = @Coordinates 8 | 9 | Debug *Screen\x 10 | Debug *Screen\y 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/275/275b.pb: -------------------------------------------------------------------------------- 1 | Structure COORDINATES 2 | x.l 3 | y.l 4 | EndStructure 5 | Point.COORDINATES 6 | 7 | Procedure IncreaseValues(*Var.COORDINATES) 8 | *Var\x + 10 9 | *Var\y + 10 10 | EndProcedure 11 | 12 | Point\x = 100 13 | Point\y = 100 14 | 15 | IncreaseValues(@Point) 16 | Debug Point\x 17 | Debug Point\y 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/277/277a.pb: -------------------------------------------------------------------------------- 1 | Weight.b = 30 2 | *Weight = @Weight 3 | ReadValue.b = PeekB(*Weight) 4 | Debug ReadValue 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/277/277b.pb: -------------------------------------------------------------------------------- 1 | Weight.b = 30 2 | ReadValue.b = PeekB(@Weight) 3 | Debug ReadValue 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/277/277c.pb: -------------------------------------------------------------------------------- 1 | Weight.l = 1024 2 | *Weight = @Weight 3 | PokeL(*Weight, 333) 4 | Debug Weight 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /code/278/278a.pb: -------------------------------------------------------------------------------- 1 | Dim Numbers.l(2) 2 | 3 | Numbers(0) = 100 4 | Numbers(1) = 200 5 | Numbers(2) = 300 6 | 7 | *ArrayPointer = @Numbers() 8 | 9 | Debug PeekL(*ArrayPointer) 10 | Debug PeekL(*ArrayPointer + 4) 11 | Debug PeekL(*ArrayPointer + 8) 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/28/28a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 1 2 | NumberTwo.l = 2 3 | 4 | If NumberOne < NumberTwo 5 | Debug "1: NumberOne is less than NumberTwo" 6 | Else 7 | Debug "2: NumberTwo is less than NumberOne" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/28/28b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 3 2 | NumberTwo.l = 2 3 | 4 | If NumberOne < NumberTwo 5 | Debug "1: NumberOne is less than NumberTwo" 6 | Else 7 | Debug "2: NumberTwo is less than NumberOne" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/28/28c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 2 2 | NumberTwo.l = 1 3 | 4 | If NumberOne > NumberTwo 5 | Debug "1: NumberOne is more than NumberTwo" 6 | Else 7 | Debug "2: NumberTwo is more than NumberOne" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/280/280a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #WINDOW_ROOT 3 | #LIST_ONE 4 | #LIST_TWO 5 | #BUTTON_TEST 6 | EndEnumeration 7 | 8 | Procedure InsertText(Gadget.l) 9 | For x.l = 1 To 25 10 | AddGadgetItem(Gadget, -1, Str(x)) 11 | Delay(100) 12 | Next x 13 | EndProcedure 14 | 15 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 16 | If OpenWindow(#WINDOW_ROOT, 0, 0, 290, 200, "Thread Test", #FLAGS) 17 | If CreateGadgetList(WindowID(#WINDOW_ROOT)) 18 | ListViewGadget(#LIST_ONE, 10, 10, 130, 150) 19 | ListViewGadget(#LIST_TWO, 150, 10, 130, 150) 20 | ButtonGadget(#BUTTON_TEST, 95, 170, 100, 20, "Start Test") 21 | Repeat 22 | EventID.l = WaitWindowEvent() 23 | Select EventID 24 | Case #PB_Event_Gadget 25 | Select EventGadget() 26 | Case #BUTTON_TEST 27 | InsertText(#LIST_ONE) 28 | InsertText(#LIST_TWO) 29 | EndSelect 30 | EndSelect 31 | Until EventID = #PB_Event_CloseWindow 32 | EndIf 33 | EndIf 34 | End 35 | ; IDE Options = PureBasic v4.00 (Windows - x86) 36 | ; HideErrorLog -------------------------------------------------------------------------------- /code/281/281a.pb: -------------------------------------------------------------------------------- 1 | ; Remember to turn on 'Create threadsafe executable' in the compiler options! 2 | 3 | Enumeration 4 | #WINDOW_ROOT 5 | #LIST_ONE 6 | #LIST_TWO 7 | #BUTTON_TEST 8 | EndEnumeration 9 | 10 | 11 | ;Insert text into the specified list gadget 12 | Procedure InsertText(Gadget.l) 13 | For x.l = 1 To 25 14 | AddGadgetItem(Gadget, -1, Str(x)) 15 | Delay(100) 16 | Next x 17 | EndProcedure 18 | 19 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 20 | If OpenWindow(#WINDOW_ROOT, 0, 0, 290, 200, "Thread Test", #FLAGS) 21 | If CreateGadgetList(WindowID(#WINDOW_ROOT)) 22 | ListViewGadget(#LIST_ONE, 10, 10, 130, 150) 23 | ListViewGadget(#LIST_TWO, 150, 10, 130, 150) 24 | ButtonGadget(#BUTTON_TEST, 95, 170, 100, 20, "Start Test") 25 | Repeat 26 | EventID.l = WaitWindowEvent() 27 | Select EventID 28 | Case #PB_Event_Gadget 29 | Select EventGadget() 30 | Case #BUTTON_TEST 31 | Thread1.l = CreateThread(@InsertText(), #LIST_ONE) 32 | Thread2.l = CreateThread(@InsertText(), #LIST_TWO) 33 | EndSelect 34 | EndSelect 35 | Until EventID = #PB_Event_CloseWindow 36 | EndIf 37 | EndIf 38 | End 39 | ; IDE Options = PureBasic v4.00 (Windows - x86) 40 | ; EnableThread 41 | ; HideErrorLog -------------------------------------------------------------------------------- /code/283/283a.pb: -------------------------------------------------------------------------------- 1 | ; Remember to turn on 'Create threadsafe executable' in the compiler options! 2 | 3 | Procedure DrawNumbers(Unused.l) 4 | For x.l = 1 To 20 5 | PrintN(Str(x)) 6 | Delay(75) 7 | Next x 8 | EndProcedure 9 | 10 | If OpenConsole() 11 | ThreadID.l = CreateThread(@DrawNumbers(), 0) 12 | WaitThread(ThreadID) 13 | Print("Press Return to quit") : Input() 14 | CloseConsole() 15 | EndIf 16 | End 17 | ; IDE Options = PureBasic v4.00 (Windows - x86) 18 | ; EnableThread 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/284/284a.pb: -------------------------------------------------------------------------------- 1 | ; Remember to turn on 'Create threadsafe executable' in the compiler options! 2 | 3 | Global ConsoleAccess.l = CreateMutex() 4 | 5 | Procedure DrawNumbers(ThreadNumber.l) 6 | LockMutex(ConsoleAccess) 7 | ConsoleLocate(ThreadNumber * 20, 0) 8 | ConsoleColor((ThreadNumber + 1) * 3, 0) 9 | Print("Thread " + Str(ThreadNumber) + " locked.") 10 | For x.l = 1 To 20 11 | ConsoleLocate(ThreadNumber * 20, x + 1) 12 | Print(Str(x)) 13 | Delay(75) 14 | Next x 15 | UnlockMutex(ConsoleAccess) 16 | EndProcedure 17 | 18 | If OpenConsole() 19 | EnableGraphicalConsole(#True) 20 | Thread0.l = CreateThread(@DrawNumbers(), 0) 21 | Thread1.l = CreateThread(@DrawNumbers(), 1) 22 | Thread2.l = CreateThread(@DrawNumbers(), 2) 23 | WaitThread(Thread0) 24 | WaitThread(Thread1) 25 | WaitThread(Thread2) 26 | ConsoleLocate(0, 23) 27 | Print("Press Return to quit") : Input() 28 | CloseConsole() 29 | EndIf 30 | End 31 | ; IDE Options = PureBasic v4.02 (Windows - x86) 32 | ; EnableThread 33 | ; HideErrorLog -------------------------------------------------------------------------------- /code/285/285a.pb: -------------------------------------------------------------------------------- 1 | ; Remember to turn on 'Create threadsafe executable' in the compiler options! 2 | 3 | Enumeration 4 | #WINDOW_ROOT 5 | #TEXT_ONE 6 | #TEXT_TWO 7 | #TEXT_THREE 8 | #BUTTON_START 9 | EndEnumeration 10 | Global Lock.l = CreateMutex() 11 | 12 | Procedure Update(Gadget.l) 13 | StartTime.l = ElapsedMilliseconds() 14 | Repeat 15 | If TryLockMutex(Lock) 16 | For x.l = 1 To 20 17 | SetGadgetText(Gadget, Str(Gadget) + " has locked the mutex. " + Str(x)) 18 | Delay(250) 19 | Next x 20 | UnlockMutex(Lock) 21 | Break 22 | Else 23 | Time.s = "(" + Str((ElapsedMilliseconds() - StartTime) / 1000) + " Secs)" 24 | SetGadgetText(Gadget, Str(Gadget) + " is waiting for mutex. " + Time) 25 | Delay(1) 26 | EndIf 27 | ForEver 28 | SetGadgetText(Gadget, Str(Gadget) + " has finished.") 29 | EndProcedure 30 | 31 | #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 32 | If OpenWindow(#WINDOW_ROOT, 0, 0, 290, 130, "'TryLockMutex()' Test", #FLAGS) 33 | If CreateGadgetList(WindowID(#WINDOW_ROOT)) 34 | StringGadget(#TEXT_ONE, 10, 10, 270, 20, "") 35 | StringGadget(#TEXT_TWO, 10, 40, 270, 20, "") 36 | StringGadget(#TEXT_THREE, 10, 70, 270, 20, "") 37 | ButtonGadget(#BUTTON_START, 95, 100, 100, 20, "Start") 38 | Repeat 39 | EventID.l = WaitWindowEvent() 40 | Select EventID 41 | Case #PB_Event_Gadget 42 | Select EventGadget() 43 | Case #BUTTON_START 44 | Thread1.l = CreateThread(@Update(), #TEXT_ONE) 45 | Thread2.l = CreateThread(@Update(), #TEXT_TWO) 46 | Thread2.l = CreateThread(@Update(), #TEXT_THREE) 47 | EndSelect 48 | EndSelect 49 | Until EventID = #PB_Event_CloseWindow 50 | EndIf 51 | EndIf 52 | End 53 | ; IDE Options = PureBasic v4.02 (Windows - x86) 54 | ; EnableThread 55 | ; HideErrorLog -------------------------------------------------------------------------------- /code/288/288a.pb: -------------------------------------------------------------------------------- 1 | ProcedureDLL AttachProcess(Instance.l) 2 | Global Message.s = "This is my DLL." 3 | EndProcedure 4 | 5 | ProcedureDLL ShowAlert() 6 | MessageRequester("Alert", Message) 7 | EndProcedure 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/29/29a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 0 2 | NumberTwo.l = 1 3 | 4 | If NumberOne > NumberTwo 5 | Debug "1: NumberOne is more than NumberTwo" 6 | Else 7 | Debug "2: NumberTwo is more than NumberOne" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/29/29b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 0 2 | NumberTwo.l = 1 3 | 4 | If NumberOne <= NumberTwo 5 | Debug "1: NumberOne is less than or equal to NumberTwo" 6 | Else 7 | Debug "2: NumberOne is NOT less than or equal to NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/29/29c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 2 2 | NumberTwo.l = 1 3 | 4 | If NumberOne <= NumberTwo 5 | Debug "1: NumberOne is less than or equal to NumberTwo" 6 | Else 7 | Debug "2: NumberOne is NOT less than or equal to NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/290/290a.pb: -------------------------------------------------------------------------------- 1 | #LIBRARY_DEMO = 0 2 | If OpenLibrary(#LIBRARY_DEMO, "Demo.dll") 3 | CallFunction(#LIBRARY_DEMO, "ShowAlert") 4 | CloseLibrary(#LIBRARY_DEMO) 5 | EndIf 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/291/291a.pb: -------------------------------------------------------------------------------- 1 | ProcedureDLL.l MultiplyValues(x.l, y.l) 2 | ProcedureReturn x * y 3 | EndProcedure 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/291/291b.pb: -------------------------------------------------------------------------------- 1 | #LIBRARY = 0 2 | If OpenLibrary(#LIBRARY, "Demo.dll") 3 | ReturnValue.l = CallFunction(#LIBRARY, "MultiplyValues", 22, 33) 4 | Debug ReturnValue 5 | CloseLibrary(#LIBRARY) 6 | EndIf 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/291/291c.pb: -------------------------------------------------------------------------------- 1 | ProcedureDLL AttachProcess(Instance.l) 2 | Global MyString.s = "Lorem ipsum dolor sit amet." 3 | EndProcedure 4 | 5 | ProcedureDLL.s GetString() 6 | ProcedureReturn MyString 7 | EndProcedure 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/292/292a.pb: -------------------------------------------------------------------------------- 1 | #LIBRARY = 0 2 | If OpenLibrary(#LIBRARY, "Demo.dll") 3 | *ReturnValue = CallFunction(#LIBRARY, "GetString") 4 | Debug PeekS(*ReturnValue) 5 | CloseLibrary(#LIBRARY) 6 | EndIf 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/292/292b.pb: -------------------------------------------------------------------------------- 1 | ProcedureDLL AttachProcess(Instance.l) 2 | Global MyFloat.f = 3.1415927 3 | EndProcedure 4 | 5 | ProcedureDLL.l GetPi() 6 | ProcedureReturn @MyFloat 7 | EndProcedure 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/292/292c.pb: -------------------------------------------------------------------------------- 1 | #LIBRARY = 0 2 | If OpenLibrary(#LIBRARY, "Demo.dll") 3 | *ReturnValue = CallFunction(#LIBRARY, "GetPi") 4 | Debug PeekF(*ReturnValue) 5 | CloseLibrary(#LIBRARY) 6 | EndIf 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/294/294a.pb: -------------------------------------------------------------------------------- 1 | #LIBRARY = 0 2 | If OpenLibrary(#LIBRARY, "User32.dll") 3 | MB_OK = 0 4 | Caption.s = "Test" 5 | TextString.s = "This is a Win32 API Test" 6 | CallFunction(#LIBRARY, "MessageBoxA", #Null, @TextString, @Caption, MB_OK) 7 | CloseLibrary(#LIBRARY) 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/294/294b.pb: -------------------------------------------------------------------------------- 1 | MessageBox_(#Null, "This is a Win32 API Test", "Test", #MB_OK) 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/294/294c.pb: -------------------------------------------------------------------------------- 1 | TextString.s = "this is all lowercase text." 2 | CharUpper_(@TextString) 3 | Debug TextString 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/295/295a.pb: -------------------------------------------------------------------------------- 1 | DesktopInfo.RECT 2 | DesktopHandle.l = GetDesktopWindow_() 3 | GetClientRect_(DesktopHandle, @DesktopInfo) 4 | 5 | DesktopSize.s = "Your current desktop size is: " 6 | DesktopSize + Str(DesktopInfo\right) + " x " 7 | DesktopSize + Str(DesktopInfo\bottom) 8 | Debug DesktopSize 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/298/298a.pb: -------------------------------------------------------------------------------- 1 | DesktopInfo.RECT 2 | DesktopHandle.l = GetDesktopWindow_() 3 | GetClientRect_(DesktopHandle, @DesktopInfo) 4 | 5 | DesktopSize.s = "Your current desktop size is: " 6 | DesktopSize + Str(DesktopInfo\right) + " x " 7 | DesktopSize + Str(DesktopInfo\bottom) 8 | Debug DesktopSize 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/299/299a.pb: -------------------------------------------------------------------------------- 1 | ;Returns the correct unsigned value from a UCHAR. 2 | Procedure.w UCHAR(UCHAR.b) 3 | ProcedureReturn UCHAR & $FF 4 | EndProcedure 5 | 6 | ;Returns the correct signed value from a TBYTE. 7 | CompilerIf #PB_Compiler_Unicode 8 | Procedure.w TBYTE(TBYTE.c) 9 | CompilerElse 10 | Procedure.b TBYTE(TBYTE.c) 11 | CompilerEndIf 12 | ProcedureReturn TBYTE 13 | EndProcedure 14 | 15 | ;Returns the correct unsigned value from a USHORT. 16 | Procedure.l USHORT(USHORT.w) 17 | ProcedureReturn USHORT & $FFFF 18 | EndProcedure 19 | 20 | ;Returns the correct unsigned value from a UINT. 21 | Procedure.q UINT(UINT.l) 22 | ProcedureReturn UINT & $FFFFFFFF 23 | EndProcedure 24 | 25 | ;Returns the correct unsigned value from a UINT32. 26 | Procedure.q UINT32(UINT32.l) 27 | ProcedureReturn UINT32 & $FFFFFFFF 28 | EndProcedure 29 | 30 | ;Returns the correct unsigned value from a ULONG. 31 | Procedure.q ULONG(ULONG.l) 32 | ProcedureReturn ULONG & $FFFFFFFF 33 | EndProcedure 34 | 35 | ;Returns the correct unsigned value from a ULONG32. 36 | Procedure.q ULONG32(ULONG32.l) 37 | ProcedureReturn ULONG32 & $FFFFFFFF 38 | EndProcedure 39 | ; IDE Options = PureBasic v4.00 (Windows - x86) 40 | ; HideErrorLog -------------------------------------------------------------------------------- /code/30/30a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 2 2 | NumberTwo.l = 1 3 | 4 | If NumberOne >= NumberTwo 5 | Debug "1: NumberOne is more than or equal to NumberTwo" 6 | Else 7 | Debug "2: NumberOne is NOT more than or equal to NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/30/30b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 0 2 | NumberTwo.l = 1 3 | 4 | If NumberOne >= NumberTwo 5 | Debug "1: NumberOne is more than or equal to NumberTwo" 6 | Else 7 | Debug "2: NumberOne is NOT more than or equal to NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/30/30c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 0 2 | NumberTwo.l = 1 3 | 4 | If NumberOne <> NumberTwo 5 | Debug "1: NumberOne does not equal NumberTwo" 6 | Else 7 | Debug "2: NumberOne does equal NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/30/30d.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 1 2 | NumberTwo.l = 1 3 | 4 | If NumberOne <> NumberTwo 5 | Debug "1: NumberOne does not equal NumberTwo" 6 | Else 7 | Debug "2: NumberOne does equal NumberTwo" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/300/300a.pb: -------------------------------------------------------------------------------- 1 | ;Returns the correct unsigned value from a UCHAR. 2 | Procedure.w UCHAR(UCHAR.b) 3 | ProcedureReturn UCHAR & $FF 4 | EndProcedure 5 | 6 | MyUCHAR.b = 255 ; This represents '-1' signed and '255' unsigned. 7 | Debug MyUCHAR ; This echoes the signed value of '-1'. 8 | UnsignedValue.w = UCHAR(MyUCHAR) 9 | Debug UnsignedValue ; This echoes the unsigned value of '255'. 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/301/301a.pb: -------------------------------------------------------------------------------- 1 | MyUCHAR.b = 255 2 | Debug MyUCHAR 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/31/31a.pb: -------------------------------------------------------------------------------- 1 | One.l = 1 2 | Two.l = 2 3 | 4 | If Not One = 5 5 | Debug "1: One = 5 is evaluated as true (1)" 6 | Else 7 | Debug "2: One = 5 is evaluated as false (0)" 8 | EndIf 9 | 10 | If Not Two = 2 11 | Debug "1: Two = 2 is evaluated as true (1)" 12 | Else 13 | Debug "2: Two = 2 is evaluated as false (0)" 14 | EndIf 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/31/31b.pb: -------------------------------------------------------------------------------- 1 | One.l = 1 2 | Two.l = 2 3 | 4 | If Not One = 5 5 | Debug "1: One = 5 is evaluated as true (1)" 6 | Else 7 | Debug "2: One = 5 is evaluated as false (0)" 8 | EndIf 9 | 10 | If Not Two = 2 11 | Debug "1: Two = 2 is evaluated as true (1)" 12 | Else 13 | Debug "2: Two = 2 is evaluated as false (0)" 14 | EndIf 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/32/32a.pb: -------------------------------------------------------------------------------- 1 | StringOne.s = "The quick brown fox" 2 | NumberOne.l = 105 3 | 4 | If StringOne = "The quick brown fox" Or NumberOne = 100 5 | Debug "1: One or more expressions evaluate to true (1)" 6 | Else 7 | Debug "2: Both of the expressions evaluate as false (0)" 8 | EndIf 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/32/32b.pb: -------------------------------------------------------------------------------- 1 | StringOne.s = "The quick brown fox" 2 | NumberOne.l = 105 3 | If StringOne = "The quick brown fox" XOr NumberOne = 105 4 | Debug "1: Only one expression is true (1)" 5 | Else 6 | Debug "2: The expressions are either both true (1) or both false (0)" 7 | EndIf 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/33/33a.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 20 % 8 2 | Debug NumberOne 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/33/33b.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 2 * 5 + 3 2 | Debug NumberOne 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/33/33c.pb: -------------------------------------------------------------------------------- 1 | NumberOne.l = 2 * (5 + 3) 2 | Debug NumberOne 3 | ; IDE Options = PureBasic v4.00 (Windows - x86) 4 | ; HideErrorLog -------------------------------------------------------------------------------- /code/34/34a.pb: -------------------------------------------------------------------------------- 1 | Debug 3 + 10 * 2 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/34/34b.pb: -------------------------------------------------------------------------------- 1 | Debug (3 + 10) * 2 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/38/38a.pb: -------------------------------------------------------------------------------- 1 | a.l = 5 2 | If a = 5 3 | Debug "A true value was found" 4 | Else 5 | Debug "No true value was found" 6 | EndIf 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/39/39a.pb: -------------------------------------------------------------------------------- 1 | a.l = 5 2 | 3 | If a = 5 4 | Debug "A true value was found" 5 | EndIf 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/39/39b.pb: -------------------------------------------------------------------------------- 1 | Beads.l = 5 2 | 3 | If Beads 4 | Debug "The variable has a value" 5 | Else 6 | Debug "The variable does not have a value" 7 | EndIf 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/40/40a.pb: -------------------------------------------------------------------------------- 1 | Value1.l = 10 2 | Value2.l = 5 3 | Value3.l = 1 4 | 5 | If Value1 >= 10 And (Value2 / 5) = Value3 6 | Debug "The expression evaluates as true" 7 | Else 8 | Debug "The expression evaluates as false" 9 | EndIf 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/40/40b.pb: -------------------------------------------------------------------------------- 1 | NumberOfBeads.l = 10 2 | 3 | If NumberOfBeads < 5 4 | Debug "The variable has a value below '5'" 5 | ElseIf NumberOfBeads > 5 6 | Debug "The variable has a value above '5'" 7 | Else 8 | Debug "The variable has a value of '5'" 9 | EndIf 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/41/41a.pb: -------------------------------------------------------------------------------- 1 | Days.l = 2 2 | 3 | Select Days 4 | Case 0 5 | Debug "0 Days" 6 | Case 1 7 | Debug "1 Day" 8 | Case 2 9 | Debug "2 Days" 10 | Default 11 | Debug "Over 2 Days" 12 | EndSelect 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/41/41b.pb: -------------------------------------------------------------------------------- 1 | Weight.l = 12 2 | 3 | Select Weight 4 | Case 0 5 | Debug "No Weight" 6 | Case 1, 2, 3 7 | Debug "Light" 8 | Case 4 To 15 9 | Debug "Medium" 10 | Case 16 To 30 11 | Debug "Heavy" 12 | Default 13 | Debug "Massive" 14 | EndSelect 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/42/42a.pb: -------------------------------------------------------------------------------- 1 | If OpenConsole() 2 | PrintN("1. Official Purebasic Home") 3 | PrintN("2. Official Purebasic Forums") 4 | PrintN("3. PureArea.net") 5 | PrintN("") 6 | PrintN("Enter a number from 1 To 3 and press Return: ") 7 | Destination.s = Input() 8 | Select Destination 9 | Case "1" 10 | RunProgram("http://www.purebasic.com") 11 | Case "2" 12 | RunProgram("http://forums.purebasic.com") 13 | Case "3" 14 | RunProgram("http://www.purearea.net") 15 | EndSelect 16 | EndIf 17 | End 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/43/43a.pb: -------------------------------------------------------------------------------- 1 | For x.l = 1 To 10 2 | Debug x 3 | Next x 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/43/43b.pb: -------------------------------------------------------------------------------- 1 | Dim Names.s(3) 2 | 3 | Names(0) = "Gary" 4 | Names(1) = "Sara" 5 | Names(2) = "Stella" 6 | Names(3) = "MiniMunch" 7 | 8 | For x.l = 0 To 3 9 | Debug Names(x) 10 | Next x 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/44/44a.pb: -------------------------------------------------------------------------------- 1 | StartVar.l = 5 2 | StopVar.l = 10 3 | 4 | For x = StartVar - 4 To StopVar / 2 5 | Debug x 6 | Next x 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/44/44b.pb: -------------------------------------------------------------------------------- 1 | Dim Numbers.l(2, 2) 2 | 3 | Numbers(0, 0) = 1 4 | Numbers(0, 1) = 2 5 | Numbers(0, 2) = 3 6 | Numbers(1, 0) = 4 7 | Numbers(1, 1) = 5 8 | Numbers(1, 2) = 6 9 | Numbers(2, 0) = 7 10 | Numbers(2, 1) = 8 11 | Numbers(2, 2) = 9 12 | 13 | For x = 0 To 2 14 | For y = 0 To 2 15 | Debug Numbers(x, y) 16 | Next y 17 | Next x 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/44/44c.pb: -------------------------------------------------------------------------------- 1 | For x.l = 0 To 10 Step 2 2 | Debug x 3 | Next x 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/45/45a.pb: -------------------------------------------------------------------------------- 1 | NewList Shopping.s() 2 | 3 | AddElement(Shopping()) 4 | Shopping() = "Bunch of bananas" 5 | 6 | AddElement(Shopping()) 7 | Shopping() = "Tea bags" 8 | 9 | AddElement(Shopping()) 10 | Shopping() = "Cheese" 11 | 12 | ForEach Shopping() 13 | Debug Shopping() 14 | Next 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/45/45b.pb: -------------------------------------------------------------------------------- 1 | Monkeys.l = 0 2 | 3 | While Monkeys < 10 4 | Debug Monkeys 5 | Monkeys + 1 6 | Wend 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/46/46a.pb: -------------------------------------------------------------------------------- 1 | Monkeys.l = 20 2 | 3 | While Monkeys < 10 4 | Debug "This code is never executed" 5 | Wend 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/46/46b.pb: -------------------------------------------------------------------------------- 1 | Bananas.l = 0 2 | 3 | Repeat 4 | Debug Bananas 5 | Bananas + 1 6 | Until Bananas > 10 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/46/46c.pb: -------------------------------------------------------------------------------- 1 | Bananas.l = 20 2 | 3 | Repeat 4 | Debug Bananas 5 | Until Bananas > 10 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/47/47a.pb: -------------------------------------------------------------------------------- 1 | Counter.l = 0 2 | 3 | Repeat 4 | Debug Counter 5 | Counter + 1 6 | ForEver 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/47/47b.pb: -------------------------------------------------------------------------------- 1 | For x = 1 To 10 2 | If x = 5 3 | Break 4 | EndIf 5 | Debug x 6 | Next x 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/48/48a.pb: -------------------------------------------------------------------------------- 1 | For x.l = 1 To 10 2 | Counter = 0 3 | Repeat 4 | If x = 5 5 | Break 2 6 | EndIf 7 | Counter + 1 8 | Until Counter > 1 9 | Debug x 10 | Next 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/48/48b.pb: -------------------------------------------------------------------------------- 1 | For x.l = 1 To 10 2 | If x = 5 3 | Continue 4 | EndIf 5 | Debug x 6 | Next 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/49/49a.pb: -------------------------------------------------------------------------------- 1 | Structure PERSONALDETAILS 2 | FirstName.s 3 | LastName.s 4 | Home.s 5 | EndStructure 6 | 7 | Me.PERSONALDETAILS 8 | 9 | Me\FirstName = "Gary" 10 | Me\LastName = "Willoughby" 11 | Me\Home = "A House" 12 | 13 | Debug "First Name: " + Me\FirstName 14 | Debug "Last Name: " + Me\LastName 15 | Debug "Home: " + Me\Home 16 | ; IDE Options = PureBasic v4.00 (Windows - x86) 17 | ; HideErrorLog -------------------------------------------------------------------------------- /code/50/50a.pb: -------------------------------------------------------------------------------- 1 | Structure PERSONALDETAILS 2 | FirstName.s 3 | LastName.s 4 | Home.s 5 | EndStructure 6 | 7 | Me.PERSONALDETAILS 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/50/50b.pb: -------------------------------------------------------------------------------- 1 | Structure PERSONALDETAILS 2 | FirstName.s 3 | LastName.s 4 | Home.s 5 | EndStructure 6 | 7 | Father.PERSONALDETAILS 8 | Father\FirstName = "Peter" 9 | Debug Father\FirstName 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/50/50c.pb: -------------------------------------------------------------------------------- 1 | Structure PERSONALDETAILS 2 | FirstName.s 3 | LastName.s 4 | Home.s 5 | EndStructure 6 | Debug SizeOf(PERSONALDETAILS) 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/51/51a.pb: -------------------------------------------------------------------------------- 1 | Structure PERSONALDETAILS 2 | FirstName.s 3 | LastName.s 4 | Home.s 5 | EndStructure 6 | 7 | Structure FULLDETAILS Extends PERSONALDETAILS 8 | Address.s 9 | Country.s 10 | ZipCode.s 11 | EndStructure 12 | 13 | User.FULLDETAILS 14 | 15 | User\FirstName = "John" 16 | User\LastName = "Smith" 17 | User\Home = "A House" 18 | User\Address = "A Street" 19 | User\Country = "UK" 20 | User\ZipCode = "12345" 21 | 22 | Debug "Users First Name: " + User\FirstName 23 | Debug "Users Last Name: " + User\LastName 24 | Debug "Users Home: " + User\Home 25 | Debug "Users Address: " + User\Address 26 | Debug "Users Country: " + User\Country 27 | Debug "Users Zip Code: " + User\ZipCode 28 | ; IDE Options = PureBasic v4.00 (Windows - x86) 29 | ; HideErrorLog -------------------------------------------------------------------------------- /code/51/51b.pb: -------------------------------------------------------------------------------- 1 | Structure UNIONSTRUCTURE 2 | StructureUnion 3 | One.l 4 | Two.l 5 | Three.l 6 | EndStructureUnion 7 | EndStructure 8 | Debug SizeOf(UNIONSTRUCTURE) 9 | 10 | UnionVariable.UNIONSTRUCTURE 11 | 12 | UnionVariable\One = 123 13 | Debug UnionVariable\One 14 | 15 | UnionVariable\Three = 456 16 | Debug UnionVariable\One 17 | ; IDE Options = PureBasic v4.00 (Windows - x86) 18 | ; HideErrorLog -------------------------------------------------------------------------------- /code/52/52a.pb: -------------------------------------------------------------------------------- 1 | Dim LongArray.l(2) 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/53/53a.pb: -------------------------------------------------------------------------------- 1 | Dim LongArray.l(2) 2 | 3 | LongArray(0) = 10 4 | LongArray(1) = 25 5 | LongArray(2) = 30 6 | 7 | Debug LongArray(0) + LongArray(1) 8 | Debug LongArray(1) * LongArray(2) 9 | Debug LongArray(2) - LongArray(0) 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/53/53b.pb: -------------------------------------------------------------------------------- 1 | LastIndex.l = 2 2 | FirstIndex.l = 0 3 | Dim StringArray.s(LastIndex) 4 | 5 | StringArray(FirstIndex) = "One is one and all alone" 6 | StringArray(FirstIndex + 1) = "Two, two, the lily-white boys" 7 | StringArray(FirstIndex + 2) = "Three, three, the rivals" 8 | 9 | Debug StringArray(FirstIndex) 10 | Debug StringArray(FirstIndex + 1) 11 | Debug StringArray(FirstIndex + 2) 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/54/54a.pb: -------------------------------------------------------------------------------- 1 | Dim TestArray.l(999) 2 | 3 | For x = 0 To 999 4 | TestArray(x) = x 5 | Next x 6 | 7 | For x = 0 To 999 8 | Debug TestArray(x) 9 | Next x 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/54/54b.pb: -------------------------------------------------------------------------------- 1 | Dim Animals.s(2, 2) 2 | Animals(0, 0) = "Sheep" 3 | Animals(0, 1) = "4 Legs" 4 | Animals(0, 2) = "Baaa" 5 | 6 | Animals(1, 0) = "Cat" 7 | Animals(1, 1) = "4 Legs" 8 | Animals(1, 2) = "Meow" 9 | 10 | Animals(2, 0) = "Parrot" 11 | Animals(2, 1) = "2 Legs" 12 | Animals(2, 2) = "Screech" 13 | 14 | Debug Animals(0, 0) + " has " + Animals(0, 1) + " And says " + Animals(0, 2) 15 | Debug Animals(1, 0) + " has " + Animals(1, 1) + " And says " + Animals(1, 2) 16 | Debug Animals(2, 0) + " has " + Animals(2, 1) + " And says " + Animals(2, 2) 17 | ; IDE Options = PureBasic v4.00 (Windows - x86) 18 | ; HideErrorLog -------------------------------------------------------------------------------- /code/56/56a.pb: -------------------------------------------------------------------------------- 1 | Structure FISH 2 | Kind.s 3 | Weight.s 4 | Color.s 5 | EndStructure 6 | 7 | Dim FishInTank.FISH(2) 8 | 9 | FishInTank(0)\Kind = "Clown Fish" 10 | FishInTank(0)\Weight = "4 oz." 11 | FishInTank(0)\Color = "Red, White and Black" 12 | 13 | FishInTank(1)\Kind = "Box Fish" 14 | FishInTank(1)\Weight = "1 oz." 15 | FishInTank(1)\Color = "Yellow" 16 | 17 | FishInTank(2)\Kind = "Sea Horse" 18 | FishInTank(2)\Weight = "2 oz." 19 | FishInTank(2)\Color = "Green" 20 | 21 | Debug FishInTank(0)\Kind+" "+FishInTank(0)\Weight+" "+FishInTank(0)\Color 22 | Debug FishInTank(1)\Kind+" "+FishInTank(1)\Weight+" "+FishInTank(1)\Color 23 | Debug FishInTank(2)\Kind+" "+FishInTank(2)\Weight+" "+FishInTank(2)\Color 24 | ; IDE Options = PureBasic v4.00 (Windows - x86) 25 | ; HideErrorLog -------------------------------------------------------------------------------- /code/58/58a.pb: -------------------------------------------------------------------------------- 1 | Structure FISH 2 | Kind.s 3 | Weight.s 4 | Color.s 5 | EndStructure 6 | 7 | Dim FishInTank.FISH(2, 2) 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/59/59a.pb: -------------------------------------------------------------------------------- 1 | Dim Dogs.s(2) 2 | 3 | Dogs(0) = "Jack Russell" 4 | Dogs(1) = "Alaskan Husky" 5 | Dogs(2) = "Border Collie" 6 | 7 | Debug Dogs(0) 8 | Debug Dogs(1) 9 | Debug Dogs(2) 10 | 11 | Dim Dogs.s(2) 12 | 13 | Debug Dogs(0) 14 | Debug Dogs(1) 15 | Debug Dogs(2) 16 | ; IDE Options = PureBasic v4.00 (Windows - x86) 17 | ; HideErrorLog -------------------------------------------------------------------------------- /code/60/60a.pb: -------------------------------------------------------------------------------- 1 | Dim Dogs.s(2) 2 | 3 | Dogs(0) = "Jack Russell" 4 | Dogs(1) = "Alaskan Husky" 5 | Dogs(2) = "Border Collie" 6 | 7 | For x.l = 0 To 2 8 | Debug Dogs(x) 9 | Next x 10 | 11 | Debug "" 12 | 13 | ReDim Dogs.s(4) 14 | 15 | Dogs(3) = "Yorkshire Terrier" 16 | Dogs(4) = "Greyhound" 17 | 18 | For x.l = 0 To 4 19 | Debug Dogs(x) 20 | Next x 21 | ; IDE Options = PureBasic v4.00 (Windows - x86) 22 | ; HideErrorLog -------------------------------------------------------------------------------- /code/61/61a.pb: -------------------------------------------------------------------------------- 1 | Structure FAMILY 2 | Father.s 3 | Mother.s 4 | Children.s[2] 5 | Surname.s 6 | EndStructure 7 | 8 | Family.FAMILY 9 | 10 | Family\Father = "Peter" 11 | Family\Mother = "Sarah" 12 | Family\Children[0] = "John" 13 | Family\Children[1] = "Jane" 14 | Family\Surname = "Smith" 15 | 16 | Debug "Family Members:" 17 | Debug Family\Father + " " + Family\Surname 18 | Debug Family\Mother + " " + Family\Surname 19 | Debug Family\Children[0] + " " + Family\Surname 20 | Debug Family\Children[1] + " " + Family\Surname 21 | ; IDE Options = PureBasic v4.00 (Windows - x86) 22 | ; HideErrorLog -------------------------------------------------------------------------------- /code/62/62a.pb: -------------------------------------------------------------------------------- 1 | Structure EMPLOYEES 2 | EmployeeName.s 3 | EmployeeClockNumber.l 4 | EmployeeAddress.s 5 | EmployeeContactNumbers.l[2] 6 | EndStructure 7 | 8 | Dim Company.EMPLOYEES(9) 9 | 10 | Company(0)\EmployeeName = "Bruce Dickinson" 11 | Company(0)\EmployeeClockNumber = 666 12 | Company(0)\EmployeeAddress = "22 Acacia Avenue" 13 | Company(0)\EmployeeContactNumbers[0] = 0776032666 14 | Company(0)\EmployeeContactNumbers[1] = 0205467746 15 | 16 | Company(1)\EmployeeName = "Adrian Smith" 17 | Company(1)\EmployeeClockNumber = 1158 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/63/63a.pb: -------------------------------------------------------------------------------- 1 | NewList Fruit.s() 2 | ; IDE Options = PureBasic v4.00 (Windows - x86) 3 | ; HideErrorLog -------------------------------------------------------------------------------- /code/63/63b.pb: -------------------------------------------------------------------------------- 1 | NewList Fruit.s() 2 | 3 | AddElement(Fruit()) 4 | Fruit() = "Banana" 5 | 6 | AddElement(Fruit()) 7 | Fruit() = "Apple" 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/64/64a.pb: -------------------------------------------------------------------------------- 1 | NewList Fruit.s() 2 | 3 | AddElement(Fruit()) 4 | Fruit() = "Banana" 5 | 6 | AddElement(Fruit()) 7 | Fruit() = "Apple" 8 | 9 | AddElement(Fruit()) 10 | Fruit() = "Pear" 11 | 12 | AddElement(Fruit()) 13 | Fruit() = "Orange" 14 | 15 | ForEach Fruit() 16 | Debug Fruit() 17 | Next 18 | ; IDE Options = PureBasic v4.00 (Windows - x86) 19 | ; HideErrorLog -------------------------------------------------------------------------------- /code/65/65a.pb: -------------------------------------------------------------------------------- 1 | Structure FISH 2 | Kind.s 3 | Weight.s 4 | Color.s 5 | EndStructure 6 | 7 | NewList FishInTank.FISH() 8 | AddElement(FishInTank()) 9 | FishInTank()\Kind = "Clown Fish" 10 | FishInTank()\Weight = "4 oz." 11 | FishInTank()\Color = "Red, White and Black" 12 | 13 | AddElement(FishInTank()) 14 | FishInTank()\Kind = "Box Fish" 15 | FishInTank()\Weight = "1 oz." 16 | FishInTank()\Color = "Yellow" 17 | 18 | AddElement(FishInTank()) 19 | FishInTank()\Kind = "Sea Horse" 20 | FishInTank()\Weight = "2 oz." 21 | FishInTank()\Color = "Green" 22 | 23 | ForEach FishInTank() 24 | Debug FishInTank()\Kind+" "+FishInTank()\Weight+" "+FishInTank()\Color 25 | Next 26 | ; IDE Options = PureBasic v4.00 (Windows - x86) 27 | ; HideErrorLog -------------------------------------------------------------------------------- /code/67/67a.pb: -------------------------------------------------------------------------------- 1 | Dim Fruit.s(3) 2 | 3 | Fruit(0) = "Banana" 4 | Fruit(1) = "Apple" 5 | Fruit(2) = "Pear" 6 | Fruit(3) = "Orange" 7 | SortArray(Fruit(), 0) 8 | 9 | For x.l = 0 To 3 10 | Debug Fruit(x) 11 | Next x 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/68/68a.pb: -------------------------------------------------------------------------------- 1 | Structure WEAPON 2 | Name.s 3 | Range.l 4 | EndStructure 5 | 6 | Dim Weapons.WEAPON(2) 7 | 8 | Weapons(0)\Name = "Phased Plasma Rifle" 9 | Weapons(0)\Range = 40 10 | 11 | Weapons(1)\Name = "SVD-Dragunov Sniper Rifle" 12 | Weapons(1)\Range = 3800 13 | 14 | Weapons(2)\Name = "HK-MP5 Sub-Machine Gun" 15 | Weapons(2)\Range = 300 16 | SortStructuredArray(Weapons(), 0, OffsetOf(WEAPON\Range), #PB_Sort_Long) 17 | 18 | For x.l = 0 To 2 19 | Debug Weapons(x)\Name + " : " + Str(Weapons(x)\Range) 20 | Next x 21 | ; IDE Options = PureBasic v4.00 (Windows - x86) 22 | ; HideErrorLog -------------------------------------------------------------------------------- /code/69/69a.pb: -------------------------------------------------------------------------------- 1 | NewList Fruit.s() 2 | 3 | AddElement(Fruit()) 4 | Fruit() = "Banana" 5 | 6 | AddElement(Fruit()) 7 | Fruit() = "Apple" 8 | 9 | AddElement(Fruit()) 10 | Fruit() = "Orange" 11 | 12 | SortList(Fruit(), 0) 13 | 14 | ForEach Fruit() 15 | Debug Fruit() 16 | Next 17 | ; IDE Options = PureBasic v4.00 (Windows - x86) 18 | ; HideErrorLog -------------------------------------------------------------------------------- /code/70/70a.pb: -------------------------------------------------------------------------------- 1 | Structure GIRL 2 | Name.s 3 | Weight.s 4 | EndStructure 5 | 6 | NewList Girls.GIRL() 7 | 8 | AddElement(Girls()) 9 | Girls()\Name = "Mia" 10 | Girls()\Weight = "8.5 Stone" 11 | 12 | AddElement(Girls()) 13 | Girls()\Name = "Big Rosie" 14 | Girls()\Weight = "19 stone" 15 | 16 | AddElement(Girls()) 17 | Girls()\Name = "Sara" 18 | Girls()\Weight = "10 Stone" 19 | 20 | SortStructuredList(Girls(), 0, OffsetOf(GIRL\Name), #PB_Sort_String) 21 | 22 | ForEach Girls() 23 | Debug Girls()\Name + " : " + Girls()\Weight 24 | Next 25 | ; IDE Options = PureBasic v4.00 (Windows - x86) 26 | ; HideErrorLog -------------------------------------------------------------------------------- /code/72/72a.pb: -------------------------------------------------------------------------------- 1 | a.l = 10 2 | 3 | Debug a 4 | Gosub Calculation 5 | Debug a 6 | End 7 | 8 | Calculation: 9 | a = a * 5 + 5 10 | Return 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/73/73a.pb: -------------------------------------------------------------------------------- 1 | a.l = 10 2 | 3 | Debug a 4 | Gosub Calculation 5 | Debug a 6 | End 7 | 8 | RunAgain: 9 | a.l = 20 10 | Debug a 11 | Gosub Calculation 12 | Debug a 13 | End 14 | 15 | Calculation: 16 | If a = 10 17 | FakeReturn 18 | Goto RunAgain 19 | Else 20 | a = a * 5 + 5 21 | EndIf 22 | Return 23 | ; IDE Options = PureBasic v4.00 (Windows - x86) 24 | ; HideErrorLog -------------------------------------------------------------------------------- /code/74/74a.pb: -------------------------------------------------------------------------------- 1 | Procedure NurseryRhyme() 2 | Debug "Mary had a little lamb, its fleece was white as snow." 3 | Debug "And everywhere that Mary went, that lamb was sure to go." 4 | EndProcedure 5 | 6 | NurseryRhyme() 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/75/75a.pb: -------------------------------------------------------------------------------- 1 | Procedure NurseryRhyme() 2 | Debug "Mary had a little lamb, its fleece was white as snow." 3 | Debug "And everywhere that Mary went, that lamb was sure to go." 4 | EndProcedure 5 | 6 | For x.l = 1 To 5 7 | NurseryRhyme() 8 | Next x 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/75/75b.pb: -------------------------------------------------------------------------------- 1 | Procedure NurseryRhyme2() 2 | Debug "And everywhere that Mary went, that lamb was sure to go." 3 | EndProcedure 4 | 5 | Procedure NurseryRhyme1() 6 | Debug "Mary had a little lamb, its fleece was white as snow." 7 | NurseryRhyme2() 8 | EndProcedure 9 | 10 | NurseryRhyme1() 11 | ; IDE Options = PureBasic v4.00 (Windows - x86) 12 | ; HideErrorLog -------------------------------------------------------------------------------- /code/75/75c.pb: -------------------------------------------------------------------------------- 1 | Declare NurseryRhyme1() 2 | Declare NurseryRhyme2() 3 | 4 | NurseryRhyme1() 5 | 6 | Procedure NurseryRhyme1() 7 | Debug "Mary had a little lamb, its fleece was white as snow." 8 | NurseryRhyme2() 9 | EndProcedure 10 | 11 | Procedure NurseryRhyme2() 12 | Debug "And everywhere that Mary went, that lamb was sure to go." 13 | EndProcedure 14 | ; IDE Options = PureBasic v4.00 (Windows - x86) 15 | ; HideErrorLog -------------------------------------------------------------------------------- /code/76/76a.pb: -------------------------------------------------------------------------------- 1 | a.l = 10 2 | 3 | Procedure DisplayValue() 4 | Debug a 5 | EndProcedure 6 | 7 | DisplayValue() 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/77/77a.pb: -------------------------------------------------------------------------------- 1 | Global a.l = 10 2 | 3 | Procedure DisplayValue() 4 | Debug a 5 | EndProcedure 6 | 7 | DisplayValue() 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/77/77b.pb: -------------------------------------------------------------------------------- 1 | Procedure DisplayValue() 2 | a.l = 10 3 | EndProcedure 4 | 5 | DisplayValue() 6 | 7 | Debug a 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/77/77c.pb: -------------------------------------------------------------------------------- 1 | Procedure DisplayValue() 2 | Global a.l = 10 3 | EndProcedure 4 | 5 | DisplayValue() 6 | 7 | Debug a 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/78/78a.pb: -------------------------------------------------------------------------------- 1 | Global a.l = 10 2 | 3 | Procedure DisplayValue() 4 | Debug a 5 | EndProcedure 6 | 7 | DisplayValue() 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/78/78b.pb: -------------------------------------------------------------------------------- 1 | Global Dim Numbers.l(1) 2 | 3 | Procedure ChangeValues() 4 | Numbers(0) = 3 5 | Numbers(1) = 4 6 | EndProcedure 7 | 8 | ChangeValues() 9 | 10 | Debug Numbers(0) 11 | Debug Numbers(1) 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/79/79a.pb: -------------------------------------------------------------------------------- 1 | Global NewList Numbers.l() 2 | 3 | AddElement(Numbers()) 4 | Numbers() = 1 5 | 6 | Procedure ChangeValue() 7 | SelectElement(Numbers(), 1) 8 | Numbers() = 100 9 | EndProcedure 10 | 11 | ChangeValue() 12 | 13 | SelectElement(Numbers(), 1) 14 | Debug Numbers() 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/79/79b.pb: -------------------------------------------------------------------------------- 1 | Global a.l = 10 2 | 3 | Procedure ChangeValue() 4 | Protected a.l = 20 5 | EndProcedure 6 | 7 | ChangeValue() 8 | 9 | Debug a 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/80/80a.pb: -------------------------------------------------------------------------------- 1 | Global Dim Numbers.l(1) 2 | 3 | Procedure ChangeValues() 4 | Protected Dim Numbers.l(1) 5 | Numbers(0) = 3 6 | Numbers(1) = 4 7 | EndProcedure 8 | 9 | ChangeValues() 10 | 11 | Debug Numbers(0) 12 | Debug Numbers(1) 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/80/80b.pb: -------------------------------------------------------------------------------- 1 | Global NewList Numbers.l() 2 | AddElement(Numbers()) 3 | Numbers() = 1 4 | 5 | Procedure ChangeValue() 6 | Protected NewList Numbers.l() 7 | AddElement(Numbers()) 8 | Numbers() = 100 9 | EndProcedure 10 | 11 | ChangeValue() 12 | SelectElement(Numbers(), 1) 13 | Debug Numbers() 14 | ; IDE Options = PureBasic v4.00 (Windows - x86) 15 | ; HideErrorLog -------------------------------------------------------------------------------- /code/81/81a.pb: -------------------------------------------------------------------------------- 1 | a.l = 10 2 | 3 | Procedure ChangeValue() 4 | Shared a 5 | a = 50 6 | EndProcedure 7 | 8 | ChangeValue() 9 | Debug a 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/81/81b.pb: -------------------------------------------------------------------------------- 1 | Dim Numbers.l(1) 2 | 3 | Procedure ChangeValues() 4 | Shared Numbers() 5 | Numbers(0) = 3 6 | Numbers(1) = 4 7 | EndProcedure 8 | 9 | ChangeValues() 10 | 11 | Debug Numbers(0) 12 | Debug Numbers(1) 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/81/81c.pb: -------------------------------------------------------------------------------- 1 | NewList Numbers.l() 2 | 3 | Procedure ChangeValue() 4 | Shared Numbers() 5 | AddElement(Numbers()) 6 | Numbers() = 100 7 | EndProcedure 8 | 9 | ChangeValue() 10 | 11 | SelectElement(Numbers(), 1) 12 | Debug Numbers() 13 | ; IDE Options = PureBasic v4.00 (Windows - x86) 14 | ; HideErrorLog -------------------------------------------------------------------------------- /code/82/82a.pb: -------------------------------------------------------------------------------- 1 | Procedure ChangeValue() 2 | Static a.l 3 | a + 1 4 | Debug a 5 | EndProcedure 6 | 7 | For x.l = 1 To 5 8 | ChangeValue() 9 | Next x 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/82/82b.pb: -------------------------------------------------------------------------------- 1 | Procedure ChangeValue() 2 | Static Dim Numbers.l(1) 3 | Numbers(0) + 1 4 | Numbers(1) + 1 5 | Debug Numbers(0) 6 | Debug Numbers(1) 7 | EndProcedure 8 | 9 | For x.l = 1 To 5 10 | ChangeValue() 11 | Next x 12 | ; IDE Options = PureBasic v4.00 (Windows - x86) 13 | ; HideErrorLog -------------------------------------------------------------------------------- /code/83/83a.pb: -------------------------------------------------------------------------------- 1 | Procedure ChangeValue() 2 | Static NewList Numbers.l() 3 | If CountList(Numbers()) = 0 4 | AddElement(Numbers()) 5 | EndIf 6 | SelectElement(Numbers(), 1) 7 | Numbers() + 1 8 | Debug Numbers() 9 | EndProcedure 10 | 11 | For x.l = 1 To 5 12 | ChangeValue() 13 | Next x 14 | ; IDE Options = PureBasic v4.00 (Windows - x86) 15 | ; HideErrorLog -------------------------------------------------------------------------------- /code/83/83b.pb: -------------------------------------------------------------------------------- 1 | Procedure AddTogether(a.l, b.l) 2 | Debug a + b 3 | EndProcedure 4 | 5 | AddTogether(10, 5) 6 | AddTogether(7, 7) 7 | AddTogether(50, 50) 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/84/84a.pb: -------------------------------------------------------------------------------- 1 | Procedure JoinString(a.s, b.s) 2 | Debug a + b 3 | EndProcedure 4 | 5 | JoinString("Mary had a little lamb, ", "its fleece was white as snow.") 6 | JoinString("And everywhere that Mary went, ", "that lamb was sure to go.") 7 | JoinString("..", "..") 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/84/84b.pb: -------------------------------------------------------------------------------- 1 | Procedure LotsOfTypes(a.b, b.w, c.l, d.f, e.s) 2 | Debug "Byte: " + Str(a) 3 | Debug "Word: " + Str(b) 4 | Debug "Long: " + Str(c) 5 | Debug "Float: " + StrF(d) 6 | Debug "String: " + e 7 | EndProcedure 8 | 9 | LotsOfTypes(104, 21674, 97987897, 3.141590, "Mary had a little lamb") 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/85/85a.pb: -------------------------------------------------------------------------------- 1 | Procedure DisplayParameters(a.l, b.l, c.l = 3) 2 | Debug a 3 | Debug b 4 | Debug c 5 | EndProcedure 6 | 7 | DisplayParameters(1, 2) 8 | ; IDE Options = PureBasic v4.00 (Windows - x86) 9 | ; HideErrorLog -------------------------------------------------------------------------------- /code/86/86a.pb: -------------------------------------------------------------------------------- 1 | Dim Countries.s(3) 2 | 3 | Countries(0) = "England" 4 | Countries(1) = "Northern Ireland" 5 | Countries(2) = "Scotland" 6 | Countries(3) = "Wales" 7 | 8 | Procedure EchoArray(MyArray.s(1)) 9 | For x.l = 0 To 3 10 | Debug MyArray(x) 11 | Next x 12 | EndProcedure 13 | 14 | EchoArray(Countries()) 15 | ; IDE Options = PureBasic v4.00 (Windows - x86) 16 | ; HideErrorLog -------------------------------------------------------------------------------- /code/87/87a.pb: -------------------------------------------------------------------------------- 1 | Dim Countries.s(3, 1) 2 | 3 | Countries(0,0) = "England" 4 | Countries(0,1) = "57,000,000" 5 | 6 | Countries(1, 0) = "Northern Ireland" 7 | Countries(1,1) = "2,000,000" 8 | 9 | Countries(2, 0) = "Scotland" 10 | Countries(2,1) = "5,200,000" 11 | 12 | Countries(3, 0) = "Wales" 13 | Countries(3,1) = "3,100,000" 14 | 15 | Procedure EchoArray(MyArray.s(2)) 16 | For x.l = 0 To 3 17 | Debug MyArray(x,0) + " - " + "Population: " + MyArray(x,1) 18 | Next x 19 | EndProcedure 20 | 21 | EchoArray(Countries()) 22 | ; IDE Options = PureBasic v4.00 (Windows - x86) 23 | ; HideErrorLog -------------------------------------------------------------------------------- /code/88/88a.pb: -------------------------------------------------------------------------------- 1 | Structure COUNTRY 2 | Name.s 3 | Population.s 4 | EndStructure 5 | 6 | Dim Countries.COUNTRY(3) 7 | 8 | Countries(0)\Name = "England" 9 | Countries(0)\Population = "57,000,000" 10 | 11 | Countries(1)\Name = "Northern Ireland" 12 | Countries(1)\Population = "2,000,000" 13 | 14 | Countries(2)\Name = "Scotland" 15 | Countries(2)\Population = "5,200,000" 16 | 17 | Countries(3)\Name = "Wales" 18 | Countries(3)\Population = "3,100,000" 19 | 20 | Procedure EchoArray(MyArray.COUNTRY(1)) 21 | For x.l = 0 To 3 22 | Debug MyArray(x)\Name + " - " + "Population: " + MyArray(x)\Population 23 | Next x 24 | EndProcedure 25 | 26 | EchoArray(Countries()) 27 | ; IDE Options = PureBasic v4.00 (Windows - x86) 28 | ; HideErrorLog -------------------------------------------------------------------------------- /code/89/89a.pb: -------------------------------------------------------------------------------- 1 | NewList Numbers.l() 2 | 3 | AddElement(Numbers()) 4 | Numbers() = 25 5 | 6 | AddElement(Numbers()) 7 | Numbers() = 50 8 | 9 | AddElement(Numbers()) 10 | Numbers() = 75 11 | 12 | Procedure EchoList(MyList.l()) 13 | ForEach MyList() 14 | Debug MyList() 15 | Next 16 | EndProcedure 17 | 18 | EchoList(Numbers()) 19 | ; IDE Options = PureBasic v4.00 (Windows - x86) 20 | ; HideErrorLog -------------------------------------------------------------------------------- /code/89/89b.pb: -------------------------------------------------------------------------------- 1 | Structure FLAGS 2 | Country.s 3 | Flag.s 4 | EndStructure 5 | 6 | NewList Info.FLAGS() 7 | 8 | AddElement(Info()) 9 | Info()\Country = "Great Britain" 10 | Info()\Flag = "Union Jack" 11 | 12 | AddElement(Info()) 13 | Info()\Country = "USA" 14 | Info()\Flag = "Stars And Stripes" 15 | 16 | AddElement(Info()) 17 | Info()\Country = "France" 18 | Info()\Flag = "Tricolore" 19 | 20 | Procedure EchoList(MyList.FLAGS()) 21 | ForEach MyList() 22 | Debug MyList()\Country + "'s flag is the " + MyList()\Flag 23 | Next 24 | EndProcedure 25 | 26 | EchoList(Info()) 27 | ; IDE Options = PureBasic v4.00 (Windows - x86) 28 | ; HideErrorLog -------------------------------------------------------------------------------- /code/91/91a.pb: -------------------------------------------------------------------------------- 1 | Procedure.l AddTogether(a.l, b.l) 2 | ProcedureReturn a + b 3 | EndProcedure 4 | 5 | Debug AddTogether(7, 5) 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/91/91b.pb: -------------------------------------------------------------------------------- 1 | Procedure.s JoinString(a.s, b.s) 2 | ProcedureReturn a + b 3 | EndProcedure 4 | 5 | Debug JoinString("Red ", "Lorry") 6 | Debug JoinString("Yellow ", "Lorry") 7 | ; IDE Options = PureBasic v4.00 (Windows - x86) 8 | ; HideErrorLog -------------------------------------------------------------------------------- /code/92/92a.pb: -------------------------------------------------------------------------------- 1 | Procedure.l AddTogether(a.l, b.l) 2 | ProcedureReturn a + b 3 | EndProcedure 4 | 5 | Debug AddTogether(AddTogether(2, 3), AddTogether(4, 1)) 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/92/92b.pb: -------------------------------------------------------------------------------- 1 | Procedure.s DisplayValue(a.l, b.s) 2 | ProcedureReturn Str(a) + b 3 | EndProcedure 4 | 5 | x = 5 6 | While x >= 0 7 | Debug DisplayValue(x, " green bottles hanging on the wall.") 8 | x - 1 9 | Wend 10 | ; IDE Options = PureBasic v4.00 (Windows - x86) 11 | ; HideErrorLog -------------------------------------------------------------------------------- /code/96/96a.pb: -------------------------------------------------------------------------------- 1 | Enumeration 2 | #IMAGE_DOG 3 | #IMAGE_CAT 4 | #IMAGE_BIRD 5 | EndEnumeration 6 | CreateImage(#IMAGE_DOG, 100, 100) 7 | CreateImage(#IMAGE_CAT, 250, 300) 8 | CreateImage(#IMAGE_BIRD, 450, 115) 9 | ; IDE Options = PureBasic v4.00 (Windows - x86) 10 | ; HideErrorLog -------------------------------------------------------------------------------- /code/98/98a.pb: -------------------------------------------------------------------------------- 1 | Text.s = "This is a test" 2 | 3 | For x.l = 1 To Len(Text) 4 | Debug Mid(Text, x, 1) + " : " + Str(Asc(Mid(Text, x, 1))) 5 | Next x 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/99/99a.pb: -------------------------------------------------------------------------------- 1 | Text.s = Chr(84) + Chr(104) + Chr(105) + Chr(115) + Chr(32) 2 | Text.s + Chr(105) + Chr(115) + Chr(32) 3 | Text.s + Chr(97) + Chr(32) 4 | Text.s + Chr(116) + Chr(101) + Chr(115) + Chr(116) 5 | Debug Text 6 | ; IDE Options = PureBasic v4.00 (Windows - x86) 7 | ; HideErrorLog -------------------------------------------------------------------------------- /code/99/99b.pb: -------------------------------------------------------------------------------- 1 | Debug "Start..." 2 | Delay(5000) 3 | Debug "This is executed 5 seconds later" 4 | ; IDE Options = PureBasic v4.00 (Windows - x86) 5 | ; HideErrorLog -------------------------------------------------------------------------------- /code/99/99c.pb: -------------------------------------------------------------------------------- 1 | Debug "Start..." 2 | StartTime.l = ElapsedMilliseconds() 3 | Delay(5000) 4 | Debug "Delayed for "+Str(ElapsedMilliseconds() - StartTime)+" milliseconds." 5 | ; IDE Options = PureBasic v4.00 (Windows - x86) 6 | ; HideErrorLog -------------------------------------------------------------------------------- /pdf/PureBasic - A Beginners Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/pdf/PureBasic - A Beginners Guide.pdf -------------------------------------------------------------------------------- /quarkxpress/book.qxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/book.qxd -------------------------------------------------------------------------------- /quarkxpress/images/Back Cover (7.5 x 9.25).eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/Back Cover (7.5 x 9.25).eps -------------------------------------------------------------------------------- /quarkxpress/images/Front Cover (7.5 x 9.25).eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/Front Cover (7.5 x 9.25).eps -------------------------------------------------------------------------------- /quarkxpress/images/Gary.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/Gary.tif -------------------------------------------------------------------------------- /quarkxpress/images/InnerTitle.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/InnerTitle.eps -------------------------------------------------------------------------------- /quarkxpress/images/SectionBacker.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/SectionBacker.eps -------------------------------------------------------------------------------- /quarkxpress/images/cc-logo.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/cc-logo.tif -------------------------------------------------------------------------------- /quarkxpress/images/fig1.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig1.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig10.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig10.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig11.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig11.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig12.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig12.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig13.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig13.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig14.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig14.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig15.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig15.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig16.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig16.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig17.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig17.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig18.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig18.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig19.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig19.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig2.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig2.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig20.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig20.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig21.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig21.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig22.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig22.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig23.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig23.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig24.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig24.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig25.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig25.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig26.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig26.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig27.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig27.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig28.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig28.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig29.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig29.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig3.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig3.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig30.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig30.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig31.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig31.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig32.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig32.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig33.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig33.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig34.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig34.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig35.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig35.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig36.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig36.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig37.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig37.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig38.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig38.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig39.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig39.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig4.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig4.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig40.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig40.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig41.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig41.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig42.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig42.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig43.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig43.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig44.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig44.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig45.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig45.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig46.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig46.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig47.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig47.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig48.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig48.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig49.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig49.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig5.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig5.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig50.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig50.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig51.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig51.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig52.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig52.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig53.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig53.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig54.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig54.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig55.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig55.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig56.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig56.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig6.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig6.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig7.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig7.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig8.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig8.eps -------------------------------------------------------------------------------- /quarkxpress/images/fig9.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/purebasic-a-beginners-guide/f0098ee8ef336357c718f69610c79457c608a46e/quarkxpress/images/fig9.eps -------------------------------------------------------------------------------- /text/About The Author.txt: -------------------------------------------------------------------------------- 1 | <> 2 | 3 | About The Author 4 | 5 | Gary Willoughby is a professional graphic artist, Internet web developer and software developer. Having first cut his teeth programming using interpreted languages such as PHP, Python and Javascript during the late nineties, Gary decided to spend his free time moving into application development using compiled languages. 6 | 7 | After using C++ for a while and noticing the massive marathon of programming needed for even a simple piece of software, a search began for a simpler, more intuitive and elegant programming language to realize well designed software within a shorter time frame. All of these wishes were fulfilled by a little known French company called Fantaisie Software. The programming language they developed and marketed was PureBasic. 8 | 9 | Since the summer of 2002, Gary has been an active community member of the official online PureBasic forum (under the pseudonym of 'Kale' and has written several pieces of successful commercial software using PureBasic. 10 | -------------------------------------------------------------------------------- /text/Appendix A.txt: -------------------------------------------------------------------------------- 1 | A 2 | 3 | Useful Internet Links 4 | 5 | The following pages contain many useful web address from the Internet that you will want to take a look at when starting out with PureBasic. These websites contain lots of useful information, such as code snippets, tool and utilities, where to get technical support and where to ask questions. 6 | 7 | PureBasic Beginners 8 | http://www.pb-beginners.co.uk 9 | The website associated to this book. Most of the code, images and sounds used in the examples contained in this book can be downloaded from this website along with other useful tools and utilities, including the elusive �Win32.hlp� help file. 10 | 11 | Official PureBasic Website 12 | http://www.purebasic.com 13 | The official website of PureBasic. This is where you buy and download the full PureBasic package. You can also find the latest development news on PureBasic and access support via the website's menu. 14 | 15 | Official PureBasic Forums 16 | http://forums.purebasic.com 17 | Hopefully this will be one of your first stops when using PureBasic. All you need to do is register with the forum and you can ask as many questions as you like. This online forum is monitored closely by the PureBasic team who regularly contribute to discussions and answer questions relating to PureBasic. The wealth of information regarding PureBasic stored on this site should not be underestimated. Not only do you have access to the shared knowledge of hundreds of PureBasic programmers willing to help you, but every post is archived and fully searchable, meaning you literally have years worth of PureBasic knowledge at your fingertips detailing almost any programming task you may encounter. 18 | 19 | PureArea 20 | http://www.purearea.net 21 | This site contains lots of PureBasic related material including, thousands of PureBasic code examples contained in the downloadable Code Archive, downloadable third party user libraries and links to hundreds of freeware and shareware utilities written in PureBasic. There is also an online PureBasic reference manual. 22 | 23 | The PureBasic Visual Designer 24 | http://www.purebasic.be 25 | This site contains news and updated builds of the new official PureBasic visual designer. Everything to do with the development of the visual designer is contained on this site. 26 | 27 | PureProject 28 | http://pureproject.reelmedia.org 29 | More PureBasic code snippets including games and applications and more downloadable third party user libraries. There�s also a Windows API section too. 30 | 31 | PureVision 32 | http://purevision.reelmedia.org 33 | A third party commercial replacement for the standard PureBasic visual designer. This professional visual designer also has full support for GUI skinning. 34 | 35 | Microsoft Windows API Documentation 36 | http://msdn.microsoft.com/library 37 | Microsoft's Windows API website detailing all the Windows Application Programming Interface. Use the search box on the webpage to quickly find information. 38 | 39 | API-Guide 40 | http://www.allapi.net/agnet/apiguide.shtml 41 | A program called 'API-Guide' that allows you to explore the commands available in the Win32 API. Details of all commands and parameters are given with examples for nearly all commands. Note: The examples are coded for VisualBasic but can easily be converted to PureBasic. 42 | 43 | The OGRE Engine 44 | http://www.ogre3d.org/ 45 | The website of the OGRE 3D engine, this is the one that PureBasic uses to provide 3D graphics. 46 | 47 | Housemarque Audio System 48 | http://www.s2.org/hmqaudio/ 49 | This is the sound system that PureBasic uses to play modules. You will need to download the 'midas11.dll' file to provide module playback capabilities in your programs. This file is part of the Housemarque 'Standard distribution package'. For more information see Chapter 12 (Module Files). 50 | -------------------------------------------------------------------------------- /text/Appendix B.txt: -------------------------------------------------------------------------------- 1 | B 2 | 3 | Helpful Charts 4 | 5 | This appendix contains many useful charts, some of which have already appeared earlier on in this book. Some are reprinted here for your convenience to make finding them easier when needed. 6 | 7 | <> 8 | 9 | <> 10 | 11 | <> 12 | 13 | <> 14 | 15 | <> 16 | 17 | <> 18 | 19 | <> 20 | 21 | <> 22 | 23 | <> 24 | 25 | <> 26 | 27 | <> 28 | -------------------------------------------------------------------------------- /text/Box 1.txt: -------------------------------------------------------------------------------- 1 | A Brief Overview of The Assembly Language 2 | 3 | Assembly language or simply Assembly, is a human-readable notation for the machine language that a specific computer architecture uses. Machine language, a pattern of bits encoding machine operations, is made readable by replacing the raw values with symbols called mnemonics. 4 | 5 | Programming in machine code, by supplying the computer with the numbers of the operations it must perform can be quite a burden, because for every operation the corresponding number must be looked up or remembered. Therefore a set of mnemonics was devised. Each number was represented by an alphabetic code. For example, instead of entering the number corresponding to addition to add two numbers together you can enter 'add'. Assembly is compiled using an Assembler. 6 | -------------------------------------------------------------------------------- /text/Box 10.txt: -------------------------------------------------------------------------------- 1 | What Are Those Square Brackets Within The Syntax Examples? 2 | 3 | The square brackets shown in syntax examples are never used when using these commands. They are only included in the examples to show what parameters (if any) are optional, when using these commands. Square brackets are only ever used in actual code when you are using Static Arrays. For more information about static arrays see Chapter 5 (Arrays). 4 | -------------------------------------------------------------------------------- /text/Box 11.txt: -------------------------------------------------------------------------------- 1 | Different Ways Of Creating Or Opening Files 2 | 3 | When using PureBasic's file commands to read or write to files, you must choose the right command depending on how you wish to use that file. The below list describes commands that enable any read or write to be catered for. 4 | 5 | 'ReadFile()' will open the defined file for reading and prevents any writing to it. 6 | 'OpenFile()' will open the defined file for reading or writing and will create it if it doesn't exist. 7 | 'CreateFile()' creates an empty file for writing to. If the file already exists, it replaces it with a blank one. 8 | 9 | Each one works in exactly the same way and all share the same two parameters. The first parameter is the PB number to be associated to the file object and the second parameter is the actual file name on disk. 10 | -------------------------------------------------------------------------------- /text/Box 12.txt: -------------------------------------------------------------------------------- 1 | The 'CloseFile()' Command Is Very Important 2 | 3 | When you have finished reading and especially writing to files you must close the file correctly using the 'CloseFile()' command. This command not only closes the selected file but frees it up again to be opened by another program if needed. Another important role that the 'CloseFile()' command plays is that it completely writes to the file any data that has been left in the file buffer. PureBasic uses a buffer system to increase performance of file access, so if you are open a file in another editor and some data you expected to be there is missing you must check that you've closed the file properly using 'CloseFile()'. This command ensures any data remaining in the file buffer is written to disk. 4 | 5 | The file buffers are completely transparent to the regular user, so you won't have to worry about them too much, you just need to close each file when you have finished with it to avoid any errors. 6 | -------------------------------------------------------------------------------- /text/Box 13.txt: -------------------------------------------------------------------------------- 1 | The File Access Pointer 2 | 3 | Within each opened file there exists an invisible file access pointer. This imaginary position is where you will read from or write to in an open file. When using the 'ReadFile()', 'OpenFile()' or 'CreateFile()' commands the access pointer starts at the beginning of the file ready for the next operation. Once you start reading or writing, the file access pointer starts moving. If you are writing to the file then the access pointer will progress through it, moving to just after the value last written, ready for the next. If you are reading from a file then the access pointer will move after each read operation to the end of the last value read until the end of the file is encountered, and the 'Eof()' command returns true. 4 | -------------------------------------------------------------------------------- /text/Box 14.txt: -------------------------------------------------------------------------------- 1 | Defining Variables Using The 'Define' Command 2 | 3 | The 'Define' command can be used in two ways. First it sets the default type for un-typed variables, as shown in Chapter 2. In this way the 'Define' keyword is used with a type suffix which defines the new default type, like this: 4 | 5 | Define.s 6 | MyString = "Hello" 7 | 8 | Secondly, the 'Define' command can be used to define variables after an 'EnableExplicit' command has been used. If the 'EnableExplicit' command has been used, all variables from then on in your program have to be strictly defined. In this case, the 'Define' command may be used like this: 9 | 10 | EnableExplicit 11 | Define MyVar.b = 10 12 | 13 | Notice that when used in this way you don't have to use the type suffix on the end of the 'Define' keyword because we define the variable type using the variable's own type suffix instead. 14 | -------------------------------------------------------------------------------- /text/Box 15.txt: -------------------------------------------------------------------------------- 1 | 'OnErrorGoto' And 'OnErrorGosub' 2 | 3 | These two commands are very similar in that they let you specify a place to jump to if an error occurs so you can handle and describe the error. The main difference between these two commands is wether or not the error handler lets you return back to the normal program flow. 4 | 5 | The 'OnErrorGoto()' command lets you specify a label that you can jump to when an error occurs but you can't return from it. Meaning that once an error is handled the program must quit immediately. 6 | 7 | The 'OnErrorGosub()' command lets you specify a label or a procedure to use as an error handler, giving you the ability to return from these with the appropriate keyword. This means you have the option of resuming normal program execution after an error has been handled. 8 | -------------------------------------------------------------------------------- /text/Box 16.txt: -------------------------------------------------------------------------------- 1 | Differences Between Graphical And Non Graphical Console Modes 2 | 3 | Using the 'EnableGraphicalConsole()' command you can switch between text mode and graphical mode of the current console. Here are the differences for each mode: 4 | 5 | Text Mode (Default): 6 | ASCII control characters work correctly (ASCII range '0' to '31'). 7 | Output redirection using Pipes works correctly (Essential for CGI programs). 8 | Long Strings of printed text wrap onto a new line if they reach the end of the console window. 9 | You can read and write data to the console that is not necessarily text based. 10 | 11 | Graphical Mode (Changed using 'EnableGraphicalConsole(#True)'): 12 | Text characters outside the ACSII range '33' to '126' are displayed as small simple graphics. 13 | Long Strings of printed text are truncated if they reach the end of the console window. 14 | 'ClearConsole()' clears the entire console of any output. 15 | 'ConsoleLocate()' Moves the cursor to be able to print text in any position in the console window. 16 | 17 | This list contains some advanced topics you might not be familiar with right now but I have included this list here to be used a future reference when you are more comfortable with these things. 18 | -------------------------------------------------------------------------------- /text/Box 17.txt: -------------------------------------------------------------------------------- 1 | Why Are The Window Position Parameters Set At '0'? 2 | 3 | When opening a window using the 'OpenWindow()' command the second and third parameters of this command determine the coordinates where this window will be drawn on screen. However, if you use the '#PB_Window_ScreenCentered' or '#PB_Window_WindowCentered' flags in the same command call the position parameters are ignored. This is because PureBasic is over-riding these position parameters to center the window on the screen or over another window. If this is the case you can safely use '0' for both the position parameters or use the '#PB_Ignore' constant to explicitly show in your source code that these two parameters are been ignored because of the flags passed. 4 | -------------------------------------------------------------------------------- /text/Box 18.txt: -------------------------------------------------------------------------------- 1 | What Is A Gadget? 2 | 3 | In PureBasic a gadget is a graphical user interface object that provides some sort of interactivity for your program. Microsoft Windows calls these 'Controls' and some Linux distributions calls these 'Widgets'. Gadgets are buttons, tick boxes, sliders, input fields, tabs, frames, progress bars, etc. All the different interactive components that make up an interface, PureBasic calls gadgets. 4 | -------------------------------------------------------------------------------- /text/Box 19.txt: -------------------------------------------------------------------------------- 1 | Why Can't I Put Icons In Menus? 2 | 3 | You will probably notice in Fig.30 that there are icons in the PureBasic IDE's menus but there are no native commands included in PureBasic for putting icons in menus. PureBasic is a cross-platform programming language and PureBasic code, once written, should compile for any supported platform. Therefore, all supported commands must achieve the same desired effect on each platform. Icons in menus were regarded as being too difficult to support in a cross-platform way so they were omitted, from the final PureBasic command set. The icons included in the PureBasic IDE were coded using each platform's native API (Such as the WinAPI in the case of Microsoft Windows). To learn more about what a native API is and learn more about the WinAPI, see Chapter 13. 4 | -------------------------------------------------------------------------------- /text/Box 2.txt: -------------------------------------------------------------------------------- 1 | The IDE Quick Help 2 | 3 | As you are entering built-in library commands into the editor pane, the status bar at the bottom of the editor will show you the completed command along with an example of what parameters (if any) are expected. This can be a very handy reference when you are speed coding (maybe after too much coffee) and searching the helpfile is too much hassle. Built-in Library commands are explained further in Chapter 7. 4 | -------------------------------------------------------------------------------- /text/Box 20.txt: -------------------------------------------------------------------------------- 1 | What Is The Bit Depth Of An Image? 2 | 3 | Each pixel on a computer display or in a digital image is described by binary numbers, as you would expect on a computer. The greater, the number of bits (or binary digits) used to describe a single pixel allows that pixel to express a broader range of colors. The number of bits describing a single pixel in any given digital image or a computer display is called its bit depth. Common bit depths are 1 bit, 8 bit, 16 bit, 24 bit, and 32 bit. 4 | 5 | 1 bit images can only describe black and white (2 color) images since the one single bit that describes each pixel can either have a value of '1' or '0'. 6 | 7 | 32 bit pixels on the other hand are capable of displaying more colors than the human eye can see, so this format is regularly used in images for digital film, digital photos, realistic computer games, etc. Modern computers nowadays tend to only use 32 bits per pixel. 8 | -------------------------------------------------------------------------------- /text/Box 21.txt: -------------------------------------------------------------------------------- 1 | What Is A Sprite? 2 | 3 | Sprites were originally special hardware accelerated images that were used to create composited 2D graphics for computer games. As processing power of computers increased through the years, the special hardware that was used to move and draw these images quickly was no longer needed. However, even today, the name still remains in use to describe 2D images that are drawn on screen to create games and the like. 4 | 5 | Today a sprite can be described as a small graphic (usually containing a transparent background) that can be positioned and drawn independently on a screen to simulate animation or to provide static graphics. 6 | -------------------------------------------------------------------------------- /text/Box 22.txt: -------------------------------------------------------------------------------- 1 | Using The Keyboard? 2 | 3 | In these examples I've used a few keyboard commands to initialize the keyboard and detect keypresses, etc. These can all be found in the 'Keyboard' library helpfile page (Helpfile:Reference Manual->General Libraries->Keyboard). This is a very small and easy to use library of commands, so you should be able to pick them up pretty easily. 4 | 5 | The 'InitKeyboard()' command initializes the keyboard and should be called before any other keyboard command. The 'ExamineKeyboard()' command examines the current state of the keyboard to see if any keys are being held down, etc. The 'KeyboardReleased()' and 'KeyboardPushed()' commands return true if a given key is either released or pushed respectively. These keys can be assigned using built-in constants, of which there is a full list on the helpfile page of each command. 6 | -------------------------------------------------------------------------------- /text/Box 23.txt: -------------------------------------------------------------------------------- 1 | Creating Your Own OGRE Meshes 2 | 3 | To create your own meshes you will need to use what is known as a 3D modeling program. This type of program will allow you create a model using a three dimensional display. This allows you to see a realtime updated preview of your model from any angle during the creation process. This type of program also provides tools to allow you to add image textures, to give your model a graphical skin for when it's rendered in the 3D engine. More advanced 3D modeling programs allow you precisely to align image textures to a model by un-wrapping the model into a 2D form. This two dimensional unwrapped form can then be exported as an image to provide a template from which you can draw your texture. When this texture is applied back onto the original 3D model, it will match the 3d shape perfectly. Any 3D modeling program can be used to create your 3D models as long as the finished model can be exported and saved as a '*.mesh' file, OGRE's native file format. 4 | -------------------------------------------------------------------------------- /text/Box 24.txt: -------------------------------------------------------------------------------- 1 | Including OGRE With Your 3D Program 2 | 3 | When you create a 3D program using PureBasic and want to share it with other people, be it commercially or as a freeware program, you must remember to distribute the OGRE 3D engine with it. 4 | 5 | PureBasic uses OGRE as a compiled DLL to provide all the 3D functions in a compact and portable way. When you compile your program, the OGRE commands are not embedded into your program like regular built-in PureBasic commands. Instead, all OGRE commands are called from a DLL dynamically. This means that the DLL file must always accompany your executable file in order for it to run correctly. 6 | 7 | This is done automatically while developing, because when you hit 'F5' from within the IDE to compile and run your program, a temporary executable file in created in the '\Compilers' directory, which is exactly where the OGRE engine is installed. This ensures that testing the 3D commands is always as easy as possible. However, once you compile to an executable file elsewhere, the engine needs to be copied along with it. 8 | 9 | The two files that you must distribute with your 3D program for it to initialize and work properly, are: 10 | 11 | 'Engine3D.dll' 12 | 'stlport_vc646.dll' 13 | 14 | Both of these files are found in the '\Compilers' directory, within your PureBasic folder. These files must be loose (not in another folder) and must be in the same folder as your program's executable file. 15 | -------------------------------------------------------------------------------- /text/Box 25.txt: -------------------------------------------------------------------------------- 1 | Particle Scripts? 2 | 3 | Like material scripts, particle scripts are a way of encapsulating complicated properties under a simple name. Then, when you next create a particle emitter you can specify the particle property name and all the properties defined under that name are applied to the emitter. This makes testing and creating particle effects quicker and easier. 4 | 5 | At the moment, PureBasic does not support particle scripts but the OGRE engine does. When asked, the PureBasic team said that particle script support will be added to PureBasic in the near future. So maybe when you are reading this, PureBasic already has this support. For more information refer to the OGRE website and the online PureBasic forums, both addresses can be found in Appendix A (Useful Internet Links). 6 | -------------------------------------------------------------------------------- /text/Box 26.txt: -------------------------------------------------------------------------------- 1 | Testing Command Line Parameters Using The IDE 2 | 3 | When developing an application in the IDE that will accept command line parameters, you don't really want to be compiling to a final executable and calling that through a command line interface every time you want to test it. Instead of this long process, the PureBasic IDE helps you out by providing a field where you can enter command line parameters that you want to pass to your program when you compile it. This field can be found in the 'Compiler Options' window, which is accessible from the 'Compiler' menu. If you look three quarters of the way down you will see the field marked 'Executable Commandline'. This is where you enter parameters that you would like passing to your program when you hit the 'Compile/Run' button. Try entering some parameters in there to test the examples in this section. 4 | -------------------------------------------------------------------------------- /text/Box 27.txt: -------------------------------------------------------------------------------- 1 | Compiling Thread Safe Programs 2 | 3 | PureBasic has a compiler setting to create thread safe executables, which is a must for trouble free programming using threads. If you are using the compiler on the command line you can use the '/Thread' compiler option or you can switch on thread safe compilation in the IDE from the 'Compiler Options' dialog box (Menu:Compiler->Compiler Options...->Compiler Options->Create Threadsafe Executable). 4 | 5 | If this mode is not enabled and you are compiling and running your program, your finished executable might not be one hundred percent thread safe. This means, that because the threads contained in your program all use shared resources from within your executable, those resources can sometimes get corrupted. This is especially true regarding String usage. Without the thread safety compiler option being used, you may find that Strings used in your program may get corrupted and may return unexpected results. 6 | 7 | Using the thread safe compilation mode comes at a small price though. Because of the extra code automatically included in your executable file to handle thread safety, you may find that your program will run slightly slower than one compiled without the thread safety mode. This is why the decision to use threads must be well thought out. 8 | 9 | For all beginners using threads in PureBasic, I would recommend that the 'Create Threadsafe Executable' compiler option is always enabled when compiling programs that use threads. 10 | -------------------------------------------------------------------------------- /text/Box 28.txt: -------------------------------------------------------------------------------- 1 | DLL Calling Conventions 2 | 3 | When using PureBasic there are two calling conventions that may be used with DLLs. As standard PureBasic assumes that any given DLL uses the 'stdcall' calling convention and that any DLLs created using PureBasic via the 'ProcedureDLL' keyword are also considered to be using the 'stdcall' calling convention. This convention is used as standard in PureBasic because it is the standard calling convention of Microsoft Windows. 4 | 5 | If needed though, the 'cdecl' calling convention can be used by using the complementary 'C' functions from the PureBasic 'Library' group of commands. For example, instead of using the 'ProcedureDLL' keyword to create a 'stdcall' DLL procedure you can make that procedure use the 'cdecl' calling convention by using the 'ProcedureCDLL' keyword instead. The same goes for calling procedures from DLLs. Instead of calling a 'stdcall' procedure using the 'CallFunction()' command, you can call a 'cdecl' procedure using the 'CallCFunction()' command. 6 | 7 | There are more of these complementary 'C' functions available to be used in PureBasic, look at the helpfile in the 'Library' section for a complete list. 8 | -------------------------------------------------------------------------------- /text/Box 3.txt: -------------------------------------------------------------------------------- 1 | The 'Debug' Command 2 | 3 | The 'Debug' command is very useful to quickly print useful text into the Debug Output window. Any data type can be used with this command, making it invaluable for quickly printing helpful numbers, memory addresses, returned Strings and/or values of calculations. 4 | 5 | Any 'Debug' commands used within your code are ignored and will not be compiled when you disable the debugger or compile your final executable using (Menu:Compiler->Create Executable...). 6 | -------------------------------------------------------------------------------- /text/Box 4.txt: -------------------------------------------------------------------------------- 1 | Everything Is True? 2 | 3 | As you have read earlier on, and generally in PureBasic, '1'=True and '0'=False. While this is correct, 'If' statements are a special case regarding what they recognized as true. In 'If' statements everything equals true unless the value returned is '0' (zero) and then it equals false (unless you are making specific comparisons). This is handy when using an 'If' statement to test if a variable, command or expression returns any value other than '0'. 4 | -------------------------------------------------------------------------------- /text/Box 5.txt: -------------------------------------------------------------------------------- 1 | Manually Stopping Never Ending Loops 2 | 3 | Sometimes when you are using loops in your program you may run into the problem of unintended continuous loops. This can cause problems in your programs because these loops can stop everything else from working until they exit. One of the main headaches of unintended continuous loops is that programs containing them are notoriously difficult to quit. 4 | 5 | The PureBasic IDE makes this easy for you. If you need to stop the running program manually then just hit the 'Kill Program' button on the IDE toolbar, it's the one that looks like a skull or use the menu command (Menu:Debugger->Kill Program). This not only ends the loop but also quits the whole program straight away. 6 | -------------------------------------------------------------------------------- /text/Box 6.txt: -------------------------------------------------------------------------------- 1 | The 'SizeOf()' Command 2 | 3 | This command returns the size of any structure or defined variable in Bytes. It does not work with arrays, linked lists or interfaces. This command is invaluable for Windows programming as some Win32 API functions need the size of a particular structure or variable as a parameter. Read more about the Windows Application Programming Interface (Win32 API) later in Chapter 13. 4 | -------------------------------------------------------------------------------- /text/Box 7.txt: -------------------------------------------------------------------------------- 1 | A Note About Using The Word 'Point' 2 | 3 | In this introduction and explanation of Linked Lists I've used the word 'point' a lot. When I'm using it here it must not be confused with the computer science term 'point' or 'pointers'. The computer science term means to point to a particular area in memory or in the case of a 'pointer', a variable that holds a memory address. When I use it here, especially when I say the Linked List name points to the current element, I use it in a descriptive sense and not literally pointing to the area in memory that this element uses. For a further explanation of pointers (in the computer science sense) refer to Chapter 13 (Pointers). 4 | -------------------------------------------------------------------------------- /text/Box 8.txt: -------------------------------------------------------------------------------- 1 | Strictly Passing Values To Procedures 2 | 3 | When calling a procedure you must make sure that any defined parameters are called using the correct types or you will raise a syntax error when compiling. For example, if a procedure is defined as this: 4 | 5 | AddTogether(a.l, b.l) 6 | 7 | then only Long variables must be passed as parameters. If String type variables are defined as parameters then you must call the procedure using Strings as values for these parameters. Procedures using arrays and linked lists as parameters must also be called correctly and all parameters must be in the correct order and using the correct type. I know this seems obvious but I think it's worth pointing out. 8 | -------------------------------------------------------------------------------- /text/Box 9.txt: -------------------------------------------------------------------------------- 1 | Arrays And Linked Lists Are Passed By Reference 2 | 3 | Unlike variables, arrays and linked lists are passed by reference. This means that values aren't actually passed from arrays and linked lists into the procedures and 'copied' into the parameters. Instead an internal memory pointer is passed to the procedure and this is used to manipulate the array or linked list. 4 | 5 | This is all done internally so you wouldn't really notice anything different from using variables. The only thing you need to consider is that when you pass an array or linked list into a procedure, the parameter name used will not be a separate local array or linked list. Whatever name you give to the array or linked list parameter inside the procedure, you are still manipulating the original passed array or linked list. 6 | 7 | For example, if you pass an array called 'Dogs()' into a procedure as a parameter, this parameter could have a different name and be called 'Cats()' for instance. Then inside the procedure you could assign the 'Cats()' array different values. When the procedure exits you will notice that the 'Dogs()' array has been modified in the same way as the 'Cats()' array. This is because the 'Cats()' parameter will be just a reference to the original passed 'Dogs()' array. 8 | 9 | This is only true for arrays and linked lists, variables on the other hand are passed by value, meaning that an actual value is copied into the variable parameter. So, if you alter a variable parameter in a procedure, it will not alter the original variable that was passed to it. 10 | -------------------------------------------------------------------------------- /text/Contents.txt: -------------------------------------------------------------------------------- 1 | Table of Contents 2 | 3 | Preface ix 4 | 5 | I. The Core Language 1 6 | 7 | 1. Getting Started 3 8 | The History Of PureBasic 3 9 | The Development Philosophy Of PureBasic 5 10 | A First Look At The IDE 6 11 | How To Run PureBasic Programs 7 12 | The Debugger 8 13 | A Note On Program Structure 8 14 | Introducing The PureBasic Help File 9 15 | 16 | 2. Data Types 10 17 | Built-In Data Types 10 18 | Numbers 10 19 | Strings 12 20 | Variables And Constants 12 21 | 22 | 3. Operators 18 23 | An Introduction To Operators 18 24 | Operator Precedence 33 25 | Expression Notes 34 26 | 27 | 4. Conditional Statements And Loops 37 28 | Boolean Logic 37 29 | The 'If' Statement 38 30 | The 'Select' Statement 41 31 | Loops 43 32 | 33 | 5. Other Data Structures 49 34 | Structures 49 35 | Arrays 52 36 | Linked Lists 62 37 | Sorting Arrays And Linked Lists 67 38 | 39 | 6. Procedures And Subroutines 71 40 | Why Use Procedures Or Subroutines? 71 41 | Subroutines 71 42 | Procedure Basics 74 43 | Program Scope 76 44 | The 'Global' Keyword 78 45 | The 'Protected' Keyword 79 46 | The 'Shared' Keyword 80 47 | The 'Static' Keyword 82 48 | Passing Variables To Procedures 83 49 | Passing Arrays To Procedures 86 50 | Passing Linked Lists To Procedures 88 51 | Returning A Value From Procedures 91 52 | 53 | 7. Using Built-In Commands 93 54 | Using The PureBasic Helpfile 93 55 | PB Numbers And OS Identifiers 95 56 | Examples Of Common Commands 98 57 | Handling Files 104 58 | Read The Helpfile 110 59 | 60 | 8. Good Programming Style 111 61 | Why Bother Formatting Code 111 62 | The Value Of Comments 112 63 | My Coding Format 113 64 | Golden Rules For Writing Easily Readable Code 116 65 | How To Minimize And Handle Errors 117 66 | 67 | II Graphical User Interfaces 129 68 | 69 | 9. Creating User Interfaces 131 70 | Console Programs 131 71 | Creating Native User Interfaces 137 72 | Understanding Events 139 73 | Adding Gadgets 140 74 | Adding A Menu 148 75 | Menu Keyboard Shortcuts 153 76 | Including Graphics In Your Program 156 77 | A First Look At The New Visual Designer 162 78 | 79 | III Graphics And Sound 165 80 | 81 | 10. 2D Graphics 167 82 | 2D Drawing Commands 167 83 | Saving Images 179 84 | Introducing Screens 181 85 | Sprites 192 86 | 87 | 11. 3D Graphics 203 88 | An Overview Of The OGRE Engine 203 89 | A Gentle Beginning 206 90 | A Simple First Person Camera 215 91 | A Little More Advanced 221 92 | What's Next? 226 93 | 94 | 12. Sound 227 95 | Wave Files 227 96 | Module Files 231 97 | Mp3's 233 98 | CD Audio 237 99 | 100 | IV Advanced Topics 243 101 | 102 | 13. Beyond The Basics 245 103 | Compiler Directives And Functions 245 104 | Advanced Compiler Options 252 105 | Parsing Command Line Parameters 259 106 | A Closer Look At Numeric Data Types 262 107 | Pointers 269 108 | Threads 279 109 | Dynamic Link Libraries 287 110 | The Windows Application Programming Interface 293 111 | 112 | V Appendices 303 113 | 114 | A. Useful Internet Links 305 115 | 116 | B. Helpful Charts 307 117 | 118 | C. Glossary 317 119 | 120 | Index 332 121 | -------------------------------------------------------------------------------- /text/Inside Front Cover.txt: -------------------------------------------------------------------------------- 1 | PureBasic - A Beginner's Guide To Computer Programming 2 | by Gary Willoughby 3 | 4 | Copyright © 2006 Gary Willoughby 5 | This book and all included source materials such as diagrams, photos and PureBasic source code is distributed under the Creative Commons Attribution Non-Commercial Share Alike License. More details can be found here: http://creativecommons.org/about/licenses/ 6 | 7 | PureBasic is a registered trademark of Fantaisie Software. PureBasic and all provided tools and components contained within the PureBasic package are Copyright © 2006 Fantaisie Software. 8 | 9 | Fantaisie Software 10 | 10, rue de Lausanne 11 | 67640 Fegersheim 12 | France 13 | www.purebasic.com 14 | 15 | 16 | Published 2006, by Aardvark Global Publishing. 17 | 18 | Editor 19 | Gary Willoughby 20 | 21 | Print History 22 | July 2006 - First Edition 23 | 24 | 25 | Disclaimer 26 | While every precaution has been taken in the preparation of this book and the programs contained within it, the author and publisher assumes no responsibility whatsoever for errors, omissions, or for damages resulting from the use of the information or programs contained herein. The author or publisher shall not be liable if incidental or consequential damages occur in connection with, or arising from, the furnishings, performance, or use of the programs, associated instructions, and/or claims of productivity gains. All information contained herein is considered accurate at time of publication but because PureBasic is a language in a constant state of refinement and development, some information over time may be rendered out-of-date. For up to date news and information regarding PureBasic please refer to www.purebasic.com. 27 | 28 | Trademarks 29 | Trademarked names appear throughout this book. Rather than list the names and entities that own the trademarks or insert a trademark symbol with each mention of the trademarked name, the publisher states that it is using the names for editorial purposes only and to the benefit of the trademark owner, with no intention of infringing on that trademark. 30 | 31 | Dedication 32 | Dedicated to my girlfriend, Sara Jane Gostick and her dog 'Stella' for putting up with many lonely nights while I wrote this book and for the encouragement (and chicken dinners) she always gives me. 33 | 34 | 35 | 36 | Acknowledgments 37 | Thanks to Fred and the Purebasic team for the Purebasic language, keep up the good work, it rocks! 38 | Thanks to Paul Dixon for clarifying some of the details regarding binary encoding of floating point numbers. 39 | Thanks to Timo Harter for helping to choose what Purebasic data types would best substitute the Win32 API types, and for demonstrating how to retrieve different strings from memory via the different Win32 API String pointer types. 40 | 41 | 42 | 43 | 'With great power there must also come great responsibility!' 44 | --Ben Parker (Spiderman's Uncle) 45 | 46 | 47 | 48 | Code examples contained in this book can be downloaded freely from 49 | www.pb-beginners.co.uk 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | ISBN 1-4276-0428-2 19/7/2006 72 | -------------------------------------------------------------------------------- /text/Section 1.txt: -------------------------------------------------------------------------------- 1 | I 2 | 3 | The Core Language 4 | 5 | In this section, we will study the PureBasic language itself. I call this part 'The Core Language', because our focus will be on the essentials of PureBasic programming: its built-in types, statements and expressions. By the time you finish reading this section and studying the examples, you'll be ready to write programs yourself. 6 | 7 | The word 'Core' in the title is used on purpose, because this section is not an exhaustive document on every minute detail of PureBasic. While I may skip certain things along the way, the basics you learn here will stand you in very good stead for when the unknown pops up. There is also a mention of the history and development philosophy of PureBasic for those who are interested. 8 | -------------------------------------------------------------------------------- /text/Section 2.txt: -------------------------------------------------------------------------------- 1 | II 2 | 3 | Graphical User Interfaces 4 | 5 | In this next section I'm going to talk about Graphical User Interfaces and how they are created in PureBasic. Nearly all modern operating systems have a built-in graphical user interface available, allowing the user to interact fluidly with programs that choose to use it. The operating system exposes the user interface to programs through an Application Programming Interface (or API) through which a program can tell the operating system how draw its user interface. This sounds extremely complicated but is simply and elegantly handled within PureBasic using the 'Window', 'Menu' and 'Gadget' libraries. 6 | 7 | PureBasic creates these graphical interfaces for your programs using the native application programming interface of the system they've been compiled for. In other words, when you code an interface for a program and compile it on a particular system, that program will have the correct look and feel of the operating system it has been compiled for. This is essential for all professional application development. 8 | 9 | This section begins with explaining and demonstrating programs that use a console as their user interface, which is arguably the simplest user interface of all. Later, I move on to explain how to create programs with native user interfaces and how to add menus and graphics. In the last section I give you and overview of the PureBasic Visual Form Designer. Using this tool you can design an interface visually as if you were painting it upon a program. 10 | 11 | After reading this section you should have a firm grasp on how to create graphical user interfaces for your programs and understand how to handle interaction from the user. 12 | -------------------------------------------------------------------------------- /text/Section 3.txt: -------------------------------------------------------------------------------- 1 | III 2 | 3 | Graphics And Sound 4 | 5 | Programs that use graphics and sound are a prerequisite now in this world of computer games and interactive applications. When programming such cool stuff you need a computer language that will provide you with the necessary tools to realize your ideas. PureBasic offers simple, powerful and fully featured commands that can create professional quality games, demo's, screensavers and other interactive programs. In this section I will show you the basics of using graphics and sound within your PureBasic programs. 6 | 7 | First I'll explain the 2D drawing commands that allow you to draw simple shapes, lines and text and then demonstrate how to save these images. Then I'll move on to show you how to open full size graphical screens to be able to draw graphics onto. Also I will introduce you to sprites and how to use them to create nice graphical effects. 8 | 9 | After that, we'll move onto 3D graphics where I will introduce you to PureBasic's adopted 3D engine and show you the basics of using 3D graphics in PureBasic. This engine is called OGRE and is a third party professional quality engine capable of producing stunning graphics and effects. 10 | 11 | The last chapter in this section deals with sound. The topics covered, are how to load and play sounds, with an emphasis on wav's, tracker modules, mp3's and CD audio. 12 | 13 | The chapters contained in this section are not complete guides on how to achieve every graphical effect or how to write games, I'll leave that to other texts. These chapters are here to introduce you to the libraries of commands that make these things possible and to provide a starting point so you can experiment and have some fun. Hopefully this section will give you a taste of what is possible graphically using PureBasic and inspire you to create a cool demo or game. 14 | -------------------------------------------------------------------------------- /text/Section 4.txt: -------------------------------------------------------------------------------- 1 | IV 2 | 3 | Advanced Topics 4 | 5 | In this section, I explain things that are a little more advanced than what the rest of this book deals with. This section is for those who have further questions on a particular facet of PureBasic or want to learn a little more about what goes on 'under the hood'. 6 | 7 | You don't need to know any of what is contained in this section to write good, solid and feature-rich programs, but I have included it here for those who want to delve a little deeper. 8 | -------------------------------------------------------------------------------- /text/Section 5.txt: -------------------------------------------------------------------------------- 1 | V 2 | 3 | Appendices 4 | 5 | This next section contains the appendices to this book. This supplementary material contains a variety of useful information including useful Internet links, a few pages of helpful charts and a complete computer science glossary. 6 | 7 | These final pages provide you with a quick reference to some of the more useful information that you will want to look at time and time again. 8 | --------------------------------------------------------------------------------