My VB Projects

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

1.

Database Connection

Interface

Properties Table

Object Property Value

Button Text load

Button Name btnLoad

Form 1 Text Database Connection

Form Name frmDatabaseconnection

Code

Imports System.Data
Public Class Form1

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnLoad.Click
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source=C:\AddressBook.accdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
MsgBox("Database Connection is Open")
con.Close()
MsgBox("Database Connection is Closed")
End Sub
End Class

2. Login

Interface

Properties Table

Object Property Value

Form1 Text Log In

Form1 Name frmLogin

Label1 Text Enter Username

Label1 Name lblpassword

Textbox1 Name txtusername

Textbox2 Name txtpassword

Button1 Text Login

Button2 Text Clear


Button1 Name btnLogin

Button2 Name frmLogin

Code

Public Class Form1

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnLogin.Click
Dim username As String
Dim password As String
username = txtusername.Text
password = txtpassword.Text
If username = "terrie" And password = "tck" Then
MsgBox("Welcome Terrie")
Me.Show()
ElseIf username = "felix" And password = "felix" Then
MsgBox("Welcome Mr Mavatu")
Me.Show()
ElseIf username = "reynold" And password = "Ncube" Then
MsgBox("Welcome Mr Ncube")
Me.Show()
ElseIf username = "mzingaye" And password = "masilela" Then
MsgBox("Welcome Mr Masilela")
Me.Show()
ElseIf username = "moureen" And password = "mpofu" Then
MsgBox("Welcome Miss Mpofu")
Me.Show()
ElseIf username = "tawanda" And password = "perai" Then
MsgBox("Welcome Mr Perai")
Me.Show()
Else
MsgBox("Wrong username or password!")
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClear.Click
txtusername.Clear()s
txtpassword.Clear()
End Sub
End Class

3. Mark Grading

Interface
Properties Table

Object Property Value Name

Label1 Text Mark lblMark

Label2 Text Grade lblGrade

Button1 Text Check btnCheck

Button2 Text Clear btnClear

TextBox1 - - txtMark

TextBox2 - - txtGrade

Form1 Text Grades frmGrades

Code

Public Class Form1

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnCheck.Click
Dim Mark As Integer
Dim Grade As String
Mark = txtMark.Text
Select Case Mark
Case 80 To 100
Grade = "DISTINCTION"
Case 70 To 79
Grade = "Merit"
Case 60 To 69
Grade = "Pass with credit"
Case 40 To 59
Grade = "PASS"
Case 0 To 39
Grade = "FAIL"
Case Else
Grade = " OUT OF RANGE!"
End Select
txtGrade.Text = Grade
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnClear.Click
txtMark.Clear()
txtGrade.Clear()
End Sub
End Class

4. Palindrome

Interface

Properties Table

Object Properties Value Name

Button1 Text Clear btnClear

Button2 Text Check btnCheck


Label1 Text Enter word lblword

TextBox1 - - txtword

Form1 Text Palindrome frmPalindrome

Code

Public Class Form1

Private Sub btnCheck_Click ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnCheck.Click
Dim mystring As String = TextBox1.Text
If LCase(mystring) = LCase(StrReverse(mystring)) Then
MsgBox(TextBox1.Text & " is a palindrome")
Else
MsgBox(TextBox1.Text & " is not a palindrome")
End If
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnClear.Click
txtword.Clear()
End Sub
End Class

5. Program using a Do While statement

Interface
Properties Table

Object Properties Value Name

Label1 Text Enter number lblnumber

TextBox1 - - txtnumber

Button1 Text Calculate btnCalculate

Form1 Text Form1 Form1

Code

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim num As Integer
num = txtnum.Text
Do While num < 5
MsgBox(num)
num = num + 2
Loop
End Sub
End Class
6. Program that counts from 0 to 100

Interface

Properties Table

Object Property Value Name

ListBox1 - - ListBox1

Button1 Text Start btnstart

Form1 Text Form1 frmCounter

Code

Public Class Form1

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

End Sub

Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnstart.Click
Dim sum, n As Integer
While n <> 100
n += 1
sum = sum + n
ListBox1.Items.Add(n & vbTab & sum)
End While
End Sub
End Class

7. Calculator

Interface

Properties Table

Object Property Value Name

Button1 Text 1 Button1

Button2 Text 2 Button2

Button3 Text 3 Button3

Button4 Text 4 Button4

Button5 Text 5 Button5

Button6 Text 6 Button6

Button7 Text 7 Button7

Button8 Text 8 Button8

Button9 Text 9 Button9


Button10 Text 0 Button10

Button11 Text + btnplus

Button12 Text - btnsubtract

Button13 Text * btnmultipy

Button14 Text / btndivide

Button15 Text = btnanswer

Button16 Text Clear btnClear

Textbox1 - - txtdisplay

Form1 Text Calculator frmCalculator

Code

Public Class frmCalculator


