Free Essay

Visual Basic

In: Computers and Technology

Submitted By dsad2012
Words 930
Pages 4
Visual Basic – Messages and data input/output
One way for a user to communicate with a procedure is via a dialogue box. The easiest way to do this in VB is to use one of the pre-defined ones. VB has two kinds, a Message box and an Input box.

Message box
The MsgBox function displays a message, waits for the user to click a button and returns a value indicating which button has been chosen. The simplest MsgBox contains only a message string and an OK button. The general syntax is MsgBox(prompt [,buttons] [,title]), where the quantities within [] are optional arguments, with prompt: string expression displayed in the message (max length 1024 characters) buttons: numerical expression that is sum of values specifying the type of buttons to display, title: string expression displayed in the title bar. Some of the button values are given below. (For a full list see the Help file). Value Constant Display 0 vbOKOnly OK button only 1 vbOKCancel OK and Cancel buttons 3 vbYesNoCancel Yes, No and Cancel buttons 4 vbYesNo Yes and No buttons 32 vbQuestion Query icon 48 vbExclamation Warning message icon 0 vbDefaultButton1 First button is default 256 vbDefaultButton2 Second button is default 512 vbDefaultButton3 Third button is default The value returned by the MsgBox function depends on the button pressed. Some values are listed below. Button selected Value Constant OK 1 vbOK Cancel 2 vbCancel Yes 6 vbYes No 7 vbNo The MsgBox function can be used as a simple debug tool. To display the contents of variable variDisplay then use MsgBox “Contents of variDisplay “ & variDisplay which creates a message made from concatenating the text Contents of variDisplay with the data in the variable variDisplay.


The example below displays a message box with two buttons, Yes and No, with No as the default response. The value returned by the MsgBox function depends on the button pressed by the user. msg = “Do you want to continue?” boxButtons = vbYesNo + vbDefaultButton2 msgTitle = “Processing mode” response = MsgBox(msg, boxButtons, msgTitle) If response = vbYes Then msg = “clicked YES” Else msg = “Clicked No or pressed ENTER” End If MsgBox msg

Data input and output
A procedure often needs some data on which it applies its actions. A Function procedure will usually get its input data from its arguments and returns a value in its name. A Sub procedure could get its input from arguments but it doesn’t return a value, yet it needs to return data somehow. One method is for the data to be taken from, or put into cells of a spreadsheet. For example Activeworkbook.Sheets(1).Range(“A1”).Value = 10 puts the value 10 into cell A1 of the current worksheet. Likewise the statement xVal = ActiveSheet.Range(“B2”).Value assigns to the variable xVal in the code the contents of cell B2. The previous technique presupposes that the values of the data are know in advance and have been entered into the spreadsheet BEFORE the procedure is run. The InputBox function creates and displays a simple dialogue box that contains a prompt, an edit box, and OK and Cancel buttons. You use this box to allow the user to input data at run-time. The format of the InputBox function is InputBox(Prompt, [,title] [,default] [,xpos] [,ypos]) with prompt := a string expression displayed in the box, Optional arguments title:= a string expression displayed in the dialogue box’s title bar. If omitted nothing is displayed. default:= default response if no input provided xpos, ypos specify the horizontal and vertical position of the box. If omitted the box is centred horizontally and about one-third of the way down the screen. A simple example is radius = InputBox(“Enter radius of circle”, “Circle _ radius”)


which will display a dialogue box with a title “Circle radius” and a message “Enter radius of circle” and wait for the user to enter a value. The InputBox Method (of the Application object) works like the InputBox function but the method also allows you specify the data type. This enable you to enter a range, e.g. A1:A10. If data entered is of the wrong type Excel displays an error message. The format to use is Application.InputBox(prompt,title,default,left,top,type) The arguments, prompt, title and default are as for the InputBox function. The arguments, left, top, and type are optional, (left and top specify the horizontal and vertical postion from the top left of the screen in point units (=1/72.27 inch)), type specifies the data type. If type is omitted the method returns text). Type has the following values, Value Description 0 a formula 1 a number 2 text (string) 4 logical 8 cell reference ( a range) 16 error value 64 an array of values Note, type = 1 + 2 accepts text or number. The code below asks the user to specify a range to search and a search value. The search range must be a valid range, e.g. sheet!A1:A10, and the search value is a number. Sub CountEntries() Dim allCount As Integer, rangeToSearch As Object Dim searchValue, c cellCount = 0 Set rangeToSearch = Application.InputBox( _ Prompt: = “Enter range to search”, _ Type: = 8) ‘ type 8 means entry must be a range object searchValue = Application.InputBox( _ Prompt: = “Search for value”, _ Type: = 1) ‘ type 1 means a number If searchValue = False Then Exit Sub ‘ user clicked Cancel For Each c In rangeToSearch If c.Value = searchValue Then cellCount = cellCount + 1 End If Next c MsgBox “Number of occurrences of “ & searchValue _ & “ is “ & cellCount End Sub


