Home

Visual Studio 2010

 

Visual Studio 2010 is a software Integrated Development Environment that contains Visual Basic, C, C# and F#  programming language aka software development tool.  Programming languages are used to create operating systems, applications programs such a Word, Excel, Access, PowerPoint, FrontPage, Publisher, and Telecommunications programs.  Everything that we do with a computer must first be written in a programming language.

The first programming language developed is called machine language which is written with 1 and 0.  This language is often referred to a binary or digital language.  This language required the programmer to give step by step instructions for each action in binary code. Computers only understand machine language.

The second level programming language is called assembler language.  This language allowed the programmer to use alphabet characters such as MV (which means move) that will be translated by the program into machine language. Two methods are used to translated a programming language into machine language.  
    1. A compiler takes all of the source code and translates the code into another file called the object file which is in binary format and then executes the object file.  The source file still remains. Compiled programs execute independent of the programming language and execute much faster than interpreted languages. Object files generally have a .exe extent. When you compile code in vb.net it is first complied in an intermediate language (IL) and then executed Just in Time (JIT) by the Common Language Runtime (CLR) compiler which is distributed with the IL code when sent to a PC or an Internet Site.
    2. An interpreter take one line of the source code translates it into machine code, executes the line, returns to the source code and gets the next line, interprets it into machine code.  This continues until all of the source code has been translated and executed line by line from the top of the program to the bottom.  This is referred to as sequencing through the program. An interpreter functions inside of the programming language. 

The third level programming languages (Higher Level) consisted of languages that were closer to natural languages.  Cobol, RPGII, Qbasic, Pascal, C, C+++, Fortran are examples of third level languages.   These languages allow you to use English words such as print, input, and read to write  program code.  

The fourth level languages are the visual languages such as Visual Basic, VB.NET and Visual C+++.  These are also called Object Oriented Programming languages because they attached code to objects (icons/visual pictures).  Windows 98 was written using OOP. 

The fifth level languages are the voice actuated languages.  Windows Office XP comes bundled with voice actuation and writing pad actuation. 

Programming Languages

Visual Basic 2010 a Object-Oriented programming Language AKA as OOP.

Visual Basic .NET combines a graphical interface called the Integrated Development Environment (IDE) and programming code to make program development as rapid as possible. The IDE contains tools for creating, testing and running computer programs.

The core of the .net environment is the IDE known as Visual Studio.Net (VSN).  VSN includes visual basic.net among several other programming languages such as C#.net  and C+++.net. Microsoft also sells the IDE to third party vendors who use it for their own programming languages.  There are three way of writing code in the IDE.

1. Console mode applications in which the code is run from the XP command Prompt.  This is the same mode as earlier versions of Basic, BasicA, and Qbasic.  There is no graphic user interface.

2. Windows-based mode applications in which code is written and run in windows graphic interface on the desktop.  When writing code in the window mode objects are created which are event (action) driven and execute code attached to the graphic object.(OOP).  The user interface in the windows mode is a form in which objects are placed and code attached in the background.

3. Web-based mode applications has a web user interface and runs on a web server that can be accessed using a computers internet browser.

Code can be written to execute in the Command Prompt environment, Windows environment, and Web Server environment using the IDE.

We will only be working with the windows-based application environment in CIS 1.

An object is anything that can bee seen, touched, or used;  When ever you go to the start button in window you are going to an object.

Attributes are the characteristics that describe the object. When you tell someone that you have a Pentium 4 computer that runs at 4 GigaHz, a DVD drive and 1 GigByte of Memory you are describing some of the attributes of your computer.

An objects behaviors also referred to as methods are the operations (actions) that the object is capable of performing.  Your computer can save digital files to a hard drive, transmit and received data over the internet, be used for word processing, etc.

A class is a structure, design  used to build an object and includes (encapsulates) the attributes and behaviors of the object. Your computer would be a class that has the above attributes and behaviors. A class is not an object until it has been built. Your computer did not become an object until an instances (the building of the computer, the use of the class in the program) of the class occurs.

