Multiple forms - SDI & MDI Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Interfacing with the User Advanced Programming Using Visual Basic 6.0.
VBA Modules, Functions, Variables, and Constants
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
InvEasy (Project1) Please use speaker notes for additional information!
MDI vs. SDI MDI – Multiple Document Interface SDI – Single Document Interface In an SDI application, each form acts independently of the others. A MDI.
Break Processing Please use speaker notes for additional information!
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 7 Code Tables. VB Code Box 7-1 Event Procedure for Compute Button Private Sub hsbExemptions_Change() txtExemptions.Text =Str(hsbExemptions.Value)
Chapter 4: The Selection Process in Visual Basic.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
The Repetition Process in Visual Basic. The Repetition Process The capability to repeat one or more statements as many times as necessary is what really.
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
Array - adding to array at run time Please see speaker notes for additional information!
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Do Loop with Interest Please see speaker notes for additional information!
Chapter Six: Working With Arrays in Visual Basic.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
MDI with Menu Please use speaker notes for additional information!
Random Files Please see speaker notes for additional information!
Applications Development
Delivery and other DO Examples Please use speaker notes for additional information!
Two Forms Please use speaker notes for additional information!
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Pay Example (PFirst98) Please use speaker notes for additional information!
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Programming with Microsoft Visual Basic th Edition
CONTROL STATEMENTS. A conditional expression uses a comparison operator which results in true or false value. If the comparision is valid it results in.
31/01/ Selection If selection construct.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Using a Database Access97 Please use speaker notes for additional information!
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Processing multiple files
Multiple Forms and Menus
Visual Basic Fundamental Concepts
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
Visual Basic..
Department Array in Visual Basic
البرمجة بلغة فيجول بيسك ستوديو
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Introduction to Computer Programming IT-104
Presentation transcript:

Multiple forms - SDI & MDI Please use speaker notes for additional information!

MuffinsM1.vbp

Const cDisc As Currency = 0.95 Dim wrkAmountDue As Currency Option Explicit Private Sub cmdHelp_Click() 'this brings up a form that provides help frmHelp.Show vbModal End Sub Private Sub cmdClear_Click() Dim ctclear As Integer txtQuan.Text = "" txtAmtDue.Text = "" chkDozen.Value = Unchecked Do While ctclear < 5 optMuffin(ctclear).Value = False ctclear = ctclear + 1 Loop End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdSum_Click() frmSummary.Show vbModal End Sub The summary is shown in vbModal which means the user must act before another form can be accessed. In this case, the user must click Okay. MuffinsM1.vbp This routine clears the information off the form. Notice that I am setting all options to false. I could have chosen to make the first option true to have a default. The Help form is shown in vbModal which means the user must click the Okay. I am defining cDisc as a constant equal to.95. Help defines a constant as “A named item that retains a constant value throughout the execution of a program.”

Private Sub cmdCalc_Click() Const ConstNum = "Please enter a number!" Dim wrkPrice As Currency Dim wrkFound As String Dim ct As Integer Dim priceArray As Variant priceArray = Array(".85", ".75", "1.00", ".90", ".90") If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR" Else ct = 0 wrkFound = "F" Do While ct < 5 And wrkFound = "F" If optMuffin(ct).Value = True Then wrkPrice = Val(priceArray(ct)) wrkFound = "T" Else ct = ct + 1 End If Loop If wrkFound = "F" Then MsgBox "Please select muffin", vbOKOnly, "SELECT" End If wrkAmountDue = wrkPrice * Val(txtQuan.Text) If chkDozen.Value = Checked Then wrkAmountDue = wrkAmountDue * cDisc End If txtAmtDue.Text = Format(wrkAmountDue, "Currency") If wrkAmountDue > gHighestSale Then gHighestSale = wrkAmountDue End If gTotal = gTotal + wrkAmountDue wrkAmountDue = 0 gCustomerCount = gCustomerCount + 1 End Sub This sets up an array which contains the prices. This goes through checking to see which muffin option has been checked. When a match is found the corresponding price is taken from the array and the indicator is set to T which ends the loop. If a match is not found, then an error message is displayed. This routine compares the calculated amount to the gHighestSale in the bas module. If it is greater, the current amount replaces the amount in the module. Then the totals are accumulated.

'Standards in naming can be helpful, for example public or global variables can start with g 'while a variable that is at the module level only can start with m - note that p can mean 'public - different companies can and will have their own internal standards for variable 'naming Public gTotal As Currency Public gHighestSale As Currency, gCustomerCount As Integer Sub Main() 'The splash screen should be loaded initially and displayed until the user clicks Okay frmSplash.Show End Sub This is the bas module. It shows the splash screen. Note that SubMain is the startup object.

This is using the Form-Activate event.

MuffinM2.vpb

Private Sub mnuAbout_Click() Call cmdHelp_Click End Sub Private Sub mnuCalculate_Click() 'You can also enable things using mnuCalculate.Enabled = True 'or make then unenabled with mnuCalculate.Enabled = False. 'Here I am using the checked feature to check calculated because 'I am currently in that routine. I do this by setting Checked = 'True - I also want to uncheck other features so I set Checked = 'False. mnuCalculate.Checked = True mnuSummary.Checked = False mnuClear.Checked = False mnuExit.Checked = False Call cmdCalc_Click End Sub Private Sub mnuClear_Click() mnuCalculate.Checked = False mnuSummary.Checked = False mnuClear.Checked = True mnuExit.Checked = False Call cmdClear_Click End Sub Private Sub mnuExit_Click() End End Sub Private Sub mnuSummary_Click() mnuCalculate.Checked = False mnuSummary.Checked = True mnuClear.Checked = False mnuExit.Checked = False Call cmdSum_Click End Sub