Similar Documents

Premium Essay

The History of Visual Basic

...The History of Visual Basic dates back to 1991 when VB 1.0 was introduced. The core of Visual Basic was constructed on the older BASIC language, which was the prevalent programming language throughout the 1980s. It's a computer programming system established and owned by Microsoft. Visual Basic was originally produced to make it easier to write programs for the Windows computer operating system. The basis of Visual Basic is an earlier programming language called BASIC that was invented by Dartmouth College professors John Kemeny and Thomas Kurtz. Visual Basic is often denoted by using just its initials; VB. Visual Basic is easily the most extensively used computer programming system in the history of software. Microsoft Visual Basic is the most common language and development environment for developers coding to the Windows operating system platform. From modest beginnings it has grown to be part of personal computing itself, and with the latest incarnation, Visual Basic .NET in Beta it looks as if it may be in use for another decade or longer. Visual Basic 1.0 for Windows was released in May 1991 at a trade show in Atlanta, Georgia. Visual Basic 2.0 was released in November 1992. The programming environment was easier to use, and its speed was improved. Visual Basic 3.0 was released in 1993 and came in Standard and Professional versions. Visual Basic 4.0 was released in August 1995. It was the first version that could produce 32-bit as well as 16-bit Windows programs.......

Words: 409 - Pages: 2

Free Essay

Visual Basic Preview

...Visual Basic 2010 Essentials Visual Basic 2010 Essentials Visual Basic 2010 Essentials – First Edition © 2010 Payload Media. This eBook is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved. The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions. 2 Visual Basic 2010 Essentials Table of Contents Chapter 1. Chapter 2. 2.1 2.2 2.3 2.4 About Visual Basic Essentials .................................................................................. 11 Downloading and Installing Visual Studio............................................................... 12 Getting Visual Studio ...................................................................................................... 12 Downloading a Visual Studio Trial .................................................................................. 12 Installing Visual Studio ................................................................................................... 13 Starting Visual Studio for the First Time ........................................................................ 14 Creating a New Visual Basic Project ....................................................

Words: 5044 - Pages: 21

Free Essay

Semantics of Visual Basics

...| Purpose In this project, a database management system will be implemented to make the self-ordering easier. The users for this program will be used for customers in various restaurants. It will take a customer’s order, total it, and give them an amount. The system will instruct the customer to enter the correct amount. If the amount is not enough, the system will instruct them to enter more money. If it is too less, however, the system will them issue out change. Use of Visual Basics Visual Basic for Applications (VBA) will be used because it is a programming language built right into many Microsoft programs. This language is built on the Basic programming language made popular by PCs over the past 25 years. VBA shares similarities with other Windows implementations of the Basic language, such as Visual Basic. If you are familiar with programming in a different language (including using macros), you can quickly get up to speed with VBA. There are a few terms you should know before you start programming in VBA: * Procedure. A section of programming code, designed to accomplish a specific task, which your program statements can use throughout your program. There are two types of procedures: functions and subroutines. * Function. A procedure that returns a value after it completes its task. When called, functions typically appear on the right side of an equal sign in an expression. * Subroutine. A procedure that does not return a value after it completes......

Words: 3627 - Pages: 15

Free Essay

Visual Basic

