1 / 31

Visual Basic 6 Programming.

Visual Basic 6 Programming. Lecture 1 : January 2005 Dr. Andrew Paul Myers. Course Methods. Lectures. Handout notes. Supervised practical work. Weekly submission of exercises. Weekly feedback on exercises. Model Answers. Final project : 12.00 Wed. 19 th May 2004.

orlando
Download Presentation

Visual Basic 6 Programming.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic 6 Programming. Lecture 1 : January 2005 Dr. Andrew Paul Myers

  2. Course Methods. • Lectures. • Handout notes. • Supervised practical work. • Weekly submission of exercises. • Weekly feedback on exercises. • Model Answers. • Final project : 12.00 Wed. 19th May 2004. • Clinics for final Project.

  3. Introduction. • A course in Visual Basic 6. • Why Visual Basic 6 (VB6)? • Objectives : • General education in computing. • Introduction to programming. • First write a simple program, then… • Write a more complex program. • Course Benefits : • I.T. is a part of all our lives and getting more so! • VB6 and computing skills for other courses. • Future employment.

  4. Tools For The Job. • Programming Environment : • CFS client PC. • Windows 2000. • Microsoft Visual Studio 6 SP5. • Computers in G73 only at present!

  5. Programming Languages. • You are users! • How computers work. • Machine code. • High level languages. • BASIC : Beginners All purpose Symbolic Instruction Code. • Other languages : • FORTRAN, C/C++ & Java

  6. Programming Cycle. • Analyse the task. • Plan the program, a structured approach! • Flowcharts & Pseudo-code (Week 2). • Edit your source code. • Execute and debug program (Week 2) • Edit source code as necessary.

  7. Setting up VB6 on CFS. VB6 is part of MS Visual Studio 6. Select : Start Menu Programs Installable Software Then navigate to : Central Software Programming Languages Double click on : Install MS Visual Studio V6 SP5

  8. VB6 Help : MSDN. • Visual Studio 6 has an extensive, inbuilt help system call MSDN. MicroSoft Developer Network. • Before this can be used select Setup Help for this session in the MS VS6 folder on the Programs menu. Only run this once per login session.

  9. Starting VB6. • After setup a new folder is added to your programs menu. • Select Microsoft Visual Basic 6 from the MS Visual Studio V6 SP5 folder. • Tip : Create a short cut on your desktop. • This will start the VB6 IDE. Integrated Programming Environment. Select Standard EXE as project type.

  10. The VB IDE. Has Standard MicroSoft “feel”. • Title Bar. Status : Design, run, debug. • Menu Bar. Pull down menus. • Tool Bar. • Tool Box. For adding controls. • Project Explorer. List project modules. • Properties Window. • Form Layout.

  11. On we go…

  12. Structure of VB Program. VB programs are made up of different subroutines (or procedures) of the form: Private Sub <name>() Comment statement(s) Declaration statement(s) BASIC statement(s) End Sub

  13. VB Statements. • Comments : Used to document programs and make them more readable. USE THEM !!! ‘ A Comment! • Terminate a program. End

  14. An assignment statement. Computers store and add numbers (very fast). Computer memory is divided into separate sections. Each is identified by a number (its address). A computer language allows us to identify these by names. Then to manipulate the numbers in them. Alan Bruce Claire Dan Ethel …….. Alan = Bruce + Claire

  15. 1 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 Bits, bytes and nibbles (its half a byte!). 8 bits make a byte Each bit can be set to 1 or 0, so within one byte (8 bits) we can represent numbers in the range 0 to 255 i.e. 2^8. Combining multiple bytes, we can store numbers: 16 bits = 2 bytes stores 2^16 = 0 to 65535 32 bits = 4 bytes stores 2^32 = 0 to 4294967295 These are whole numbers (integers), no decimals allowed. We are restricted to numbers +/- 2 billion.

  16. 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 Different Forms of Storage. • A large number on a calculator is represented in exponential (also called scientific) format e.g. 1.23456E+23. • If we take 4 bytes of memory, and store the mantissa (1.23456) in 3 bytes, and the exponent (+23) in one byte, we can store real numbers, with a greater range. • Represent letters by a numerical code from 0 – 255 (ASCII) and store them in one byte. Text can then be stored as a linked set of bytes, called a String. ASCII 107 is k ASCII 43 is +

  17. Types of Variables. • Integers (whole numbers) • Real numbers. • Single. • Double (twice the number of bytes). • Strings. • And others coming later… • Variants. • All types automatically converting. • DANGEROUS! – Don’t go there!

  18. Variable Names. Data is stored as variables, each with a different name. Variable names are: • Case insensitive. • Up to 255 characters long. • First character must be a letter. • Can use any combination of alphanumeric characters and the underscore character.

  19. Examples. Value yes 3radius no Question&Reply no Density_of_water yes lngRadius1 yes

  20. Hungarian Notation. A convention of prefixes for variable names, depending on variable type. String : str Integer : int Long Integer : lng Single : sng Double : dbl Boolean : bln Currency : cur Variant : vnt

  21. Variable Types I VB6 has 14 standard types. • String : Hold characters, approx 231, can be null (empty). Can be identified by $. strText$=“Hello.” strEmptyText = “”

  22. Variable Types II. • Integer : Range –32,768 to +32,767. Can be identified by %. intValue% = 1 intValue2 = 1000 • Long Integer : Larger range (231). lngValue1& = 56000 lngValue2 = -56000

  23. Variable Types III. • Single Precision : Real numbers. Accuracy of 7 digits. sngReal_Number1! = 1.23 sngReal_Number2 = -0.345 • Double Precision : Accuracy of 16 digits dblValue1# = 0.435827348593 dblValue2 = 23.4782947373 Reals are slower than integers in calculations!

  24. Variable Types IV. • Boolean : True or False? blnAnswer = False • Other types include : Currency, Date, Byte (range 0 to 255) and variant (can be any data type – very flexible, but dangerous!).

  25. Variable Type Declarations I Declare all variables before use! Good programming practice. Also avoids having to use the suffixes $, #, ! etc. Use the Dim statement. e.g. Dim <variable> as <data type> Dim intDays as Integer Dim strText as String, dblAns as Double

  26. Variable Type Declarations II Declaring all variables before use is good programming practice. Use the “Option Explicit” command to make VB insist of variables being declared before you can use them. Option Explicit This also avoids having to use the suffixes $, #, ! etc, as all variable types are explicitly defined. Note : This check is carried out when the program is run, not at the editing stage!

  27. Assignments I. • 5 basic mathematical operators: Addition (+) Subtraction (-) Division(/) Multiplication (*) Exponentiation (^) • Precedence follows BODMAS. • Parentheses can be used to over ride precedence. 6 * 5 + 4 * 3 gives 42 (((6 * 5) + 4) * 3) gives 102

  28. Assignments II. <variable> = <value> | <variable> | <expression> Examples : intValue = 1 strText2 = strText1 intValue = intValue + 1 sngVol = sngLength^3.0 strText = “Hello” dblVol= (4#/3#)*dblPi*dblRadius^3

  29. Print Statements. Print <expression> Print “Hello!” Print “Value is “; intValue Print “A : “; intA; “ cm.” Print dblRadius We shall be using “Text Boxes”!

  30. Good Programming Style. • Comment your program! • Hungarian notation for variable names. • Use descriptive variable names. • Blanks lines may be used to improve readability. • Indent code with “tabs”.

  31. References. Visual BASIC 6 from the ground up. Gary Cornell. (Osborne). MSDN On-line Help. Active subsection : Visual Basic Documentation.

More Related