Public firstnumber As Single
Public secondnumber As Single
Public sign As String
Public answer As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt1.Click
txtdisplay.Text = txtdisplay.Text & 1
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt2.Click
txtdisplay.Text = txtdisplay.Text & 2
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt3.Click
txtdisplay.Text = txtdisplay.Text & 3
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt4.Click
txtdisplay.Text = txtdisplay.Text & 4
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt5.Click
txtdisplay.Text = txtdisplay.Text & 5
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt6.Click
txtdisplay.Text = txtdisplay.Text & 6
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt7.Click
txtdisplay.Text = txtdisplay.Text & 7
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt8.Click
txtdisplay.Text = txtdisplay.Text & 8
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt9.Click
txtdisplay.Text = txtdisplay.Text & 9
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txt0.Click
txtdisplay.Text = txtdisplay.Text & 0
End Sub

Private Sub Btnplus_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Btnplus.Click
firstnumber = txtdisplay.Text
'my name is tawanda
sign = "add"
txtdisplay.Text = ""
txtdisplay.Focus()
End Sub

Private Sub btnnegative_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnnegative.Click
firstnumber = txtdisplay.Text
sign = "subtract"
txtdisplay.Text = ""
txtdisplay.Focus()
End Sub

Private Sub btnanswer_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Btnequal.Click
secondnumber = txtdisplay.Text

Select Case sign


Case "add"
answer = firstnumber + secondnumber
Case "subtract"
answer = firstnumber - secondnumber
Case "multiply"
answer = firstnumber * secondnumber
Case Else
answer = firstnumber / secondnumber
End Select
txtdisplay.Text = answer
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClear.Click
txtdisplay.Clear()

End Sub

Private Sub btndivide_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btndivide.Click
firstnumber = txtdisplay.Text
sign = "divide"
txtdisplay.Text = ""
txtdisplay.Focus()
End Sub

Private Sub btnmulyiply_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnmulyiply.Click
firstnumber = txtdisplay.Text
sign = "multiply"
txtdisplay.Text = ""
txtdisplay.Focus()
End Sub
End Class

8. Area of a circle

Interface

Properties Table

Object Properties Value Name

Label1 Text Radius lblrds


Label2 Text Area lblarea

Button1 Text Calculate btncalc

Form1 Text Are of a circle frmArea

Code

Public Class frmArea


Dim Radius As Double
Dim Area As Double
Dim PI As Double
Private Sub btncalc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncalc.Click
PI = 3.14
Radius = txtrds.Text
Area = (radius * radius * PI)
txtans.Text = Area
End Sub
End Class

Area of a triangle

Interface
Properties Table

Object Property Value Name

Label1 Text enter h lblh

Label2 Text enter b lblb

TextBox1 - - txthieght

TextBox2 - - txtbase

Button1 Text calculate btncalculate

Form1 Text Area of a triangle frmArea

Code

Public Class frmArea


Private Function area(ByVal h As Single, ByVal b As Single) As Object
area = 1 / 2 * b * h

End Function

Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btncalculate.Click
Dim b As Integer
Dim h As Integer
Dim y As Integer
h = TextBox1.Text
b = TextBox2.Text
y = area(h, b)
MsgBox(y)

End Sub

End Class

Declaring an array

Interface
Properties Table

Object Properties Value Name

Label1 Text enter position lblposition

TextBox1 - - txtposition

Button1 Text show btnshow

Form1 Text Form1 Form1

Code

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim players() As String = {"me", "myself", "i"}
Dim i As Integer = TextBox1.Text
MsgBox(players(i) & "is in the first team")

End Sub
End Class

Finding factorial

Interface
Properties Table

Object Property Value Name

Label1 Text number Lblnumber

Textbox - - Txtnumber

Button1 Text calculate Btncalculate

Form1 Text Form1 Form1

Code

Public Class Form1

Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btncalculate.Click
Dim num As Integer
Dim factorial, i As Integer
num = txtnum.Text
factorial = 1
For i = num To 1 Step -1
factorial = factorial * i

Next i
MsgBox(factorial)

End Sub
End Class
Triangular number solution

Interface

Properties Table

Object Property Value Name

Label1 Text number Lblnumber

Textbox - - Txtnumber

Button1 Text calculate Btncalculate

Form1 Text Form1 Form1

Code

Public Class Form1

Private Sub btnnumber_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnnumber.Click
Dim counter As Integer
Dim result As Long
Dim x As String = (Val(txtFirstNum.Text))
counter = 1
result = 0
While counter <= x
result = result + counter
counter = counter + 1
txtAnswer.Text = result
End While
End Sub
End Class

FACULTY: APPLIED SCIENCES

DEPARTMENT: COMPUTER SCIENCE

COURSE: VISUAL PROGRAMMING CONCEPTS AND


DEVELOPMENT

COURSE CODE: SCS1206

YEAR: 2011

Assignment 2(Group)

NAMES STUDENT NUMBER

Takura Felix Mavatu N0110945V

Terrance Chikomborero Kanyezi N0110164Y

Charles Gatsi N0111081N

Reynold Ncube N0111157T

Mzingaye Kennedy Masilela N0110560Y

Providence Ncube P0113841B


Benard Manzini N0110858L

Tawanda Perai N0111044B

Maureen Mpofu N0110289H

You might also like