...Textbook problem #3 on Page 232/234 Public Class Form1 Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click Dim Visited As String = "", Dates As String = "", Location As String = "" 'Declaring information entered in txtboxes 1-3 Dim Meals As Double, Airfare As Double, Lodging As Double, Taxifare As Double 'Declaring information entered in txtboxes 4-7 DisplayBox.Visible = True Inputs(Visited, Dates, Location, Meals, Airfare, Lodging, Taxifare) Displayexpenses(Visited, Dates, Location, Meals, Airfare, Lodging, Taxifare) End Sub Sub Inputs(ByRef Visited As String, ByRef Dates As String, ByRef Location As String, _ ByRef Meals As Double, ByRef Airfare As Double, ByRef Lodging As Double, ByRef Taxifare As Double) 'all wordlike inputs as string, all number inputs being recognized as double Visited = CStr(TxtBox1.Text) 'telling us where information is located on the form Dates = CStr(TxtBox2.Text) Location = CStr(TxtBox3.Text) Meals = CDbl(TxtBox4.Text) Airfare = CDbl(TxtBox5.Text) Lodging = CDbl(TxtBox6.Text) Taxifare = CDbl(TxtBox7.Text) End Sub Sub Displayexpenses(ByVal Visited As String, ByVal Dates As String, ByVal Location As String, ByVal Meals As Double, ByVal Airfare As Double, ByVal Lodging As Double, ByVal Taxifare As Double) 'Display Expenses as per book......

Words: 447 - Pages: 2

Premium Essay


...Engineer | SOFTWARE PROFICIENCY |Web Technologies  |HTML, XML | |Script |PERL Scripting,Java Scripts | |RDBMS/DBMS |Oracle 9i | |IDE’s |Eclipse, NetBeans | |Languages |C++, SQL, PL\SQL, Visual Basic and JAVA | |Operating System |Windows XP, Windows 95/98, & UNIX | |PLM/PPM Packages |Windchill/Planisware 5 | PROJECTS UNDERTAKEN |Project Name |Support and Enhancement of the Product Planisware 5(PPM) | |Period |01-July-10 to | |Location...

Words: 431 - Pages: 2

Free Essay


...Week 7 iLab—Sales Tax TCO 3: Given a simple problem, design and desk-check a solution algorithm requiring a modular design that is expressed in terms of pseudocode or program notes, input-process-output (IPO) analysis, and flow chart. * TCO 7: Given a program with logic errors that is intended as a solution to a simple problem, employ debugging diagnostics to remove and correct the errors. TCO 8: Given a more complex problem, develop a complete solution that includes a comprehensive statement of the problem, complete program design, and program documentation. Scenario Your algorithm will write two functions called ComputeTotal( ) and ComputeTax( ). ComputeTotal( ) will receive the quantity of items purchased, and the unit price of each item. It will return the total sales (quantity times price). ComputeTax( ) will receive total sales as a number and the state as a string and return the amount of tax depending on the state. NJ requires 7% tax, FL requires 6% tax, and NY has 4% tax. The main program will ask for the name of the customer and read the name in a variable called name. It will also ask for one of the three states listed above. It will ask for the number of items sold and the unit price of the item. Main will then call ComputeTotal( ), passing the quantity and unit price. Main will then call ComputeTax( ), passing the state and the amount of sales and receive back the tax. Finally Main( ) will print out the total sales, the tax amount, and the total...

Words: 784 - Pages: 4

Free Essay

Art History

...OMIS 462 Spring 2013 Visual Basic Assignment 4 Due: April 25rd 100 points Title: University Book Store Learning Objectives After completing this project, you will be able to: 1. Create a database in VB, use the data in an application, and create queries. 2. Build an application using multiple forms, and pass data between forms. Description Build a simple University Bookstore system. This system will have a one-table Inventory database for books. For this system, each book will have only one author. Here are the main things you must do in your application: 1. Using the Golf Tutorial as a guide, create a database containing an Inventory table. The inventory table should have the following attributes: BookID, Title, Author (just last name), ISBN and edition. Enter data for at least 5 books. Include two books written by Dickens, and at least three others of your choice. 2. Create a query to allow the user to enter the author name to find all books by that author. 3. The first form should allow the user to search for the author by name (the query created above), displaying all the details except BookID. Once the user finds the desired book, the user should be able to click a button to put the selected book on a book order on a new form. Also add a Quit button. 4. On the order form, display the values shown. Have a button to Place the Order. Clicking this button should display a “Thank you for your order”......

Words: 403 - Pages: 2

Free Essay


