User Forms.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Excel and VBA Creating an Excel Application
VB Controls and Events Week 7: Picture Box, Image Box, Option, Check box, Mouse over, Frames, Shapes.
Visual Basic.net IDE. Integrated Development Environment.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
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,
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
XP Week 6 – ABC By Aurino Djamaris Bakrie School of Management.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Lab 9 – User Forms Design. User Forms What are user forms? –Known as dialog boxes –Major ways for getting user input An example of using user forms: Monthly.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
IN THE NAME OF ALLAH UserForms on VBA Lab 06 Tahani Al_dweesh.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
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”
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
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.
The Object Model. You can think of the contents of an Excel application as a hierarchy of collections of objects, manipulated by code Each object can.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
Lab 10. User Forms Design – Code Part ► Lab 9 Review ► Continue ‘Student Record’ Example ► A Car Loan Application.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Introducing UserForms Joanna Wyrobek 1. Ms Excel UserForms A UserForm object is a window or dialog box that makes up part of an application's user interface.
Working with UserForms Dr Joanna Wyrobek 1. Displaying a modeless UserForm By default, UserForms are displayed modally. This means that the UserForm must.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
3.02 APPLY PROPERTIES ASSOCIATED WITH THE CONTROLS Computer Programming I.
Visual Basic Fundamental Concepts
Excel Tutorial 8 Developing an Excel Application
Visual Basic.NET Windows Programming
VBA - Excel VBA is Visual Basic for Applications
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Computing with C# and the .NET Framework
3.01 Apply Controls Associated With Visual Studio Form
How to design a Windows Forms application
CHAPTER FIVE Decision Structures.
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Apply Procedures to Develop Menus, List Box and Combo Box Objects
VB 6.0.
Introducing VBA Macros
CHAPTER FIVE Decision Structures.
Variables and Arithmetic Operations
Visual Basic..
Custom dialog boxes Unit objectives
Visual Basic.
Department Array in Visual Basic
Chapter 6 - Visual Basic Schneider
Hello World in Visual Basic
P.J.Balakumaran, AP, Commerce CA, SNMV CAS
Visual Studio.
Web Development Using ASP .NET
Visual C# - GUI and controls - 1
Group Boxes, Radio buttons and Checked List Boxes
Week 2: WINDOWS PROGRAMMING
Presentation transcript:

User Forms

Designing User Forms What you need to know: Open Excel > Alt+F11 puts you in the VBA Editor Make sure the Project Explorer and Properties windows are visible. Insert/UserForm menu will add a form. A blank user form will appear. The Toolbox should also appear. If it disappears it can be redisplayed using the View/Toolbox menu item. What you need to know: 1. Which controls are available. 2. How to place, resize, and line up controls on the form. 3. How to give controls properties in the Properties window.

Available Controls The available controls are displayed in the Toolbox. The arrow at the top left is used only for pointing. First row: Label, TextBox, ComboBox, ListBox Second row: CheckBox, OptionButton, ToggleButton, Frame, CommandButton Third row: TabStrip, MultiPage, ScrolBar, SpinButton, Image Fourth row: RefEdit These controls have certain behaviors built into them. Example: if you have several radio buttons on the form, the user will only allowed to select one at time.

Functionality of Frequently Used Controls CommandButton-used to run subprocedures Label-used mainly for explanations and prompts TextBox-used to let the user input information to be used in the macro ListBox-used to let the user choose one or more items from a list or output results to the control ComboBox-similar to a list box, except that the user can type an item that isn’t on the list in a box CheckBox-lets the user check whether an option is desired or not (any or all can be selected) OptionButton-lets the user check which of several options is desired (only one of a set of option buttons can be checked at a time) Frame-usually used to group a related set of options buttons, but can be used to organize any set of controls into logical groups RefEdit-similar to a TextBox control, but used specifically to lwt the user highlight a worksheet range

Adding Controls to a User Form and Setting Properties Add a control to a user form, click on control in Toolbox and then drag a shape on the form. Once the control is on the form, you can resize it and drag it to a different location. Depending on the control, there is generally a label that is visible to the user and a name for the actual object. These two items are found in the properties window. Color can also be added to the control using the properties window. You change a property by clicking on the object and the properties window becomes visible.

Commonly Used Control Name Prefixes CommandButton-cmd Label-lbl TextBox-txt ListBox-lst ComboBox-cbo CheckBox-chk OptionButton-opt Frame-fra Form-frm

Points of Interest Tab order is a characteristic which allows you to control how the user can tab from one control to the next. The tab order is controlled by the TabIndex property. The TabStop property set to False will not allow a tab action on that control. The Run Sub/UserForm button can be used to test the form. Note: the InputBox and MsgBox can also be used.

Writing Event Code for User Forms Much of Windows programming is built around events, An event occurs whenever the user does something (generally a click event). The events have built-in event handling. You can add code to the sub which will execute desired actions. These subs are always available if you want the program to react to certain events.

Writing Event Code for User Forms Code to this point have been added by creating a subprocedure in the code window. Event code is not placed in this area but is placed in a user form’s code window. To get to a user form’s code window, make sure you are viewing the form’s design window. Select the View/Code menu item. In general, the View/Code and View/Object (F7 or Shift-F7) will toggle between the form’s design and its code window.

Object Browser and Controls The control sub will have the following parts: control name, underscore, event type and it must contain any arguments that are given. If you want to know what a particular control responds to, you can use the Object Browser. Open the Object Browser and select the MSForms library. The library provides help for all objects in the user form. It provides a list of controls on the left and their properties, methods, and events on the right. The events are designated by lightning icons. By selecting any of these and clicking on the question mark button, you can get plenty of help.

Avearge UserForm Code Example Private Sub cmdClear_Click() lstOut.Clear ‘clear the list box txtSize.Text = "" ‘clear the text box txtSize.SetFocus ‘set mouse focus to text box End Sub Private Sub cmdAverage_Click() Dim Input1 As Integer, x As Integer, Sum As Integer, Average As Double, Array1() As Integer, _ Size As Integer, count As Integer Size = txtSize.Text count = 1 ReDim Array1(Size) For x = 1 To Size Array1(x) = InputBox("Enter your data here:", "INPUT") Sum = Sum + Array1(x) Next Average = Sum / Size lstOut.AddItem ("The Input #" & count & " is " & Array1(x)) ‘adds items to the list box count = count + 1 lstOut.AddItem ("The Average is " & Average) ‘add the message and value to list box

Completed User Form

Looping Through the Controls on a User Form Dim ctl As Control For Each ctl In Me.Controls If TypeName(ctl) = “TextBox” Then If ctl.Value = “” Or Not IsDate(ctl) Then MsgBox “Enter valid dates in the text boxes.”, _ vbInformation, “Invalid entry” ctl.SetFocus Exit Sub End If Next