STATE UNIVERSITY OF NEW YORK

COLLEGE AT OLD WESTBURY

 

BU 3015                                                                       

Visual Basic                                                                   

Spring  2006 (TUE/THU 1:00pm-2::40pm)                          

 

Dr. A. Ebrahimi

Office:                 D222
Office Number:    (516) 876 - 8594
E-mail:
               ebrahimia@oldwestbury.edu

Site:                    www.drebrahimi.com     www.programmingeasyways.com

Office Hours:       Tuesday-Thursday       (2:45pm-3:45pm AND 8:10pm - 8:40pm)
                           Monday-Wednesday    (7:15pm-8:15pm AND 7:50pm - 8:20pm)

 

Required Text: Visual Basic .NET Schneider, David

References: C++ Programming Easy Ways (Volume 1 & 2) Dr. A. Ebrahimi, American Press

  VISUAL BASIC TRIAL BETA VERSION http://lab.msdn.microsoft.com/express/vbasic/
 

Winter 2006 Notes

Sample Chapters Visual Basic .Net Programming Easy Ways
Chapter One
, Chapter Two, Chapter Three Chapter Four Chapter FiveChapter Nine, Sample Test Sample/True/False Test

TEST 3

A.1. Course Description:

Students will learn how to develop software business applications using event-driven programming and graphical user interface provided by Visual Basic.

A.2. Intended Audience:  MIS and CS majors

A.3. Course Objectives:

Students will learn how to work with the Visual Basic .NET, be able to use Visual Basic with database such as Access, incorporate Visual Basic tools in their project.

B. Course Prerequisites: CS 1500 or equiv

C. Mode of Instruction:

The class consists of both lecture and lab. During the lab, there will be demonstrations using the Visual Basic environment, as well as writing, testing, and debugging programs.

D. Student Responsibilities:

  1. Each student will be expected to complete a series of lab assignments for each topic and one large project, preferably payroll or invoice.
  2. There will be a test, midterm and final exam.
  3. Students must plan to spend a minimum of two (2) hours per week outside of the class working with computer.

E. Grading:

Test and Midterm

30%

Assignments & projects

25%

Final Exam

30%

Class Work & Attendance

15%

 

Total

 

 

100%

Course grades will be assigned according to the following scale:

92 - 100 %

A

89 - 91 %

A-

86 - 88 %

B+

82 - 85 %

B

79 - 81 % B-
76 - 78 % C+
73 - 75 % C
69 - 72 % C-
66 - 68 % D+
62 - 65 % D
59 - 61 % D-

58% and Below

F

 

Course Policies:

Four or more absences may lead to failure
All work submitted for grading must be the student's own.
Student is responsible to obtain missing works
Each assignment is due one week (2 classes) later.
The assignment will not be accepted after it has been solved.
Each week a late assignment will be divided by 2.

Main Topics:

Weeks:

Topic:

Programs:

Tue Jan 24,
Thu Jan 26
 

 A Brief History on Programming Languages and Visual Basic

Intro to Visual Basic environment
Opening a new Visual Basic project

VB controls (Text Boxes, Command Buttons, Labels, Picture Boxes) and their properties
Designing a user interface
Adding a Form, working with multiple forms
Modifying control properties in VB code

 Create, compile,  and run VB program
Designing a menu for ATM or bank program

Tue Jan 31
Thu Feb 02
 

Calculations in VB

Declaring variables

 Creating a calculator in VB

Tue Feb 07,
Thu Feb 09
 

 Input Box, Message Box
Strings
Programming Visual Basic Events

 Simple payroll application with fixed tax rate

Tue Feb 14,
Thu Feb 16
 

 Decision making: If ... Then statement
Select Case Blocks

 Extend the payroll program, to compute, over time pay, and tax amount with variable tax rates

Tue Feb 21,

Thu Feb 23
 

 Repetition: loop constructs

 

Tue Feb 28,

Thu Mar 02
 