...Being a CCNA certified and thre benefits CCNA is one of the most vouched and valued IT certification throughout the world. Cisco certifications have benefited both the employee as well as the employer. It is a known fact that many people have literally changed their lives and have got real benefits and acquired valuable skills in the process of becoming certified. In the process of getting your CCNA certification you are sure to increase your knowledge base and understanding of the concepts. . In the process of getting certified you would be bombarded with many advancements of the industry thus increasing your overall knowledge. CCNA Certification increases your chances of promotion. You could expect to move up in the hierarchy of your organization. Getting a CCNA certificates commands a certain amount of respect from your colleagues and employer. Some of your colleagues would have also tried to get certified, but could not get certified. So, this achievement of yours deserves a back-patting. You always wanted to get certified, so after you receive your certification letter and other stuff, a sense of personal satisfaction, gratification, and relief is felt. Those were some of the benefits that you could receive after getting CCNA certified. Top 10 best free web design software 1. Coffeecup html editor 2. Notepad++ 3. Pagebreeze 4. Firebug 5. Bluefish editor 6. Brackets 7. kompoZer 8. openBexi 9. GIMP 10. Bluegriffon The......

Words: 541 - Pages: 3

Free Essay


...Coursework Assignment Brief Semester: | A15 | Module Code: | PI307 | Module Title: | Visual Basic.Net Programming | Programme | BSc (Honours) Computer Science BSc (Honours) Business Management & Information Technology | Level: | Level 6 | Awarding Body: | Plymouth University | Module Leader | Asma Aslam | Format: | Code based Report | Presentation: | No | Any special requirements: | All work should be submitted on the Student Portal along with an acceptable Turnitin Report | Word Limit: | Not Applicable | Deadline date for submission: | 03Rd April 2015 | Learning outcomes to be examined in this assessment | * Design and develop programs including internet programs deploying visual basic Net applications. * Implement user interfaces with relation to object orientated programming techniques and use classes and assemblies to make code reusable and extendable. * Use visual tools ADO.NET objects and basic Structured Query language to access and manipulate data. | Percentage of marks awarded for module: | This assignment is worth 50% of the total marks for the module | Assessment criteria | Explanatory comments on the assessment criteria | Maximum marks for each section | A working application with VB Code | Practical application of what has been learned during the module | 35% | The quality of your comments in Code | Both line and block comments will make your code more easily understandable | 10% | ......

Words: 698 - Pages: 3

Free Essay


...MapX Developer’s Guide MapInfo Corporation Troy, NY 2 MapX Developer’s Guide Information in this document is subject to change without notice and does not represent a commitment on the part of the vendor or its representatives. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying without the written permission of MapInfo Corporation, One Global View, Troy, New York 12180–8399. ©1992–1999 MapInfo Corporation. ALL RIGHTS RESERVED. MapInfo Help ©1992–1999 MapInfo Corporation. ALL RIGHTS RESERVED. MapInfo, MapInfo Professional, MapBasic, MapXtreme and the MapInfo Logo are registered trademarks of MapInfo Corporation. Contact MapInfo Corporation on the Internet at: MapInfo Corporate Headquarters: Voice: (518) 285–6000 Fax: (518) 285–6060 Sales Info Hotline: (800) 327–8627 Federal Sales: (800) 619–2333 Technical Support Hotline: (518) 285–7283 Technical Support Fax: (518) 285–6080 MapInfo Europe Headquarters: England voice: +44 (0)1753 848 229 fax: +44 (0)1753 621 140 Germany voice: +49 6196 6700 0 fax: +49 6196 6700 11 For international customers, please use the Technical Support Fax number. WARNING: This software uses patented LZW technology for .GIF image compression and/or decompression. (Unisys United States patent No. 4,558,302 and corresponding patents in Canada, France, Germany, Italy, Japan and the United Kingdom). GIF images......

Words: 73952 - Pages: 296

Free Essay

Visual Basic Calculater

...Public Class Form1 Dim m, num, count As Double Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click TextBox1.AppendText("7") End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click TextBox1.AppendText("9") End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.AppendText("1") End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.AppendText("2") End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click TextBox1.AppendText("3") End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.AppendText("4") End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click TextBox1.AppendText("5") End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click ......

Words: 858 - Pages: 4

Free Essay

Sales and Inventory System

