Two Forms Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
VB Data Validation Unit 4. Input Validation Validating user input before it is written can improve the quality of the data stored. Good validation schemes.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
Match-and-Stop Search Will find FIRST match Use Boolean variable to denote whether a match has been found or not Found initially False If a match is found,
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
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.
Control Arrays, Records, and Record Arrays in V.B. Week 10.
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.
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Handling of data from multiple databases. Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application.
A453 Exemplar Password Program using VBA
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Using Arrays and File Handling
InvEasy (Project1) Please use speaker notes for additional information!
Break Processing Please use speaker notes for additional information!
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Visual Basic Games: Prepare for Hangman
Chapter 7 Code Tables. VB Code Box 7-1 Event Procedure for Compute Button Private Sub hsbExemptions_Change() txtExemptions.Text =Str(hsbExemptions.Value)
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Logic Structure - focus on looping Please use speaker notes for additional information!
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
Array - adding to array at run time Please see speaker notes for additional information!
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.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
© 1999, by Que Education and Training, Appendix A, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
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!
Chapter Two Creating a First Project in Visual Basic.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Delivery and other DO Examples Please use speaker notes for additional information!
Notes on ADO from other projects Please use speaker notes for additional information!
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
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.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Pay Example (PFirst98) Please use speaker notes for additional information!
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Maximum Profit Please use speaker notes for additional information!
31/01/ Selection If selection construct.
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.
Controlling Program Flow with Looping Structures
05/02/ Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.
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!
Sequential Processing to Update a File Please use speaker notes for additional information!
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
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.
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Visual Basic - Break Processing
Processing multiple files
Find, filter etc with connection to Access code internally
Department Array in Visual Basic
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Please use speaker notes for additional information!
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Please see speaker notes for additional information!
Presentation transcript:

Two Forms Please use speaker notes for additional information!

2 Forms On the first form, Next will bring up the second form. On the second form, Previous will bring up the first form.

2 Forms

prSrchCr

First I entered the course number that I want to search for. The retrieval is successful and comes back with the name of the course.

prSrchCr This time when I entered CIS67 and clicked retrieve, the course name came back with Invalid Course Number and a message box screen with option Yes/No appeared asking me whether I want to add a course. I responded Yes. I entered in the new course information and clicked Add Course. Note that the new course is added.

prSrchCr In this case I want to add CIS45. I enter the data and click Add Course and the course is added.

frmSrhCr Option Explicit Dim CourseFile As String Dim crsArray(1 To 20) As String Dim numCrs As Integer Private Sub cmdClear_Click() txtCrsNum.Text = "" txtCrsName.Text = "" txtCrsNum.SetFocus End Sub Private Sub cmdExit_Click() End End Sub Private Sub Form_Load() Dim ptr As Integer CourseFile = App.Path & "\CISCrs.txt" ptr = 1 Open CourseFile For Input As #1 Do While Not EOF(1) And ptr < (UBound(crsArray) + 1) Input #1, crsArray(ptr) ptr = ptr + 1 Loop numCrs = ptr - 1 Close #1 End Sub A course array is set up to hold 20 courses - that is all I can handle in this program. When I load the form, I open the file that contains the course code and course name and move the information into the array. The DO loop will continue while it is not EOF and the ptr is less than the upper bound of the array + 1. In this case that would be 21 so as long as the ptr is less than that I can add to the array.

CISCrs.txt The records each contain one element or field which is compatible with moving the data into the array.

prSrchCr Private Sub cmdRetrieve_Click() Dim wrkInd As String, ptr As Integer Dim AddCrsResp As Integer wrkInd = "N" ptr = 1 Do While wrkInd = "N" And ptr < (UBound(crsArray) + 1) If UCase(txtCrsNum.Text) = UCase(Left(crsArray(ptr), 5)) Then wrkInd = "Y" Else ptr = ptr + 1 End If Loop If wrkInd = "Y" Then txtCrsName.Text = Mid(crsArray(ptr), 7) cmdClear.SetFocus Else txtCrsName.Text = "Invalid Course Number" AddCrsResp = MsgBox("Add Course?", vbYesNo) If AddCrsResp = vbYes Then Rem frmCIS.Show vbModal, Me frmCIS.Show vbModal Call Form_Load End If cmdClear_Click End If End Sub Set up an indicator and ptr to search the array. DO while loop that looks for a match. This puts up a box that gives a yes/no choice - vbYesNo. If they respond yes (vbYes) then the next form is shown. The next form is shown. By using vbModal, the user has to make a response or do something to exit the form. After the processing is accomplished, I call Form_Load to load the information into the array.

Option Explicit Dim crsArray(1 To 20) As String Dim numCrs As Integer Dim CourseFile As String Private Sub cmdDisp_Click() Dim ptr As Integer picArrayDisp.Cls For ptr = 1 To numCrs picArrayDisp.Print crsArray(ptr) Next ptr txtNewCrsNum.SetFocus End Sub Private Sub CmdStop_Click() txtNewCrsNum.Text = "" txtNewCrsName.Text = "" Me.Hide End Sub Private Sub Form_Load() CourseFile = App.Path & "\CISCrs.txt" Open CourseFile For Input As #1 numCrs = 0 Do Until EOF(1) Or numCrs = UBound(crsArray) numCrs = numCrs + 1 Input #1, crsArray(numCrs) Loop Close #1 End Sub frmCIS In this program, I have associated an array with each form so they are not required to pass information between forms. In the form load, this array is filled. This code simply displays the courses in the picture box being used for that purpose. If the user clicks stop, the text boxes for course number/code and name are set to null and the form is hidden using Me.Hide.