Abstraction refers to the hiding of the internal detail of an object from the user.  This prevents the user from changing the object when they should not be messing with it. Attributes that are not hidden are said to be exposed to the user.  You only want to expose the behaviors and attributes that are necessary for the user to complete their job and hide all of the rest of them.

Once you create a class you can create another class from it called a derived class.  The derived class inherits(inheritance)  the attributes and behavior from the base class ( the class from which it was built). When you buy a new computer the salesman will show a base machine, and then will show you one with a DVD, Joy Stick, Large Monitor, Wireless Keyboard, etc.  The computer with all the bells and whistles is derived from the base class and inherits all of its attributes and behaviors and has some of its own.

Polymorphism is the oop feature that allows the same instruction to be carried out differently depending on the object. You open a file, open a form, open a report, etc.

An event (action) is something that occurs to an object.  When you left click the start button (object) on the window desktop  a pop up window comes up that allows you to access the programs.  The left click was an event that executed code that was attached to the object. If you right click the start button the response will be a different pop up menu.  The right click action executes different code on the object.  One object can have many different events associated with it. Visual Basic. Net is an event driven OOP language.

Visual Basic .Net is a graphical programming language that let you build a complete application without writing any source code.  The functionality of the application will be very limited without writing code.

Writing Source code attached to objects.

All computer languages operate within the Structured Theorem parameters which allow the solving of programming problems with:

    1. Sequencing in which source code is executed line by line from top to bottom.  All computers execute source code starting at the top of the program and continue to the bottom (end) of the program code.

    2. Selection in which a branch of code is executed based on a true or false condition. The control structures used with selection are if, then, endif for single selection, if, then, else, endif for two way selection statement, and a if, then, elseif, then, else enidif for multiple selection. 

IF condition1 THEN
[statementblock-1]
[ELSEIF condition2 THEN
[statementblock-2]]...
[ELSE
[statementblock-n]]
END IF
If age < 30 then
Print "You are less than 30 yrs old"
ElseIf age <40 then
print "You are less than 40 yrs old"
Else
Print "You are older than 40"
End If

 

  

 Select Case allows selection of a branch of code based on a pre-selected condition being true.