...Rica A. Hernandez BSCS 2101 Start Microsoft Visual Basic 6.0 (VB6) The New Project dialog box will appear. If it doesn't go up to the menu bar and select File -> New Project In the New Project dialog select Standard EXE, and click the Open Button. This will bring up your new Project 1 application with Form1 visible. Already Visual Basic has done a lot for us. As you can see this tutorial isn't very long but already you have a full working application. You can see your new program in action by going up to the menu bar and selecting Run -> Start (Or simply press the F5 key). You should see the Form1 window appear: This is a fully functional application. You can move it around, minimize and maximize it, and close it down. For you to do this same thing in C++ - the original language most of Windows was written in you would have written hundreds of lines of code. You area already getting to see some of the extreme power VB gives you. Now lets continue with the tutorial.  Lets make this program say hello! On the left side of the screen you can see the toolbox (if this doesn't show up go to the top menu bar and select View -> Toolbox). In this toolbox you will see a picture of a button. Double click the button icon and it will create a Command1 CommandButton in the center of your form.    If you run the program now (Press F5) you will see your window now has a button labeled Command1 in the center of it, but if you click the button it doesn't do anything...

Words: 628 - Pages: 3

Free Essay

Chapter of My... The program is also robust; phpMyAdmin has enough functionality that you can probably create and run a Web site without knowing any SQL. Being free and open-source never hurt anybody, either. For these reasons, most hosting sites include phpMyAdmin in their control panel as the default MySQL administration tool. phpMyAdmin has some nice extras, such as importing and exporting Excel, OpenDocument, and XML files, and a tool that generates a PDF image of your database schema. Visual Basic  According to Laud (2012) Visual Basic is a programming language and integrated development environment (IDE). It derives from the much older BASIC programming language, and so is considered a useful and relatively easy programming language for the beginner to learn. Visual Basic (VB) is now integrated into many different software applications and also web applications. Visual Basic was developed to be easy to learn, with a quick learning curve and a diverse scope of possibilities. Using the Visual Basic software, you can either hard-code or use the developer software to assist you throughout. It's also used to create ActiveX controls (for web usage and other controls), .dll file extensions or executables for standalone operation. LAN (Local Area Network) According to Rouse (2006) a local area network (LAN) is a group of computers and associated...

Words: 1499 - Pages: 6

Premium Essay

Unit 3

...Lab 3: Input, Processing, and Output This lab accompanies Chapter 2 (pp. 56-68) of Starting Out with Programming Logic & Design. Chris Garcia Name: ___________________________ Lab 3.1 – Pseudocode This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Write a program that will take in basic information from a student, including their name and how many credits they have taken in Network Systems Administration program. The program will then calculate how many credits are needed to graduate. Display should include the student name and the number of credits left to graduate. This should be based off a 90 credit program, where some courses are half credits. Step 1: This program is most easily solved using just a few variables. Identify potential problems with the following variables declared in the pseudocode. Assume that the college has the ability to offer half credits. (Reference: Variable Names, page 39-40). |Variable Name |Problem (Yes or No) |If Yes, what’s wrong? | |Declare Real creditsTaken |n | | |Declare Int creditsLeft |y | | |Declare Real studentName ...

Words: 1394 - Pages: 6

Premium Essay


...Lab 4.1 – Pseudocode and Modules (“UTP Installed”) Critical ReviewA Module is a group of statements that exists within a program for the purpose of performing a specific task.Modules are commonly called procedures, subroutines, subprogram, methods, and functions.The code for a module is known as a module definition. To execute the module, you write a statement that calls it.The format for a module definition is as follows:Module name()StatementStatementEtc.End ModuleCalling a module is normally done from the Main() module such as:Call name()Generally, local variables should be used and arguments should be passed by reference when the value of the variable is changed in the module and needs to be retained. For example:Module main()Real Integer numberCall inputData(number)Call printData(number)End Module// Accepts number as a reference so that changed value// will be retainedModule inputData(Real Ref number)number = 20End Module// number does not need to be sent as reference because// number is not going to be modifiedModule printData(Real number)Display “The number is “, numberEnd Module | This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Data Communications Corp wants a small program that will calculate the cost of UTP it installs for their clients. Write a program that will ask the user to input the name of the client, the number of feet of cable installed. The......

Words: 1808 - Pages: 8