Private Sub cmdAddCrs_Click() Dim wrkhold As String, newhold As String Dim ptr As Integer, ct As Integer If numCrs = UBound(crsArray) Then MsgBox "Array is full", vbOKOnly, "Error" Else newhold = UCase(Left(txtNewCrsNum.Text, 3)) _ & Right(txtNewCrsNum.Text, 2) _ & " " & txtNewCrsName.Text For ptr = 1 To numCrs If Left(crsArray(ptr), 5) >= Left(newhold, 5) Then wrkhold = crsArray(ptr) crsArray(ptr) = newhold newhold = wrkhold End If Next ptr numCrs = numCrs + 1 crsArray(numCrs) = newhold Open CourseFile For Output As #1 ptr = 0 Do Until ptr = numCrs ptr = ptr + 1 Write #1, crsArray(ptr) Loop Close #1 Call cmdDisp_Click End If End Sub frmCIS If the course array is at its upper bound, no course can be added. Establishes course code/number and name as a string in the hold area. Goes through the array and inserts the add in the appropriate place. Writes the changed array to the disk file. When we go back to the original form we will process the Call to Form_Load which will fill the array on the original form with the data from the file. Calls the display routine.

prSrcjCr3.vbp frmSrhCr2.frm prSrcjCr3.vbp frmSrhCr2.frm

prSrchCr3.vbp frmCIS3.frm prSrchCr3.vbp frmCIS3.frm

prSrchCr3.vbp FileHandlr2.bas prSrchCr3.vbp FileHandlr2.bas

prSrcjCr3.vbp frmSrhCr2.frm prSrcjCr3.vbp frmSrhCr2.frm Option Explicit Private Sub cmdClear_Click() txtCrsNum.Text = "" txtCrsName.Text = "" txtCrsNum.SetFocus End Sub Private Sub cmdExit_Click() End End Sub Private Sub Form_Load() Call Load_File End Sub When the call is made to Load_file it is executing Load_File which is part of FileHandlr2.bas.

Private Sub cmdRetrieve_Click() Dim wrkInd As String, ptr As Integer Dim AddCrsResp As Integer wrkInd = "N" ptr = 1 Do While wrkInd = "N" And ptr < (UBound(crsArray) + 1) If UCase(txtCrsNum.Text) = UCase(Left(crsArray(ptr), 5)) Then wrkInd = "Y" Else ptr = ptr + 1 End If Loop If wrkInd = "Y" Then txtCrsName.Text = Mid(crsArray(ptr), 7) cmdClear.SetFocus Else txtCrsName.Text = "Invalid Course Number" AddCrsResp = MsgBox("Add Course?", vbYesNo) If AddCrsResp = vbYes Then frmCIS2.Show vbModal, Me End If cmdClear_Click End If End Sub prSrcjCr3.vbp frmSrhCr2.frm prSrcjCr3.vbp frmSrhCr2.frm Shows the second form.

prSrchCr3.vbp frmCIS3.frm prSrchCr3.vbp frmCIS3.frm Option Explicit Private Sub cmdDisp_Click() Dim ptr As Integer txtCrsNames.Text = "" For ptr = 1 To UBound(crsArray) txtCrsNames.Text = txtCrsNames.Text _ & crsArray(ptr) & vbCrLf Next ptr txtNewCrsNum.SetFocus End Sub Private Sub CmdStop_Click() Call Clear_Text Me.Hide End Sub Private Sub Clear_Text() txtNewCrsNum.Text = "" txtNewCrsName.Text = "" End Sub Private Sub Form_Activate() txtNewCrsNum.Text = frmSrhCr2!txtCrsNum.Text End Sub When the form is activated, the form will receive the txtCrsNu.text from the fromSrhCr2 and store it in txtNewCrsNum.text. This is a way of passing data between forms.

Private Sub cmdAddCrs_Click() Dim wrkhold As String, newhold As String Dim ptr As Integer, ct As Integer Dim ErrFlg As Boolean ErrFlg = False If txtNewCrsNum.Text = "" _ Or txtNewCrsName.Text = "" Then ErrFlg = True Else newhold = UCase(Left(txtNewCrsNum.Text, 3)) _ & Right(txtNewCrsNum.Text, 2) _ & " " & txtNewCrsName.Text For ptr = 1 To UBound(crsArray) If Left(crsArray(ptr), 5) > Left(newhold, 5) Then wrkhold = crsArray(ptr) crsArray(ptr) = newhold newhold = wrkhold Else If Left(crsArray(ptr), 5) = Left(newhold, 5) Then MsgBox "Course already exists", vbOKOnly, "Error" ptr = UBound(crsArray) ErrFlg = True End If Next ptr End If If ErrFlg = False Then ReDim Preserve crsArray(UBound(crsArray) + 1) crsArray(UBound(crsArray)) = newhold Call Write_File Call cmdDisp_Click End If Call Clear_Text txtNewCrsNum.SetFocus End Sub prSrchCr3.vbp frmCIS3.frm prSrchCr3.vbp frmCIS3.frm I have set up an error flag (ErrFlg) that will be used to test conditions. If I successfully added an element to the array. The last step was completed in this code. Then I called the Write_file which is in FileHandlr2.bas. This routine will write the updated array to the file.