SELECT CASE testexpression
CASE expressionlist1
[statementblock-1]
[CASE expressionlist2
[statementblock-2]..
[CASE ELSE
[statementblock-n]
END SELECT
 

  3. Iteration (looping, repetition) in which a branch of code is executed over and over while a condition is true.  The control structures are Do While-Loop,- Do Loop Until, and For, Next  for iteration statements.

Do While... Loop   and  While...End While execute a set of statements while a condition remains true.

Do Until...Loop - executes a set of statements until a condition becomes true.

Do...Loop While - executes a set of statements while condition remains true. Will execute at least once.

Do...Loop Until - executes a set of statements until condition becomes true.  Will execute at least once.

For... Next -executes a set of statements for a specific number of times - counter controlled repetition.

FOR counter = start TO end [STEP increment]
[statementblock]
NEXT [counter [,counter]...]

For Each...Next -performs a set of statements for every element of a so-called array or collection of values.

In summary all computer programming languages  solve problems using sequencing, selection, and  iteration .  We will be working with the above control structures when we write code  behind the objects.

Additionally data used during program execution is obtain through three primary ways.

1. Data is stored within the program. VB.Net does this by using a dimensioned array with a list.  For example:

Dim strMonth() as String = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}

will store in memory in elements 0 to 11 for the strMonth variable the above data. This is called an initialization list which will automatically set the upper bounds of the array equal to the length of the list.

2. Data is input from the keyboard or other device.  Text boxes are the fields place on dialog boxes and in other windows that allow the user to enter a value. The characters entered into a text box needs to be converted into a numeric value before mathematical operations can be performed. The Val function takes number that are in text format and returns a numeric value that can be used in calculations.

lblTotal.Text=Val(txtPrice.Text) In this example the data contained in the txtPrice.text box will be converted into a number and assigned to the lblTotal.text box.

3. Data is written to or input from a disk storage device. In order to read or write file  "mports system.io" must be placed before the first form.

Algorithms

Computing problems are solved by a series of steps in a specific order.  An algorithm is a procedure for solving problems by stateing what actions are to be taken and what order that they are executed. The order in which the actions are executed determines the outcome.  When the order is incorrect it is a logic error.

Variables

Variables are memory address whoes contents may or may not change during program execution.and Constants are memory addresses whoes content will not change during program execution

Variables are declared at three levels.
1. Local variables are declared within a subrountine and are only accessible by the subrountine and are erased from memory when the subrountine is exited.  Dim intage as integer.
2. Modular/Form Variables are declared in the decelarations section of the form and are accessible by all the subrountines in the form and are erased from memory when the form is exited.  They are declared with Private Dim intage as integer.
3. Global Variables are declared at the beginnng of the project and are accessible by all of the forms and the subrountines in the forms until the project is exited - Public Dim intage as integer.

Constants are declared at two levels.
1. Modular/Form Constants are declred in the declarations section of the form and are accessible by all the subrountines in the form.
Const dectax as decimal =.05
2. Global Constant are declared at the beginning of the project and are accessible by all forms and subrountine in the project.
Public const dectax as decomal=.05.

Variable and Constant Data Type Summary (Visual Basic) 

The following table shows the Visual Basic data types, their supporting common language runtime types, their nominal storage allocation, and their value ranges.

Visual Basic type

Common language runtime type structure

Nominal storage allocation

Value range

Boolean

Boolean

Depends on implementing platform

True or False

Byte

Byte

1 byte

0 through 255 (unsigned)

Char (single character)

Char

2 bytes

0 through 65535 (unsigned)

Date

DateTime

8 bytes

0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999

Decimal

Decimal

16 bytes

0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9...E+28) with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal;

smallest nonzero number is +/-0.0000000000000000000000000001 (+/-1E-28)

Double (double-precision floating-point)

Double

8 bytes

-1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values;

4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values

Integer

Int32

4 bytes

-2,147,483,648 through 2,147,483,647 (signed)

Long (long integer)

Int64

8 bytes

-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18 ) (signed)

Object

Object (class)

4 bytes on 32-bit platform

8 bytes on 64-bit platform

Any type can be stored in a variable of type Object

SByte

SByte

1 byte

-128 through 127 (signed)

Short (short integer)

Int16

2 bytes

-32,768 through 32,767 (signed)

Single (single-precision floating-point)

Single

4 bytes

-3.4028235E+38 through -1.401298E-45 for negative values;

1.401298E-45 through 3.4028235E+38 for positive values

String (variable-length)

String (class)

Depends on implementing platform

0 to approximately 2 billion Unicode characters

UInteger

UInt32

4 bytes

0 through 4,294,967,295 (unsigned)

ULong

UInt64

8 bytes

0 through 18,446,744,073,709,551,615 (1.8...E+19 ) (unsigned)

User-Defined (structure)

(inherits from ValueType)

Depends on implementing platform

Each member of the structure has a range determined by its data type and independent of the ranges of the other members

UShort

UInt16

2 bytes

0 through 65,535 (unsigned)

In scientific notation, "E" refers to a power of 10. So 3.56E+2 signifies 3.56 x 102 or 356, and 3.56E-2 signifies 3.56 / 102 or 0.0356.

Description: NoteNote

For strings containing text, use the StrConv function to convert from one text format to another.

 

Common User Interface Controls selected from the toolbox.

Control Name

Function

Prefix when naming

Form - is the basic platform that we work on.  We place all other controls on the form. frm
Labels  - use for placing text on the form and for program output lbl
Buttons - when the user clicks on a button code is executed attached to the button.  btn
Textbox  - used for program input  txt
Picturebox - used for placing pictures in -  pic
RadioButton - used in group box - only one can be selected from the group rad
CheckBox - used to select option - multiple check boxes can be checked chk
Groubox - use to put radiobuttons in -  grp
ComboBox - used to present a list of selections - cbo
ListBox - use to display a list of items - lst

