Download presentation
Presentation is loading. Please wait.
1
Introduction to Visual Basic What it is, and a simple program Mike Thelwall University of Wolverhampton, UK
3
Origins through BASIC Beginners All-purpose Symbolic Instruction Code A simple programming language Developed mid 1960’s Simplicity of BASIC made it a natural choice as a programming language Most machines have own version of BASIC
4
Windows Programming Visual Basic developed for Windows by Microsoft from BASIC –Interface designer –Simple coding language –Quick to produce programs Versions of it are now also in Excel, Access, Word, PowerPoint and many other software
7
What is it good for? Lots of things! But particularly… automating repetitive tasks that are governed by strict rules It is a relatively easy to learn language –Good for those who are not ‘real’ programmers
8
Designing a Program – Draw it first
9
VB Environment: Menu Bar The Menu Bar consists of 3 elements the –Title Bar, which holds the name of application, default if Microsoft Visual Basic [design] –Menu Bar, this is the link to Visual Basics menu facilities, each menu option drops down into sub-menus –Toolbar, contains icons which give access to the more commonly used commands (which are also available through the menu bar) Title barMenu BarToolbar
10
VB Environment: Control Toolbox Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shape Image Common Dialog OLE Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Line Data Control Grid
11
VB Environment: Properties Window
12
Events and Visual Basic Start by drawing the screen Then add program code for Button Clicks Trigger Event Code Executed
13
Visual Basic Environment
14
Programming Application Example You have a large text file containing 100,000 lines, each one of which is a reference from a journal article, with details of the author You want to count how many of these references are to SUNY Albany faculty Visual Basic can make this task possible
15
Designing the Program Open the text file Read in the first line of text Check if the line contains “SUNY Albany” –Keep a running total of how many matches there are Read in the next line and repeat Display the total count when finished
16
What it looks like
17
The code
18
The data nobody, no journal someone not from Albany, journal of nothing someone else not from Albany, journal of nothing john smith, SUNY Albany, Topological properties of Spheres Rong Tang, SUNY Albany, Some very hard information science nobody, no journal
19
The result
20
Visual Basic in Excel Visual basic hides behind Excel Macros If you know any version of VB then it is not difficult to learn the other versions VB looks horrible in Excel programs, but can be very useful
21
A simple task for VB in Excel Find the distance, in metres, between all pairs of a set of 34 US Chemistry departments This is 1,089 distances – how can it be done?
22
Solution 1 Get the coordinates of each department by entering its Zip code into Multimap.com Enter the coordinates into an Excel spreadsheet Write a VB program to use this data to calculate the distances between all pairs of departments
24
The code
27
How to write a Visual Basic program: Plan A Think about EXACTLY what you want to do –Can it be fully automated, or will it require human judgement? Write down EXACTLY what you want to do –Break it into a series of steps Take VB101 and learn VB Write the program Test the program to make sure that it works
28
How to write a Visual Basic program: Plan B [Quick Version] Think about EXACTLY what you want to do –Can it be fully automated, or will it require human judgement? Write down EXACTLY what you want to do –Break it into a series of steps Find a VB programmer Ask them to write the program for you Test the program to make sure that it works Buy them lunch
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.