Visual Basic Examples.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
1 MA 1128: Lecture 19 – 4/19/11 Quadratic Formula Solving Equations with Graphs.
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
Whiteboardmaths.com © 2007 All rights reserved
1 Advanced PowerPoint Cliff Solomon. 2 Presentation Outline Inserting Movies and Animations Into Your Presentations Using Progressive Disclosures and.
1 Excel Lesson 3 Using Formulas and Functions Microsoft Office 2010 Fundamentals Story / Walls.
1 ADVANCED MICROSOFT POWERPOINT Lesson 7 – Working with Visual and Sound Objects Microsoft Office 2003: Advanced.
Other Features Index and table of contents Macros and VBA.
Controls General Discussion. VB Controls Visual Basic Controls A control is the generic name for any object placed on a form Controls may be images,
1 Lesson 6 Exploring Microsoft Office 2007 Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Excel Tutorial Enfield High School 2007.
PowerPoint for teachers and students C MacFadyen, Dec 2008.
Inspire students to develop ideas & organize thinking
Multimedia ! Graphics ! Animation ! Sound Tip Of the Day 4 Tip of the Day: When using graphic methods at Form Load, the AutoRedraw property of the container.
IE 411/511: Visual Programming for Industrial Applications
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Quadratic Functions. Examples 3x 2 +2x-6 X 2 -4x+3 9x
Copyright © Cengage Learning. All rights reserved. 4 Quadratic Functions.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Getting Started with TI-Interactive. TI-Interactive TI-Interactive can be used to create a variety of graphs. Scatter Plots, Line Plots, Histograms, Modified.
Chapter Two Creating a First Project in Visual Basic.
Writing Linear Equations Graphing Linear Equations Solving Linear Equations Properties of Real Numbers Equations and Functions $500 $400 $300 $200 $100.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Building the Events Components– Lesson 111 Building the Events Components Lesson 11.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Lesson 4 Mathematical Operators! October 6, 2009.
Controls. Common properties Height – Height of the control Left – Left of the control Width – width of a control Top - From the screen top Font – Foreground.
Quadratic Functions.
BBT 10 Visual Basic 03 Enrichment. Tip Before creating any files for your project, first create a new folder Save all of your files in the folder Pieces.
Controlling Program Flow with Decision Structures.
Visual Basic A Quick Tutorial VB Review for ACS 367.
More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
TOOLBOX. The Toolbox Intrinsic Controls - always included in the Toolbox ActiveX Controls - separate files with ocx file extension Insertable Objects.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
I am using Visual Basic 6 for this class. If you want to use a different version, please contact me. Thanks!
1 By Dr. HANY ELSALAMONY. 1. What are differences between interpreted and compiled languages? 2. What are the programming steps to creating the Visual.
Computing and Information Technology Building a Web Browser
3.01 Apply Controls Associated With Visual Studio Form
1. Introduction to Visual Basic
Standard Controls.
Please use speaker notes for additional information!
Microsoft Office Access 2003
Visual Basic.
Microsoft Office Access 2003
Department Array in Visual Basic
Chapter 6 - Visual Basic Schneider
Визуалды бағдарламалау ортасы.
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
AS-Level Maths: Core 2 for Edexcel
Chapter 4 Enhancing the Graphical User Interface
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

Visual Basic Examples

1. Cubic Function Graph Plotter This is a program that enable users to input the coefficients of a cubic equation and draw its graph. The cubic equation takes the form  ax3+bx2+cx+d

The Codes Private Sub cmd_draw_Click() Dim a, b, c, d As Integer Dim w, v As Double a = Val(txt_a.Text) b = Val(txt_b.Text) c = Val(txt_c.Text) d = Val(txt_d.Text) 'Using a scale of 0.5 cm to represent i unit to draw the graph ' Need to make some transformation as the coordinates in VB start from top left For w = 0 To 10 Step 0.001 v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d pic_graph.PSet (w, 5 - v) Next w End Sub

Private Sub Command1_Click() 'To clear the old graph pic_graph Private Sub Command1_Click() 'To clear the old graph pic_graph.Cls txt_a.Text = "" txt_b.Text = "" txt_c.Text = "" txt_d.Text = "" End Sub   Private Sub Command2_Click() End End Sub

2- Traffic Light This Traffic Light program is a Visual Basic program. It is a nice little program. In this program, you have to insert one timer and set its interval according to your wish. Here I set it to 3000, which is equivalent to 3 seconds. Next you insert three shapes and set their shape properties to circle and fill the colors. There it goes, your traffic light is working!