All controls have properties which we will be using.

Name property -  we will name almost all of our controls so we can reference them in the code window.
Text property - the text property of a control is often treated like a caption.  In the text property we can put an & in front of a letter in the will allow us to execute the control by holding down the alt key and the letter.

Counters and Accumulators

When working with loops, for-next, do while, do until it is often necessary to know how many times the loop has executed.  For example if you were reading data records from a file to determine the average wage of a group of employees you would have to know how many employess and the total sum of their wages.

To know how many employee wages were read we would use a counter and to sum of the wages we would use an accumulator.

dim intcounter as integer
dim inttotalwage as integer
dim decaverage as decimal
intcounter=0
inttotalwage =0
for x = 1 to 5
intcounter=intcounter + 1
inttotalwage=inttotalwage + intcounter
next
decaverage=intotalwage/intcounter
lbloutput.text="you looped "&intcounter & " times with a total of  "& inttotalwage & "  and the average is " &decaverage

loop iintcounter inttotalwage
1 1 1
2 2 3
3 3 6
4 4 10
5 5 15

 

 

Declaring an Array

We learned how to declare variables and now we going to declare an array which is like a group of variables that has one name. We are able to store and retrive data from an array by indexing it subscript, the number that identifies the array element.

For example:
Dim inttestscores(10) as integer declares that inttextscores has 11 elements in it beginning with element 0 and ending with element 10.
What is stored in element 9 is refered to as subscript 9. All array delecatctions are 0 based.

We can initilaze an array a number of ways.

1. inttestscores(0)=89
    intestscore(1)=79
    intestscore(2)=88  These statements would assign 89 to element 0, 79 to element 1 and 88 to element 2.
   intestscore()={8,9,10,2,3,4} This statement would assign 8 to element 0, 9 to element 1, 10 to element 2, 2 to element 3, 3 to element 4, and 4 to element 5 of the array.

 

The following code declares the array grade(10), then uses an input box with a for next loop to enter data into 10 elements of the
grade array.  Then when computing the average grade use a for next loop with an accumulator to read the data from the array,
sum up the data and compute the average score.

Public Class Form1
'declare grade array with 11 elements
 Private Dim intgrade(10) As Integer    'declare modular level variable


Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
me.close()
End Sub

Private Sub btnGrades_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGrades.Click
'use input boxes to get the grades for each student
'declare a n index variable
Dim intindex As Integer
Dim strname as string
'use input box to get student name
strname=inputbox("Enter students name","Name entry")
'use input boxes to tet the grades for each student
For intindex = 1 To 10
grade(intindex) = InputBox("Enter grade " & intindex, _
"grade entry", "100")
Next
End Sub

Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAverage.Click
'declare variable for the total land the average
Dim sgltotal As Single
Dim sglaverage As Single
'add al the indidual grades to get a total
Dim intindex As Integer
For intindex = 1 To 10
sgltotal += grade(intindex)
Next
'calcualte the average
sglaverage = sgltotal / 10
'display the average grade
lblAverage.Text = strname & " Your grade average is " & sglaverage.tostring("n2")
lblAveragelbl.Visible = True
lblAverage.Visible = True

End Sub
End Class

The following code declares two arrays strnames and intgrades and initilize them.  You will notice that there is no number contain
within the ( ).  The reason for this is that the number of elements in the array will be equacl to the number of elemnets in the list. The strname array list 20 names in the list which mean the strnames array will have elements 0 to 19.

 

Public Class Form1
'declare and initialize the name array
Dim strnames() As String = {"John", "Paul", "Mary", "Jane", "Peter", _
"Sam", "Andrew", "Laura", "Juan", "rachel", "clifford", "Thomas", _
"Rebecca", "Susan", "Roberto", "StefanoZ", "Sara", "Jean", "Fred", "Roseann"}

