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
Sample Chapters Visual Basic .Net Programming
Easy Ways
Chapter One,
Chapter Two,
Chapter Three,
Chapter Four,
Chapter Five,
Chapter Nine,
Sample Test,
Sample/True/False Test
A.1. Course Description:
A.2. Intended Audience: MIS and CS majors
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.
|
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:
|
Main Topics:
|
Weeks: |
Topic: |
Programs: |
|
Tue Jan 24, |
A Brief History on Programming Languages and Visual Basic Intro to Visual Basic environment VB controls (Text Boxes, Command
Buttons, Labels, Picture Boxes) and their
properties |
Create,
compile, and run VB program |
|
Tue Jan 31 |
Calculations in VB Declaring variables |
Creating a calculator in VB |
|
Tue Feb 07, |
Input
Box, Message Box |
Simple payroll application with fixed tax rate |
|
Tue Feb 14, |
Decision
making: If ... Then statement |
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 |
Translator
Program |
|
Tue Mar 07 |
Sequential Files: Creating, writing to, and reading from text files
|
An assignment on file handling |
|
Tue Mar 14, |
Spring Recess
|
|
|
Tue Mar 28, |
More on files Additional Controls (Check Boxes, Radio Buttons, List Boxes, Combo Boxes) |
Assignment on creating a search program using file |
|
Tue Apr 04, |
Sub
Procedures |
|
|
Tue Apr 11, |
Access
Database |
Assignment using database |
|
Tue Apr 18, |
Searching, Modifying, Adding Records of a Database |
|
|
Tue Apr 25, |
Linking
VB to applications (Internet, Excel, Word) |
|
|
|
|
|
|
Tue May 9, 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