1 / 160

Foundation of Computer Programming Visual Basic 6.0 Programming

Foundation of Computer Programming Visual Basic 6.0 Programming. Instructor : Mr. Nguyen Cao Tri caotri@dit.hcmut.edu.vn http://www.dit.hcmut.edu.vn/~caotri Documents : Course syllabus, lecture’s slide, samples can be found at http:// www.dit.hcmut.edu.vn/~caotri/VB6.

magdalene
Download Presentation

Foundation of Computer Programming Visual Basic 6.0 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. Foundation of Computer ProgrammingVisual Basic 6.0 Programming Instructor: Mr. Nguyen Cao Tri caotri@dit.hcmut.edu.vn http://www.dit.hcmut.edu.vn/~caotri Documents: Course syllabus, lecture’s slide, samples can be found at http://www.dit.hcmut.edu.vn/~caotri/VB6

  2. Course Information • Course objectives: • Understand basic theories on Computer software programming • Understand Microsoft Visual Basic 6.0 syntax and its major features • Design and develop GUI Windows applications • Develop critical thinking of software programming • Text book/reading material: • Visual Basic 6.0 how to program ,Deitel & Deitel • Cyber classroom CD :Visual Basic 6.0 how to program • Internet Web site access

  3. Introduction Computing concepts Programming concepts Flowchart

  4. Computing Concepts CPU • Computer • Processor • I/O Devices • Storage system: Primary & Secondary • Operating system • User interface: command line , GUI • Programming concepts: • What’s Program • Programming languages: machine code, high level languages • Developing environmental • Algorithms I/O devices Storage System

  5. Programming languages & IDE • Programming languages • GO TO Programming : basic, assembly • Structured Programming: Pascal, C,.. • Object Programming: Java, C++ • Visual approach for GUI programming. • Compiler • Interpreter • Compiler • Integrated Development Environment (IDE) • Project manager, Code editor, debug, compiler

  6. Object Oriented Programming (OOP) • What’s Object? • Object properties • Object method • What’s Class? • Message/Even • Object vs. Structure • How can an OOP program works? • Object and Visual Basic Object Name (ID) Properties Methods Object 1 Object 1 Messages Object 1

  7. Algorithms & Flowchart • What’s algorithms • How to present an algorithms? • Natural language, Programming languages • Others? • Flowchart • Characteristic: picture base, chart base • Capability • Advantage: • Simple • Easy to understand • Powerful • Better view and control of Flowchart

  8. Flowchart components • Start or Begin of algorithms. One START point only. Start • Process Flow • Input / Output data • Process description / data calculation No Condition • Process Direction Control Yes Evaluation Item • Other Process direction Control Value 1 Value i Others Stop • Stop or End of algorithms. One/Multi STOP point.

  9. Flowchart Example Algorithms ax + b=0 equation solving. Start Read a, b a=0 ? b=0 ? Yes Yes No No X=-b/a Any number is solution No Solution Stop

  10. Control Structures in programming languages • If <condition> then Statement; • If <condition> then Statement 1 else Statement 2; • Case <Value> of value 1 : Statement 1; ……….. value n : Statement n; else : Statement 0 end; • While <condition> do Statement; • Repeat Statement until <condition>; • For counter=start value to end value do Statement; • For counter=start value downto end value do Statement;

  11. Other terms in computer programming • Data & Data type • Basic data type • integer, long, character, byte, …. • Real (double, float) • Others: string • Structured data type: array, string, record,.. • Variable, Constant • Reserve words, keywords • Error : Syntax error, Semantic error, Run time error • Debug : trace, break point, test case • Packet & installation tools

  12. What’s Visual Basic (VB) • Microsoft Windows Programming language • Microsoft IDE for Visual studio developer • Visual Basic versions • Version history • Standard , Professional & Enterprise • What can programmers do with VB? • Windows GUI applications • Database applications • Computer Graphic applications • Internet / WEB applications • ………

  13. Visual Basic programming steps • User interface design. • Forms design • Objects/Components properties define • Resource edit : icon, button image,.. • Code Writing form “even base” concept. • Compile/Build program • Debug source code • Packet application • Deploy application. • Maintenance

  14. Microsoft Visual Studio IDE Integrated Development Environment Project Tools Box Form layout Properties Menu Bar and Tool Bar Simple Program develop

  15. IDE Overview Menu Bar Tool Bar Project Window Properties Window

  16. Project Windows Standard EXE application Title Bar Project View Tool Box Properties Form

  17. Other IDE Components • Tool Box • Content all objects/components for FORM design. • Properties Windows • Control all properties of Form/Objects/Components • Display, font, format, enable,… • Project Windows • Project folder view • Form view • Code view

  18. Simple Welcome Program • Program description • The program will show/hide the text “Welcome to Visual Basic 6.0” when button Show/Hide is clicked • The exit button used to exit the program. It is available after first click of Show button only. • How to do that with Visual Basic 6.0 • Design form with Label object name Label1 and caption “Welcome to Visual Basic 6.0” Set it visible properties to false. • Add button cmdShowHide & Button cmdExit to form. • Click on each button for writing code to it base on “Click” even • Click Play button on IDE to run program. • See sample below

  19. Simple application FORM design form1 Label1 Visible = false Caption = “welcome to Visual Basic 6.0” cmdExit Enable = false cmdShowHide Caption =“&Show

  20. Simple application Code write

  21. Simple Application Run Time Click Show button: Exit enable, show Text, Show -> Hide First run: Only Show button available Click Hide button: Hide Text Click Exit button: Exit Program

  22. Review & Home Work • Review from page 25 -> 47 • Drawing the Flowchart for Solving the equation ax2 +bx + c =0 • Redo the simple program • Using Visual Basic 6.0 IDE to build the form design from page 48->49 • Submit to instructor by email. • Pre-View chapters 3 and 4 for next lecture.

  23. Introduction to Visual Basic programming Get familiar with Visual Basic Programming Get familiar with fundamental data types Using arithmetic operators Writing simple program in Visual Basic

  24. Visual Programming & Even Programming • Visual tool of Visual basic for user interface design (GUI) • Tool Box components • From • Components • Component evens • Even procedure • Some basic components: Label Button (CmdButton) Text box Frame, Selected box, List box …….

  25. Visual Basic Tools Box

  26. Even drive programming • What’s Even? • Component evens • Even Procedure The sub procedure will be done when an even happened to component Each component has its own evens.

  27. Writing first program with Visual Basic • Print Line of Text on form • Button Exit : exit program on click • Button print: On click, print a line of text “Hello, Welcome to Visual Basic” on form. • CODE • Private Sub Command1_Click() • Print " Hello! Welcome to Visual Basic" • End Sub • Private Sub Command2_Click() • End • End Sub

  28. Other Application • Accumulate ADD Program allow user to enter an integer number and click add button. The numbers will be accumulate and display on form. Dim sum As Integer Private Sub cmdClear_Click() sum = 0 txtInput.Text = " " txtAdd.Text = 0 End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdAdd_Click() sum = sum + txtInput.Text txtAdd.text = sum txtInput.Text = "" End Sub Private Sub Form_Load() cmdClear_Click() End Sub

  29. Syntax and statement • Data type • Variable declaration DIM variablename As datatype Ex: Dim Sum As Integer Dim Total As Integer • Keywords and reserved words • Statement Statement end with “end of line” • Assign statement Variable = Assigned value

  30. Arithmetic

  31. Operators Precedence

  32. Comparison Operators

  33. Example of comparison operator Private Sub cmdClear_Click() txtInput1.Text = "" txtInput2.Text = "“ Label3.Caption = “Result” End Sub Private Sub cmdCompare_Click() Dim input1, input2 As Integer input1 = txtInput1.Text input2 = txtInput2.Text If input1 = input2 Then Label3.Caption = "First number equal second number" Else If input1 < input2 Then Label3.Caption = "First number less than second number" Else Label3.Caption = "First number greater than second number" End If End If End Sub • Write a windows program which allow user input 2 numbers A and B and then compare and show the result. Private Sub cmdExit_Click() End End Sub

  34. Visual Basic Control structures Understanding control structures of VB Flowchart and control structures Using control structure by samples

  35. Syntax if <condition> then statements end if Example If cmdShowHide.Caption = “&Show” then cmdShowHide.Caption = “&Hide” Label1.Visible = true end if If/Then structure Condition Yes Statements

  36. Syntax if <condition> then statements else statements end if Example If cmdShowHide.Caption = “&Show” then cmdShowHide.Caption = “&Hide” Label1.Visible = true else cmdShowHide.Caption = “&Show” Label1.Visible = false end if If/Then/Else structure Condition No Yes Statements Statements

  37. Syntax While <condition> statements Wend Example Dim product As integer product = 1 While product <= 1000 product = product * 2 print product Wend What’s on form 4 8 16 32 64 128 256 512 1024 While/Wend structure Condition Yes Statements No Beware of infinite loop

  38. Syntax Do while <condition> statements Loop Example Dim product As integer product = 1 Do while product <= 1000 product = product * 2 print product Loop What’s on form 4 8 16 32 64 128 256 512 1024 Do while/Loop structure While/Wend || Do while/Loop

  39. Syntax Do until <condition> statements Loop Example Dim product As integer product = 1 Do until product >1000 product = product * 2 print product Loop What’s on form 4 8 16 32 64 128 256 512 1024 Do until/Loop structure Condition Statements No Yes Beware of infinite loop

  40. Syntax Forcounter=startValueToendValueStepStepsize statements Nextcounter Example For j = 2 to 80 step 5 a= a+2 Next j For/Next structure Counter = StartValue Counter = Counter + Stepsize statements Counter > endValue ** Stepsize = 1 is default value No Yes

  41. Sample of For/Next For years = 1 To 10 Step 1 amount = principal * (1 + interestRate) ^ years lstDisplay.AddItem Format$(years, "@@@@") & vbTab & Format$(Format$(amount, "Currency"), _String$(17, "@")) Nextyears

  42. Select Case structure • Syntax Select Case mAccessCode CaseIs < 1000 message = "Access Denied" Beep Case 1645 To 1689 message = "Technician Personnel" Case 8345 message = "Custodial Services" Case 55875 message = "Special Services" Case 999898, 1000006 To 1000008 message = "Scientific Personnel" Case Else message = "Access Denied" End Select

  43. Do/loop while structure • Syntax counter = 1 Do Print counter & Space$(2); counter = counter + 1 Loop While counter <= 10 • Result 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

  44. Do/Loop Until structure • Syntax counter = 1 Do Print counter & Space$(2); counter = counter + 1 Loop Until counter >= 10 • Result 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 Statements Do Loop While Condition Yes No Statements Do Loop Until Condition No Yes

  45. For x=1 to 10 if x=5 then exit for end if print x next x Result: 1 2 3 4 5 counter = 1 Do Print counter & Space$(2); counter = counter + 1 if n = 5 then Exit Do Loop Until counter >= 10 Result: 1 2 3 4 5 Exit Do / Exit For Why do exit do and exit be used.

  46. Variable & Constant – Logical operators • Dim VariableName As DataType • Const ConstantName = value As DataType • Logical operators • NOT • AND • OR • Where ‘s Logical operators used

  47. Visual Basic Data type

  48. LAB Works • All Samples from text book • Exercises at end of chapters • Assignment Calculator application • Your own applications (option)

  49. SUB & Function procedure Procedure in VB Sub/Function Recursive

  50. Module programming • What’s module? • Why do we need to write program in module? • Modules in Visual Basic • Even procedure • Visual basic procedure • SUB procedure • Function procedure • What should be used ? • Visual basic procedures • Sub/function procedures

More Related