A Beginner's Guide to Gambas Cover design by Fabien Bodard Foreword by Fabien B
A Beginner's Guide to Gambas Cover design by Fabien Bodard Foreword by Fabien Bodard and Benoît Minisini 1 A Beginner's Guide to Gambas Copyright Notice for the printed version of this work: A Beginner's Guide to Gambas (this work) is copyright © 2005 by John W. Rittinghouse, all rights are reserved. Personal use of this material is permitted. However, permission to reprint/republish this material for advertising or promotional purposes or for creating new collective works for resale or redistribution to servers or lists, or to reuse any copyrighted component of this work in other works must be obtained from the the author, John W. Rittinghouse. The author grants a perpetual license to the Gambas user-community for use of the electronic version of this printed work under the terms and conditions of the OpenContent License printed on the following page. 2 A Beginner's Guide to Gambas Copyright Notice for the electronic (online) version of this work, based on the OpenContent License (OPL), Version 1.0, July 14, 1998. This document outlines the principles underlying the OpenContent (OC) movement and may be redistributed provided it remains unaltered. For legal purposes, this document is the license under which OpenContent is made available for use. The original version of this document may be found at http://opencontent.org/opl.shtml . LICENSE Terms and Conditions for Copying, Distributing, and Modifying Items other than copying, distributing, and modifying the Content with which this license was distributed (such as using, etc.) are outside the scope of this license. 1. You may copy and distribute exact replicas of the OpenContent (OC) as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the OC a copy of this License along with the OC. You may at your option charge a fee for the media and/or handling involved in creating a unique copy of the OC for use offline, you may at your option offer instructional support for the OC in exchange for a fee, or you may at your option offer warranty in exchange for a fee. You may not charge a fee for the OC itself. You may not charge a fee for the sole service of providing access to and/or use of the OC via a network (e.g. the Internet), whether it be via the world wide web, FTP, or any other method. 2. You may modify your copy or copies of the OpenContent or any portion of it, thus forming works based on the Content, and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified content to carry prominent notices stating that you changed it, the exact nature and content of the changes, and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the OC or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License, unless otherwise permitted under applicable Fair Use law. These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the OC, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the OC, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Exceptions are made to this requirement to release modified works free of charge under this license only in compliance with Fair Use law where applicable. 3. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to copy, distribute or modify the OC. These actions are prohibited by law if you do not accept this License. Therefore, by distributing or translating the OC, or by deriving works herefrom, you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or translating the OC. NO WARRANTY 4. BECAUSE THE OPENCONTENT (OC) IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE OC, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE OC "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE OF THE OC IS WITH YOU. SHOULD THE OC PROVE FAULTY, INACCURATE, OR OTHERWISE UNACCEPTABLE YOU ASSUME THE COST OF ALL NECESSARY REPAIR OR CORRECTION. 5. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MIRROR AND/OR REDISTRIBUTE THE OC AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE OC, EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 3 A Beginner's Guide to Gambas Table of Contents Acknowledgments........................................................................16 Foreword.......................................................................................17 Chapter 1 Introducing Gambas.................................................19 Gambas Architecture......................................................19 The Gambas Programming Environment......................22 Gambas IDE Components.................................................25 Chapter 2 – Gambas Language Concepts.................................30 Gambas Variables, Datatypes and Constants.............30 Variable Assignment..........................................................35 Assignment Using The WITH Statement...........................35 Operators and Expressions............................................36 Comparison operators ......................................................36 Arithmetic Operators..........................................................36 Let's Start Coding Gambas................................................37 END, RETURN and QUIT Statements.......................................37 String Operators................................................................44 Chapter 3 Keywords and Program Flow Control....................46 The PRINT Statement.......................................................46 The IF Statement...............................................................47 The SELECT / CASE Statement.......................................48 GOTO and LABELS..........................................................49 The FOR / NEXT Statement..............................................49 DO [WHILE] LOOP............................................................51 WHILE [Expression] WEND Loops ...................................52 The REPEAT UNTIL loop .................................................53 Defining and Using Arrays in Gambas..........................53 Collections.......................................................................55 The FOR EACH Statement...............................................55 Chapter 4 – Introducing the Gambas ToolBox..........................57 The Button Control..........................................................61 Common Control Properties..............................................62 Button Methods.................................................................70 4 A Beginner's Guide to Gambas Button Events....................................................................78 The Picture Class............................................................78 Chapter 5 – Controls for Gathering Input...................................80 TextLabel..........................................................................82 TextBox............................................................................83 ComboBox........................................................................85 ListBox.............................................................................89 Frame................................................................................92 ToggleButton...................................................................93 Checkbox.........................................................................93 Panel.................................................................................95 RadioButton.....................................................................95 Chapter 6 – Menus, Modules, Dialogs and Message Boxes.....97 The Gambas Menu Editor...............................................98 Building Menus..............................................................101 Dialogs............................................................................103 Modules..........................................................................105 MessageBoxes...............................................................112 Information Messages.....................................................112 Query/Confirm Messages................................................114 Error Messages...............................................................115 Warning or Alert Messages.............................................115 Delete Messages.............................................................116 Dialog Class Filerelated Functions.............................117 Dialog OpenFile Function................................................117 Dialog SaveFile Function.................................................118 Dialog SelectDirectory Function......................................119 Complete Example Listing............................................120 Module1.module listing.................................................123 Chapter 7 – Handling Strings and Converting Datatypes.....125 String Functions............................................................125 Len...................................................................................126 5 A Beginner's Guide to Gambas Upper$/Ucase$/Ucase and Lower$/Lcase$/Lcase ........126 Trim$, LTrim$, and RTrim$..............................................127 Left$, Mid$, and Right$ ..................................................128 Space$............................................................................130 Replace$ ........................................................................130 String$ ............................................................................131 Subst$ ............................................................................131 InStr.................................................................................132 RInStr..............................................................................134 Split..................................................................................134 Converting Datatypes..................................................135 Asc and Chr$ ..................................................................135 Bin$.................................................................................136 CBool ..............................................................................137 CByte...............................................................................138 CDate..............................................................................138 CFloat..............................................................................139 CInt / Cinteger and CShort .............................................140 CStr / CString .................................................................140 Hex$................................................................................141 Conv$ .............................................................................141 Val and Str$ ....................................................................142 Str$ .................................................................................142 Format$...........................................................................145 Datatype management .................................................147 TypeOf.............................................................................148 Chapter 8 – Using Advanced Controls.....................................149 IconView Control...........................................................149 ListView Control............................................................158 Using the Gambas Icon Edit Tool................................162 The TreeView Control....................................................163 The GridView Control....................................................171 The ColumnView Control..............................................174 Layout Controls – HBox, VBox, HPanel and Vpanel. .176 HBox and VBox...............................................................177 HPanel and Vpanel..........................................................177 6 A Beginner's Guide to Gambas The TabStrip Control.....................................................181 Chapter 9 – Working with Files.................................................188 Access............................................................................188 Dir....................................................................................189 Eof...................................................................................190 Exist................................................................................190 IsDir / Dir? .....................................................................191 Stat .................................................................................191 Temp / Temp$ ...............................................................192 OPEN and CLOSE..........................................................192 LINE INPUT.....................................................................193 READ, SEEK, WRITE and FLUSH.................................194 COPY, KILL and RENAME.............................................195 MKDIR, RMDIR...............................................................196 Chapter 10 – Math Operations..................................................215 Precedence of Operations............................................215 Abs..................................................................................216 Acs / ACos......................................................................216 Acsh / ACosh.................................................................217 Asn / ASin.......................................................................217 Asnh / ASinh..................................................................218 Atn / ATan.......................................................................218 Atnh / ATanh..................................................................219 Cos..................................................................................219 Cosh................................................................................220 Deg and Rad...................................................................221 Exp..................................................................................221 Fix and Frac...................................................................222 Int....................................................................................223 Log..................................................................................223 Log10..............................................................................224 7 A Beginner's Guide to Gambas Max and Min...................................................................224 Pi.....................................................................................225 Randomize and Rnd......................................................225 Round.............................................................................227 Sgn..................................................................................227 Sin...................................................................................228 Sinh.................................................................................229 Sqr...................................................................................229 Tan..................................................................................230 Tanh................................................................................231 Derived Math Functions................................................231 Chapter 11 – ObjectOriented Concepts..................................237 Fundamentals of Object Oriented Programming........238 Objects............................................................................239 Data Abstraction..............................................................239 Encapsulation..................................................................240 Polymorphism..................................................................240 Inheritance.......................................................................240 The Gambas Approach to OOP....................................241 Gambas Classes.............................................................241 Sample program: Contacts...........................................242 The Contact class............................................................242 Contact.GetData Method.................................................243 Contact.PutData Method.................................................246 Form1.class file...............................................................247 Form1 Constructor...........................................................249 Form_Open Subroutine...................................................250 Adding Controls to Form1.Form......................................250 The ToolButtons.......................................................................251 The Quit Button.........................................................................251 Adding the Labels and TextBoxes............................................252 UpdateForm() Subroutine................................................253 Coding Toolbuttons: First, Prev, Next, and Last.......................254 Coding ToolButtons: Adding a record.......................................256 Coding ToolButtons: Clearing data...........................................258 Validating User Input.......................................................258 8 A Beginner's Guide to Gambas Adding a Search Feature.................................................260 The DoFind Subroutine.............................................................262 ToolButtons again: Updating a Record............................263 Toolbuttons again: Deleting a Record.............................264 ToolButtons again: Saving Data......................................265 Creating a Standalone Executable..............................266 Chapter 12 – Learning to Draw.................................................267 Draw Properties.............................................................267 BackColor/Background and ForeColor/Foreground........267 Clip..................................................................................268 FillColor,FillStyle,FillX,FillY..............................................268 Font.................................................................................269 Invert................................................................................269 LineStyle/LineWidth.........................................................270 Transparent.....................................................................270 Draw Methods................................................................270 Text/TextHeight/TextWidth..............................................272 Draw Primitives: Point/Rect/Ellipse/Line..........................274 Draw Primitives: Polygon and Polyline............................280 Image/Picture/Tile............................................................284 Drawing with a Drawing object........................................292 Chapter 13 – Error Management...............................................298 General uploads/Litterature/ gambas-guide.pdf
Documents similaires










-
41
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Jan 16, 2022
- Catégorie Literature / Litté...
- Langue French
- Taille du fichier 5.5064MB