Private Sub Timer1_Timer() If Shape1. Visible Then Shape2 Private Sub Timer1_Timer() If Shape1.Visible Then Shape2.Visible = True Shape1.Visible = False Shape3.Visible = False ElseIf Shape2.Visible Then Shape3.Visible = True Shape2.Visible = False Shape1.Visible = False Else Shape1.Visible = True Shape2.Visible = False Shape3.Visible = False End If End Sub

3-Digital Clock Visual Basic programming is so simple that sometime you just need to write a one line code to create a wonderful tiny little but nice application. For example, you can write a one- line code to create a digital clock. In this program, you have to insert a timer control into the form . Then go to the properties window to set the timer's interval value to 1000 so that Visual Basic updates the time every 1000 milliseconds, or once a second. Other properties that you ought to set are to change the caption (here is My Clock) and  to set Form1's MaxButton to false (so that it cannot be maximized by the user)

Now, double click the timer and enter the one line code as follows:        Private Sub Timer1_Timer()                 Label1.Caption = Time        End Sub

  4- Calculator This is simple calculator created by my son, Liew Xun. This program uses a combo box which include four operators, addition, subtraction, multiplication and division. It can perform the above four basic calculations by changing the operators.

The Codes (Copyright Liew Xun) Private Sub Combo1_() Select Case Combo1.ListIndex Case 0 Label1 = Str$(Val(Text1.Text) + Val(Text2.Text)) Case 1 Label1 = Str$(Val(Text1.Text) - Val(Text2.Text)) End Select End Sub

Private Sub Command1_Click() Select Case Combo1 Private Sub Command1_Click() Select Case Combo1.ListIndex Case 0 Label1 = Str$(Val(Text1.Text) + Val(Text2.Text)) Case 1 Label1 = Str$(Val(Text1.Text) - Val(Text2.Text)) Case 2 Label1 = Str$(Val(Text1.Text) * Val(Text2.Text)) Case 3 Label1 = Str$(Val(Text1.Text) / Val(Text2.Text)) End Select End Sub

Private Sub Command2_Click() End End Sub Private Sub Form_Load() Combo1.AddItem "+" Combo1.AddItem "-" Combo1.AddItem "x" Combo1.AddItem "÷" Combo1.ListIndex = 1 End Sub

5-Picture Viewer Let’s create a program that enables the users to open and choose files from the folders in their PC. This can be done easily using a picture box and a common dialog box. In this program, you need to insert a picture box, a common dialog box and an image. In the image properties windows, click on the picture property and select a picture that resembles an open file icon. 

The procedure to open the common dialog box to browse the picture files as well as to load the selected picture into the picture box is CommonDialog1.Filter = "Bitmaps(*.BMP)|*.BMP|Metafiles(*.WMF)|*.WMF|Jpe g Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*" CommonDialog1.ShowOpen Picture1.Picture = LoadPicture(CommonDialog1.FileName)

The filter property of the common dialog box uses the format as shown below Bitmaps(*.BMP)|*.BMP to specify the file type, and uses the pipe line | to separate different file types. Visual Basic supports most of the picture formats namely bmp, wmf, jpg, gif, ico(icon) and cur(cursor) files. The command  CommonDialog1.ShowOpen is to open the common dialog box and the command  Picture1.Picture = LoadPicture (CommonDialog1.FileName) is to load the selected picture file into the picture box.

The whole program is shown below and the output is shown in the figure below:  Private Sub Image1_Click() CommonDialog1.Filter = "Bitmaps(*.BMP)|*.BMP|Metafiles(*.WMF)|*.WMF|Jpe g Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*" CommonDialog1.ShowOpen Picture1.Picture = LoadPicture (CommonDialog1.FileName) End Sub

6- Quadratic Functions Graph Plotter This is a program that can plot graphs for quadratic functions. The general format of a quadratic equation is f(x)= ax2+bx+c , where a, b and c are constant. This program  employs a picture box as the plot area and three text boxes to obtain the values of the coefficients a, b, c of the quadratic equation from the users. We also need to modify the scale factor in the properties windows of the picture box. I am using a scale of 0.5 cm to represent 1 unit .

Besides, we need to make some transformation as the coordinates in VB start from top left but I want it to start from the middle. I am using the Pset method to draw the graph using a very small increment. This program is useful for high school students and mathematics teachers.

The Code Private Sub cmd_draw_Click() Dim a, b, c As Integer Dim w, v As Single a = Val(txt_a.Text) b = Val(txt_b.Text) c = Val(txt_c.Text) 'Using a scale of 0.5 cm to represent i unit to draw the graph ' Need to make some transformation as the coordinates in VB start from top left For w = 0 To 10 Step 0.001