'declare and initialize the grade array
Dim intgrades() As Integer = {75, 85, 95, 100, 87, 77, 65, 73, 99, 100, _
83, 88, 92, 93, 90, 80, 70, 97, 76, 88}


Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub

Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
'declare an index variable
Dim intindex As Integer
'set the index to the lower bount
intindex = strnames.GetLowerBound(0)
'while theindex is in range compare an element in the array with _
'the search text
While ((intindex < strnames.GetUpperBound(0)) And _
(strnames(intindex) <> txtName.Text))
intindex += 1 'increment the index
End While
'check to see if the name has been found
If strnames(intindex) = txtName.Text Then
lblGrade.Text = intgrades(intindex)
Else
lblGrade.Text = "not found"
End If
End Sub
End Class

Creating Files

There are two types of files: text and binary- A text file contain plain text and may be opened in a text editor. A binary file is stored as pure binary data and can not be viewed with a text editor. There are two methods of accessing files: Sequential and Random access.
We can create a new file or append data to an already existing file. 

Creating a new file.
1. Enter above  the declarations section Imports System.IO
2. Declare your streamwriter object - dim testscores as streamwriter
3. Testscores=file.createtext("testscores.text)
Opening an existing file and appending data to it.
1. Enter in the declarations section Imports System.IO
2.Declare your streamwriter object - dim textscores as streamwriter
3. Testscores=file.appendtext("testscores.text)
Writing data to file using writeline which puts each field into a seperate line in the text file.
1.testscores.writeline("Earl")
  testscores.writeline("Wylie")
  testscores.writeline(70)
  testscores.writeline()   this writes a blank line
Writing data to file using  write method which puts data on same line.
testscores.write(strname)
testscores.write(" ")
testscore.write(dectest)
Closing a file
testscores.close()

Note: you must always close a file and once you close it you must reopen the file to perform any operations.

The following code ask for input from the keyboard, creates a file called testscores and reads data from the text boxes and inserts the data into the file on a single line.

Private Sub btncreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncreate.Click
'this creates a file in which each data byte is written in a row on the same line.
Dim testscores As StreamWriter  
Dim strname As String
Dim inttest1 As Integer
Dim inttest2 As Integer
'open the file
testscores = File.CreateText("H:\ewylie\cis1\fall10\testscores.txt")
strname = InputBox("Enter your name.")
Integer.TryParse(InputBox("enter test one score"), inttest1)
Integer.TryParse(InputBox("enter test two score"), inttest2)
'write data tofile
testscores.Write(strname)
testscores.Write(", ")      This line places a comma between strname and inttest creating a commas serperated values (CSV) file.
testscores.Write(inttest1)
testscores.Write(", ")
testscores.Write(inttest2)
'close the file
testscores.Close()
End Sub

The following code ask for input from the keyboard, opens  a file called testscores and reads data from the text boxes and appends  the data into the file by moving down to the next line and then adding the data to a new line.

.
Private Sub btnappendsameline_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnappendsameline.Click
Dim testscores As StreamWriter
Dim strname As String
Dim inttest1 As Integer
Dim inttest2 As Integer
'open the file
testscores = File.AppendText("H:\ewylie\cis1\fall10\testscores.text")
strname = InputBox("Enter your name.")
Integer.TryParse(InputBox("enter test one score"), inttest1)
Integer.TryParse(InputBox("enter test two score"), inttest2)
'write data tofile
testscores.WriteLine(" ")  this code creates a new line below the existing data.
testscores.Write(strname)
testscores.Write(" ,")
testscores.Write(inttest1)
testscores.Write(",")
testscores.Write(inttest2)
'close the file
testscores.Close()

End Sub


The follow code ask for input from the keyboard, creates a file called testscores and reads data from the text boxes and inserts the data into the file creating a line for each datum.


Private Sub btnsamelilne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsamelilne.Click
Dim testscores As StreamWriter
Dim strname As String
Dim inttest1 As Integer
Dim inttest2 As Integer
'open the file
testscores = File.CreateText("H:\ewylie\cis1\fall10\testscoressingleline.txt")
strname = InputBox("Enter your name.")
Integer.TryParse(InputBox("enter test one score"), inttest1)
Integer.TryParse(InputBox("enter test two score"), inttest2)
'write data tofile
testscores.WriteLine(strname)
testscores.WriteLine(inttest1)
testscores.WriteLine(inttest2)
'close the file
testscores.Close()
End Sub


The follow code ask for input from the keyboard, opens a file called testscores and reads data from the text boxes and appends the data into the file on mulitple lines.


Private Sub btnappenddifferent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnappenddifferent.Click
Dim testscores As StreamWriter
Dim strname As String
Dim inttest1 As Integer
Dim inttest2 As Integer
'open the file
testscores = File.AppendText("H:\ewylie\cis1\fall10\testscoressingleline.txt")
strname = InputBox("Enter your name.")
Integer.TryParse(InputBox("enter test one score"), inttest1)
Integer.TryParse(InputBox("enter test two score"), inttest2)
'write data tofile
testscores.WriteLine(strname)
testscores.WriteLine(inttest1)
testscores.WriteLine(inttest2)
'close the file
testscores.Close()
End Sub

The following code open the file testscoressingline.txt and reads the data from it and displays the data on the form.


Private Sub btnreadsameline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tnreadsameline.Click
Dim testscores As StreamReader
Dim strname As String
'open the file
testscores = File.OpenText("H:\ewylie\cis1\fall10\testscoressingleline.txt")
'read data from file
strname = testscores.ReadLine
'close the file
testscores.Close()
'display results
lblresult.text = strname

End Sub

 

The following code added to the dog years program creates a file, saves the data to the file, then reads the data back from file and display it.

 

 

 Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
'declare variables
Dim intage As Integer
Dim strname As String
Dim intdogyears As Integer
'initilize variables
intage = Integer.Parse(txtage.Text)
strname = txtname.Text
' compute dog years
intdogyears = intage * 7
'display output
lbloutput.Text = "In dog years " & strname & " Your are " & intdogyears & " old."
'send data to file
Dim dogage As StreamWriter
dogage = File.CreateText("dogage.txt")
dogage.Write(strname)
dogage.Write(" ")
dogage.Write(intage)
dogage.Write(" ")
dogage.Write(intdogyears)
dogage.Close()
End Sub

Private Sub btnclear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnclear.Click
txtname.Clear()
txtage.Clear()
lbloutput.Text = ""
lblfileout.Text = ""
txtname.Focus()
End Sub

Private Sub btnexit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnexit.Click
Me.Close()
End Sub

Private Sub btndisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndisplay.Click
Dim dogread As StreamReader
Dim strname As String
dogread = File.OpenText("dogage.txt")
strname = dogread.ReadLine()
dogread.Close()
lblfileout.Text = strname

End Sub

 

Comma Seperated Values (CSV) Files

One common way to store data in a text file is to place each record on a single line with the fields separted by commas(comma separted values). Visual Basic has a function called split that facilitates working with SCV formatted files. Split can convert a line containing commas into a string asrray where the oth element contain the text preceding the fist comma, the 1st element contain the text between the first and second commas,.....

An example of using split function:

dim statdata(), line as string
line="California, 1850,Sacramento, Eureka"
startdate=line.split(","c)
for i as integer = 0 to statedate.getupperbound(0)
statedate(i)=statedata(i).trim
lstoutput.items.add(statedata(i))
next
end sub

The following code first uses Imports System.IO as a global reference to enable file writing.  Btncreate opens grades as streamwriter, creates the file grades.txt, wrties student name and 10 test grade to the CSV file.  Btnadd opens the same file to have records appended to it. Btnread opens the file grades.txt and reads a record from the file and displays the record.

Imports System.IO

Public Class frmfile

Private Sub btnexit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnexit.Click
Me.Close()
End Sub

Private Sub btncreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncreate.Click
'declare variables
Dim grades As StreamWriter
Dim strname As String
Dim dectest(10) As Decimal
Dim intcounter As Integer
'initilize grades text file which will be stored in the
'bin/debug folder within the project. You can howerver
'designate by putting the path to store the file where
'you want it.
grades = File.CreateText("grades.text")
'initilize strname
strname = InputBox("Enter the student name", "Student Name")
'write to the file the student name
grades.Write(strname)
'initilize grade array
For intcounter = 1 To 10
Try
dectest(intcounter) = Decimal.Parse(InputBox("Enter test score " & intcounter, _
"Enter test grade"))
Catch
MessageBox.Show("must be an integer")
Exit Sub
End Try
grades.Write(",") 'this puts a comma in the record
grades.Write(dectest(intcounter)) ' this writes to the file
'the current contents of dectest(intcounter)
Next
grades.Close()
End Sub

Private Sub btnadd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadd.Click
'declare variables
Dim grades As StreamWriter
Dim strname As String
Dim dectest(10) As Decimal
Dim intnumberofstudents As Integer
Dim intcount As Integer
'initilize intcount
intcount = 0
'initilize intnumberofstudents
intnumberofstudents = InputBox("Enter the number of students to be added", "Number of students")
'start a do while loop to enter the students
Do While intcount <= intnumberofstudents
'open the file
grades = File.AppendText("grades.text") 'this opens the
'grades file to add data to it
'initilize strname
strname = InputBox("Enter the student name", "Enter name")
grades.WriteLine("") 'this moves the record pointer down
'to the next line in the file
grades.Write(strname) 'this write strname to the file
For intcounter = 1 To 10
Try
dectest(intcounter) = Decimal.Parse(InputBox("Enter test score " & intcounter, "Enter test grade"))
Catch
MessageBox.Show("must be an integer")
Exit Sub
End Try
grades.Write(",")
grades.Write(dectest(intcounter))
Next
intcount = intcount + 1
grades.Close()
Loop
End Sub

Private Sub btnread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnread.Click


Dim grades As StreamReader
Dim strname As String
'open the file
grades = File.OpenText("grades.txt")
'read data from file
strname = grades.ReadLine
'close the file
grades.Close()
'display results
lblresult.text = strname

End Sub
End Class

Using a Combo Box and Select Case

The follow code uses a Combo Box with a list of items of freshman, sophmore, junior, senior, and graduate. In btnstart a message box is used to display the selected item.  In btncase a select case is used to display the selected item.

 Private Sub btnstart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnstart.Click
'demonstratews using a combo box for data entry
MessageBox.Show("The sleected name is " & _
cmbitems.SelectedItem, "Selected name")


End Sub

Private Sub btncase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncase.Click
Dim strstatus As String
'initilize string
strstatus = cmbitems.SelectedItem
Select Case strstatus
Case "Freshman"
lbldisplay.Text = "You are a freshman"
Case "Sophmore"
lbldisplay.text = "You are a sophmore"
Case "Junior"
lbldisplay.text = "You are a junior"
Case "Senior"
lbldisplay.text = "You are a senior"
Case "Graduate"
lbldisplay.text = "You are a graduate"
Case Else
lbldisplay.text = "Incorrect data"
End Select
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
cmbitems.SelectedIndex = -1
lbldisplay.text=""
End Sub

Definitions

A Graphical User Interface (GUI) is the visual part of a program containing forms and controls.

A control is a visual object on the screen that helps the program to communicate with the user by accepting input or displaying output.

Multi-tasking is the process of doing more than one thing at a time.

A front-end program is a client application that connects to a database or other server program.

A back-end program is a server program that accepts connections from client applications.

A multi-processing systems are computers with more than one processor that are capable of handling more data-processing tasks than computers with just a single processor.