310 likes | 544 Views
Introduction to Visual Basic. What it is, and a simple program. Mike Thelwall University of Wolverhampton, UK. Origins through BASIC. B eginners A ll-purpose S ymbolic I nstruction C ode A simple programming language Developed mid 1960’s
E N D
Introduction to Visual Basic What it is, and a simple program Mike Thelwall University of Wolverhampton, UK
Origins through BASIC • BeginnersAll-purposeSymbolicInstructionCode • 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
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
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
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 bar Menu Bar Toolbar
VB Environment: Control Toolbox Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Line Data Control Grid Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shape Image Common Dialog OLE
Events and Visual Basic • Start by drawing the screen • Then add program code for Button Clicks Trigger Event Code Executed
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
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
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
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
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?
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
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
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