v = a. (5 - w) ^ 2 - b. (5 - w) + c pic_graph v = a * (5 - w) ^ 2 - b * (5 - w) + c pic_graph.PSet (w, 5 - v) Next w End Sub Private Sub Command1_Click() pic_graph.Cls txt_a.Text = "" txt_b.Text = "" txt_c.Text = "" End Sub

7- Multimedia Player I have created a multimedia player that can play all kinds of media files such as wav, midi, mp3, mpeg video, avi video and so on. When you launch the program, you can select files of different types from different drives. After you have selected a particular files, you can play it using the customized button or you can use the buttons of the multimedia control In this program, you need to insert the Microsoft Multimedia Control, a combo box, a dirListBox, a DriveListBox, a fileListbox, a picture box(to play the video) , a text box and four command buttons which you label as "Play", "Open","Stop" and "Exit".One of the most important procedures is to open various audio files, the codes are as follow:

Private Sub Open_Click() If Combo1. ListIndex = 0 Then MMControl1 Private Sub Open_Click() If Combo1.ListIndex = 0 Then MMControl1.DeviceType = "WaveAudio" End If If Combo1.ListIndex = 1 Then MMControl1.DeviceType = "Sequencer" End If If Combo1.ListIndex = 2 Then MMControl1.DeviceType = "AVIVideo" End If If Combo1.ListIndex = 3 Then MMControl1.DeviceType = "" End If

8-Simultaneous Equations Solver It has been sometimes we have not deal with mathematical problems, so why not focus on this subject once again. Actually the thought of programming a mathematical tool came across my mind when my son asked me some questions associated with simultaneous equations. Then It dawned on me that why not I program a simultaneous equation solver so that it can solve my son's problems as well as my problems too. There you are, the program is ready and I am showing the codes here:

Private Sub Command1_Click() Dim a, b, c, d, m, n As Integer Dim x, y As Double a = Val(Txt_a.Text) b = Val(Txt_b.Text) m = Val(Txt_m.Text) c = Val(Txt_c.Text) d = Val(Txt_d.Text) n = Val(Txt_n.Text) x = (b * n - d * m) / (b * c - a * d) y = (a * n - c * m) / (a * d - b * c) Lbl_x.Caption = Round(x, 2) Lbl_y.Caption = Round(y, 2) End Sub

Private Sub Command2_Click() Txt_a. Text = "" Txt_b. Text = "" Txt_m Private Sub Command2_Click() Txt_a.Text = "" Txt_b.Text = "" Txt_m.Text = "" Txt_c.Text = "" Txt_d.Text = "" Txt_n.Text = "" Lbl_x.Caption = "" Lbl_y.Caption = "" End Sub

Explanation: Linear simultaneous equations take the following forms: ax+by=m cx+dy=n Simultaneous equations can normally be solved by the substitution or elimination methods. In this program, I employed the substitution method. So, I obtained the following formulae: x = (b * n - d * m) / (b * c - a * d) y = (a * n - c * m) / (a * d - b * c) To limit the answers to two decimal places, I used the round function.

9-Simultaneous Equations Solver 2 The coming example will show you how to design a program that can solve mixed simultaneous equations, that is , one linear equation and one quadratic equation. Here is the program: Private Sub Command1_Click() Dim a, b, c, d, m, n As Integer Dim x1, x2, y1, y2 As Double a = Val(Txt_a.Text) b = Val(Txt_b.Text) m = Val(Txt_m.Text) c = Val(Txt_c.Text) d = Val(Txt_d.Text) n = Val(Txt_n.Text)

x1 = (m. a. d + Sqr(m ^ 2. a ^ 2. d ^ 2 - (b ^ 2. c + a ^ 2. d). (d x1 = (m * a * d + Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d) x2 = (m * a * d - Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d) y1 = (m - a * x1) / b y2 = (m - a * x2) / b Lbl_x1.Caption = Round(x1, 2) Lbl_y1.Caption = Round(y1, 2) Lbl_x2.Caption = Round(x2, 2) Lbl_y2.Caption = Round(y2, 2) End Sub

Explanation: Mixed simultaneous equations take the following forms: ax+by=m cx2+dy2=n Simultaneous equations can normally be solved by the substitution or elimination methods. In this program, I employed the substitution method. So, I obtained the following formulae:

x1 = (m a d + Sqr(m 2 a 2 d  2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d) x2 = (m a d +-Sqr(m 2 a 2 d  2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d) y1 = (m - a x1) / b y2 = (m - a x2) / b To limit the answers to two decimal places, I used the round function.