Arrays: Creating and accessing arrays
Parallel arrays
Simple Search program

 Translator Program
Assignment on creating a telephone directory using arrays
 

Tue Mar 07
Thu Mar 09

 

Sequential Files: Creating, writing to, and reading from text files

 

An assignment on file handling

Tue Mar 14,
Thu Mar 16
 

Spring Recess

 

 

Tue Mar 28,
Thu Mar 30

 

More on files

Additional Controls (Check Boxes, Radio Buttons, List Boxes, Combo Boxes)

Assignment on creating a search program using file

Tue Apr 04,
Thu Apr 06
 

Sub Procedures
User-defined types

 

Tue Apr 11,
Thu Apr 13
 

Access Database
Tables, Records, and Queries (SQL)
Access and Visual Basic

 Assignment using database

Tue Apr 18,
Thu Apr 20
 

Searching, Modifying, Adding Records of a Database

 

Tue Apr 25,
Thu Apr 27
 

Linking VB to applications (Internet, Excel, Word)
 Intro to HTML and VBScript
 

 

Tue May 2,
Thu May 4
 


Project and Review

 

Tue May 9,
Thu May 11
 

Exams Week
 

Final

 

 

 

BU 3015 Visual Basic  (Midterm Dr. A. Ebrahimi SPRING 06)

 

Answer 4 out of 5 questions. (5 for extra credit)

 

To answer the questions, work with the Visual Basic .Net environment and paste all of your answers (forms and code) into a Word document to print out. (Use Alt + Print Screen to copy forms when program is running)

 

To receive complete points answer each part separately.

Q1a)What is wrong with the following average program?
dim x as integer
dim count as integer
dim avg as single
sum= 0
count=1
while x<>9999
x=inputbox("ENTER A NUMBER")
sum=sum+x
count = count + 1
end while
if count > = 0 then
 avg = sum / count
else
msgbox (" ERROR IN COUNT " )
endif

 

Q1b) Fix the above problem and run the program


Q1c) What is wrong with the following search program?

dim id( ) as integer ={1234, 4567,8901,2468,1357,9764}

dim i,key as integer
for i=1 to id.length-1
key=inputbox("ENTER THE SEARCH KEY")
if  (key=id(i) then
 msgbox ("ID FOUND IN LOCATION" & i)
else
msgbox(" ID IS NOT LISTED")
end if
next

Q1d) Fix the above problem and run the program.

 

Q2a)Design a form called Dr Ebrahimi payroll (instead put your own name). The form has three textbox labeled as EMPLOYEE’S ID, HOURS WORKED and HOURLY RATE. A button known as COMPUE GROSS PAY will compute the gross pay for the employee. The output will be display in a textbox labeled as GROSS PAY.

 

Q2b) Expand the above program to compute the employee’s tax amount. An input text box labeled as TAX RATE is to enter the tax rate for example (The default tax rate will be set in property to 0.30 for 30%). A button known as COMPUTE TAX AMOUNT will figure out the employee’s tax amount. The output will display in a text box labeled as TAX AMOUNT.

Extra credit- Instead of compute button use textchanged(  ) to compute the tax amount.

 

Q2c) Expand the above program to compute the net pay. A button known as COMPUTE NET PAY will compute the net pay. The output will be display in a text box labeled as NET PAY. 

Extra credit- instead of text box numbering such as textbox1.text use a proper name in the properties such as empid.text.

 

Q3A)Expand the above program to repeat for 5 employees. Declares all variables used in the program. Assign each input variable by inputbox (“PLEASE ENTER EMPLOYEE’S ID”). Assign value of each input variable to the respective text box. Similarly assign value of each output 

Variable to the respective text box. Only use one command button captioned as COMPUTE 5 EMPLOYEE.

Q3b) Display the employee counter by a msgbox at the end of each round in the loop or assign the value of the counter variable to a textbox labeled as COUNTER.

Q4c) loop the number of employees interactively by an inputbox. Assign the input value of the input box as a number of the employees. The program will loop depends on the entered value (6 or 10).