Private Sub mnuCalculate_Click() mnuCalculate.Checked = True mnuSummary.Checked = False mnuClear.Checked = False mnuExit.Checked = False Call cmdCalc_Click End Sub MuffinM2.vpb

MuffinM2Popup.vbp Visible is unchecked on Popup, however it is checked on all of the menu items that are under popup - calculate, summary, clear etc.

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then PopupMenu Popup End If End Sub If the mouse is down on the form, I check to see if it is the right mouse button, if it is I bring up the PopupMenu which is named Popup. Private Sub popClear_Click() mnuCalculate.Checked = False mnuSummary.Checked = False mnuClear.Checked = True mnuExit.Checked = False Call cmdClear_Click End Sub Private Sub popExit_Click() End End Sub Private Sub mnuSummary_Click() mnuCalculate.Checked = False mnuSummary.Checked = True mnuClear.Checked = False mnuExit.Checked = False Call cmdSum_Click End Sub Private Sub popSummary_Click() mnuCalculate.Checked = False mnuSummary.Checked = True mnuClear.Checked = False mnuExit.Checked = False Call cmdSum_Click End Sub Private Sub popCalculate_Click() mnuCalculate.Checked = True mnuSummary.Checked = False mnuClear.Checked = False mnuExit.Checked = False Call cmdCalc_Click End Sub

PRMuffinsMDI.vbp frmHelp and frmSplash are regular forms - note the icon. frmMainMDI is a parent MDI form - note the icon. frmMuffins and frmSummary are child MDI forms - note the icon ModuleM1.bas is a bas module

PRMuffinsMDI.vbp

Note that I have both the Muffins form and the Summary form opened within the parent window (Main-MDI) - Main has the menu that we will be using.

PRMuffinsMDI.vbp

Private Sub mnuBuy_Click() frmMuffins.Show frmMuffins.SetFocus End Sub Private Sub mnuCascade_Click() frmMainMDI.Arrange vbCascade End Sub Private Sub mnuDesribe_Click() frmHelp.Show End Sub Private Sub mnuExit_Click() End End Sub Private Sub mnuSummary_Click() frmSummary.Show frmSummary.SetFocus End Sub PRMuffinsMDI.vbp Private Sub mnuTileHorizontally_Click() frmMainMDI.Arrange vbTileHorizontal End Sub Private Sub mnuTileVertically_Click() frmMainMDI.Arrange vbTileVertical End Sub

Const cDisc As Currency = 0.95 Dim wrkAmountDue As Currency Option Explicit Private Sub cmdCalc_Click() Const ConstNum = "Please enter a number!" Dim wrkPrice As Currency Dim wrkFound As String Dim ct As Integer Dim priceArray As Variant priceArray = Array(".85", ".75", "1.00", ".90", ".90") If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR" Else ct = 0 wrkFound = "F" Do While ct < 5 And wrkFound = "F" If optMuffin(ct).Value = True Then wrkPrice = Val(priceArray(ct)) wrkFound = "T" Else ct = ct + 1 End If Loop If wrkFound = "F" Then MsgBox "Please select muffin", vbOKOnly, "SELECT" End If PRMuffinsMDI.vbp

wrkAmountDue = wrkPrice * Val(txtQuan.Text) If chkDozen.Value = Checked Then wrkAmountDue = wrkAmountDue * cDisc End If txtAmtDue.Text = Format(wrkAmountDue, "Currency") If wrkAmountDue > gHighestSale Then gHighestSale = wrkAmountDue End If gTotal = gTotal + wrkAmountDue wrkAmountDue = 0 gCustomerCount = gCustomerCount + 1 txtQuan.SetFocus End Sub Private Sub cmdClear_Click() Dim ctclear As Integer txtQuan.Text = "" txtAmtDue.Text = "" chkDozen.Value = Unchecked Do While ctclear < 5 optMuffin(ctclear).Value = False ctclear = ctclear + 1 Loop End Sub PRMuffinsMDI.vbp

Private Sub Form_Activate() Dim wrkAverage As Currency Dim wrkMsgStr As String Dim fmtwrkHighestSale As String, fmtwrkAverage As String txtHighSale = Format$(gHighestSale, "Currency") If gCustomerCount > 0 Then wrkAverage = gTotal / gCustomerCount fmtwrkAverage = Format$(wrkAverage, "Currency") txtAvgSale = fmtwrkAverage Else txtAvgSale = 0 End If End Sub PRMuffinsMDI.vbp The code on the Summary Form is executed when the form is activated. Note there is no exiting of this form. If the user wants to continue the buying of muffins, they should select Buy from the menu on the parent form. Note that the user can also switch forms by clicking on the form by name in the Windows menu option.

PRMuffinsMDI1.vbp frmMainMDI is the parent MDI form frmMuffins, frmSummary and frmHelp are Child forms. frmSplash is not part of the MDI group, it stands alone

PRMuffinsMDI1.vbp

Private Sub mnuExit_Click() 'Unload frmHelp 'Unload frmMainMDI 'Unload frmMuffins 'Unload frmSummary Dim AForm As Form For Each AForm In Forms Debug.Print Aform.name Unload AForm Next End End Sub PRMuffinsMDI1.vbp This loop unloads each form which has been named Aform that is in the collection Forms by looping through and unloading them one at a time. When I look at the Intermediate Window, I see the following: frmMainMDI frmMuffins frmSummary frmHelp