VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.

Slides:



Advertisements
Similar presentations
Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
Advertisements

Multiple Forms, Standard Modules, And Menus
Practical Programming COMP153-08S Lecture: Repetition Continued.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
.NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically. –Programming in.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Odds and Ends Component Tray Menu and contextmenu Splash Screen.
Chapter 5 - Menus, Sub Procedures, and Sub Functions  Menus - controls - properties and events –menu editor - create and change –defining menus - menu.
Multiple Forms & Procedures. Form Methods: –Show, Hide, Activate, Close Events: –Load, Activated, Closing, Closed.
VB.Net Introduction. .NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically.
Customizing Menus and Toolbars. Manipulating Command Bars Customize: –Right-click any place on a command bar and cick Customize … Customize window: –Toolbars,
Creating Menu. Objectives Create a menu system for a form –Create a menu –Create a menu titles –Create a menu items –Create a submenu –Modify menu –Edit.
VB.Net Introduction. .NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically.
VB.Net Introduction. Visual Studio 2010 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# or VB –Windows.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Apply Sub Procedures/Methods and User Defined Functions
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 6 Procedures and Functions Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Multiple Forms, Standard Modules, And Menus
Why to Create a Procedure
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Lecture 8 Visual Basic (2).
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Tutorial 6 The Repetition Structure
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
3.2 VB.NET Events An Event Procedure Properties and Event Procedures of the Form Tab Order of Controls Exercises.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Menus Menus provide groups of related commands for windows applications Menu, menu items, submenus A menu item that contains a submenu is considered to.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
VB.Net Introduction. Visual Studio 2008 It supports VB.Net, J#, C#, and C++. Demo: –Start page: Recent projects –Starting project: File/New Project/Project.
CONTROL STATEMENTS. A conditional expression uses a comparison operator which results in true or false value. If the comparision is valid it results in.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Computer Science Up Down Controls, Decisions and Random Numbers.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Chapter 7, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 7 Multiple Forms, Standard Modules, And Menus.
Sub Procedures And Functions
Visual Basic Fundamental Concepts
Introduction to VB programming
للمزيد زورونا على موقعنا الإلكتروني:
Visual Basic..
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
CIS16 Application Development and Programming using Visual Basic.net
VB.Net Introduction.
STARTING OUT WITH Visual Basic 2008
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

VB Procedures

Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form. Public: Can be accessed by procedures in other forms. To call a sub procedure SUB1 Call SUB1(Argument1, Argument2, …)

Function Private Function tax(salary) As Double tax = salary * 0.1 End Function –Or Private Function tax(salary) Return salary * 0.1 End Function

Creating a IsAlphaNumeric(string) Function IsNumeric: test a string IsDigit, IsLetter, IsLetterOrDigit: test a char –Char.IsLetterOrDigit(char)

Function IsAlphaNumeric(ByVal aString As String) As Boolean Dim i As Integer = 0 Dim AlphaNumeric As Boolean = True For i = 0 To aString.Length - 1 If Not Char.IsLetterOrDigit(aString.Substring(i, 1)) Then AlphaNumeric = False Exit For End If Next If AlphaNumeric = True Then IsAlphaNumeric = True Else IsAlphaNumeric = False End If End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If IsAlphaNumeric(TextBox1.Text) Then MessageBox.Show("textbox1 is alphanumeric") Else MessageBox.Show("textbox1 is not alphanumeric") End If End Sub

Call by Reference Call by Value ByRef –Default –The address of the item is passed. Any changes made to the passing variable are made to the variable itself. ByVal –Only the variable’s value is passed.

ByRef, ByVal example Private Sub Command1_Click() Dim myStr As String myStr = TextBox1.Text ChangeTextRef (myStr) TextBox1.Text = myStr End Sub Private Sub ChangeTextRef(ByRef strInput As String) strInput = "New Text" End Sub

Input, Output Arguments Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sal, tax As Single sal = CSng(TextBox1.Text) Call CalTax(sal, tax) TextBox2.Text = tax.ToString End Sub Private Sub CalTax(ByVal Salary As Single, ByRef Tax As Single) Tax = 0.1 * Salary End Sub Can we pass the Tax ByVal?

Static Variables Static VariableName as DataType Static variables are local variables but are not destroyed when a procedure terminates. Their value are kept.

Static Variable Example Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Static clickCounter As Integer = 0 clickCounter += 1 If clickCounter > 3 Then MsgBox("Sorry, you can only click 3 times!") Button1.Enabled = False End If End Sub

Event Procedures Example: –Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click The Handles keyword –Procedure name may change Handling multiple events: –Private Sub AllButtons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.CLick

Using One Event Handler to Handle Events Generated by Many Controls Assume we have 3 buttons. Use the Handles clause in the event procedure to associate controls with the event procedure. We can assign a value for each control’s Tag property, or use control’s TabIndex property to determine which control generates the event.

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click If sender.tag = "1" Then MessageBox.Show("button 1 clicked") ElseIf sender.tag = "2" Then MessageBox.Show("button 2 clicked") Else MessageBox.Show("button 3 clicked") End If End Sub Note: VB IntelliSense will not show the Tag property after you type sender.

Early Binding/Late Binding Early binding: VB compiler knows the object’s data type. It enables the use of IntelliSense. Late binding: VB compiler can’t determine the type of object that we are calling. This occurs because the object is declared as Object data type.

Demo: Phone Simulator

Menu

Main Menu Control –Add MainMenu control and follow the TypeHere instruction. –Each submenu and each item on a submenu is represented by a MenuItem control. –Use an & to specify an access key in the caption. Ex. &File, Sho&s –Write an event procedure for each menu item.

Shortcut keys –Select the Shortcut key property in the MenuItem’s property window. –Select the Shorcut key from list. –Set ShowShortcut property to true. Separator bar –Right clock a menu item/Insert Separator Inserting, deleting a menu item –Right click and select the option. Rearranging menu items –dragging

Context Menu A context menu is a menu that displays when an object on the screen is right- clicked. Add the ContextMenu control (it is placed in a tray under the form). Right-click the control and choose Edit to create the menu. Use the object’s ContextMenu property to bind the object to the context menu.

Simple Text Editor Textbox’s properties, methods –Help –Object Browser System.Windows.Forms –Cut, Copy, Paste, Undo, SelectAll, etc. Menu: Undo, Copy, Cut, Paste, SelectAll, Search Clipboard: –Clipboard.SetDataObject(TextBox1.SelectedText) –Clipboard.GetDataObject()

FontDialog Control If FontDialog1.ShowDialog() = DialogResult.OK Then TextBox1.Font = FontDialog1.Font End If