Extra credit- program should loop until a sentinel value is entered.

 Q3d) Expand the program to take all the data from the input file called employee.txt

 

Q4a) Modify the above program to use a variable tax rate. Assign the tax rate based on the computed gross pay. Tax rate for gross pay more than $500.00 is 20%, for more than $300.00 is 15%, and 10% for the rest. You can use the following:

 

If ………….Then

                                                          ………….

ElseIf ……. Then

………….

                                                Else

                                                          ………….

End If

 

 

 

Q4b)  Include marital status (Single, Married) as input to your form. You can use a TextBox or RadioButton, etc. For Single employees, additional 10% will be added to the tax rate.  For Married employees, 5% will be subtracted from tax rate.

 

         

Q4c) Error-checking: Use If … Then statements to check for errors on two of the TextBoxes such as hours worked, hourly rate, or gross pay (e.g. hours worked must be greater than 0 and less than 56, and gross pay must be greater than zero, etc.).

 

For example:

 

For hours worked greater than 56, you can display an error message such as MsgBox(“Please enter correct hours worked.”)

 

 

Q5a) Run the following program. Briefly say in your own words what does it do?

 

Create a new project and use your name in the project title, save it on your F: drive (your account). Create a text file called employees.txt and save it desktop or in the “bin” folder of your project. Enter data into your text file including the name and gross pay of employees in the following format:

Andres

1000.00

John

500.00

Lina

750.00

Peter

456.00

Anna

670.00

 

 

 

 

 

 

 

 

Create a form similar to:

 

 

Double-click on the button to write the code:

 

  Dim name As String

        Dim grosspay As Double

        Dim i As Integer

 

        Dim fin As IO.StreamReader = IO.File.OpenText("employees.txt")

 

        For i = 1 To 5

 

            name = fin.ReadLine

            grosspay = fin.ReadLine

 

            If name = TextBox1.Text Then

                TextBox2.Text = FormatCurrency(grosspay)

            End If

 

        Next

 

5b)Explain what this program does and how it works (e.g. what does the loop do, what does the If … Then statement do)

 

 

How to create a text file and write to a file  

dim fout as Io.streamWriter = Io.File.CreateText("employee2.txt)

fout.writeline(textbox1.text)

fout.writeline(textbox2.text)

fout.close

 

 

 

Visual Basic (Bu3035 Fall 04 Dr. A. Ebrahimi

Q1a)What is wrong with the following average program?
dim x as integer
dim count as integer
dim avg as single
sum= 0
count=1
while x<>9999
x=inputbox("ENTER A NUMBER")
sum=sum+x
count = count + 1
end while
if count > = 0 then
 avg = sum / count
else
msgbox (" ERROR IN COUNT " )
endif

 

Q1b) Fix the above problem and run the program


Q2a) What is wrong with the following search program?

dim id( ) as integer ={1234, 4567,8901,2468,1357,9764}

dim i,key as integer
for i=1 to id.length-1
key=inputbox("ENTER THE SEARCH KEY")
if  (key=id(i) then
 msgbox ("ID FOUND IN LOCATION" & i)
else
msgbox(" ID IS NOT LISTED")
end if
next

Q2b) Fix the above problem and run the program.


Q3a) Design a payroll program that compute overtime pay and tax rate as well as gross pay, tax amount and net pay. Design a form with all the necessary  controls.

Q3b) All the data should be written to a file called employee.txt

Q3c) Search the file for a particular employee and display the record of the employee.


Q4a) Convert the above program using array. All the data will be into the designated array.

Q4b) modify an employee hours worked and hourly rate

Q4c) Delete an employee record


5) Do the above program using VB with access.

 

Final Exam

1)   Focus on assignments, class works and projects

Array

File

Controls boxes and event

Database on .net

Search program using array

Search program using a file

Sorting

More on input and output

More on loop

More on decision making

On Dec. 21 you will submit all your works

 

 

sample solution for final spring '05