VB application to design a Calculator

Dim sd, operator, result As Integer
Private Sub com0_Click(Index As Integer)
txtoutput = txtoutput & 0
End Sub
Private Sub com1_Click(Index As Integer)
txtoutput = txtoutput & 1
End Sub
Private Sub com2_Click(Index As Integer)
txtoutput = txtoutput & 2
End Sub
Private Sub com3_Click(Index As Integer)
txtoutput = txtoutput & 3
End Sub
Private Sub com4_Click(Index As Integer)
txtoutput = txtoutput & 4
End Sub
Private Sub com5_Click(Index As Integer)
txtoutput = txtoutput & 5
End Sub
Private Sub com6_Click(Index As Integer)
txtoutput = txtoutput & 6
End Sub
Private Sub com7_Click(Index As Integer)
txtoutput = txtoutput & 7
End Sub
Private Sub com8_Click(Index As Integer)
txtoutput = txtoutput & 8
End Sub
Private Sub com9_Click(Index As Integer)
txtoutput = txtoutput & 9
End Sub
Private Sub comclear_Click(Index As Integer)
txtoutput.Text = ""
End Sub
Private Sub comdiv_Click(Index As Integer)
operator = 4
sd = txtoutput.Text
txtoutput = ""
End Sub
Private Sub comequal_Click(Index As Integer)
If operator = 1 Then
result = Val(sd) + Val(txtoutput.Text)
txtoutput.Text = result
ElseIf operator = 2 Then
result = Val(sd) - Val(txtoutput.Text)
txtoutput.Text = result
ElseIf operator = 3 Then
result = Val(sd) * Val(txtoutput.Text)
txtoutput.Text = result
ElseIf operator = 4 Then
result = Val(sd) / Val(txtoutput.Text)
txtoutput.Text = result
ElseIf operator = 5 Then
result = Val(sd) Mod Val(txtoutput.Text)
txtoutput.Text = result
'ElseIf operator = 6 Then
'result = Val(sd) Mod Val(txtoutput.Text)
'txtoutput.Text = result
End If
End Sub
Private Sub comminus_Click(Index As Integer)
operator = 2
sd = txtoutput.Text
txtoutput = ""
End Sub
Private Sub commod_Click(Index As Integer)
operator = 5
sd = txtoutput.Text
txtoutput = ""
End Sub
Private Sub commul_Click(Index As Integer)
operator = 3
sd = txtoutput.Text
txtoutput = ""
End Sub
Private Sub complus_Click(Index As Integer)
operator = 1
sd = txtoutput.Text
txtoutput = ""
End Sub
Private Sub comsqrt_Click(Index As Integer)
sd = txtoutput.Text
result = Val(sd) * Val(sd)
txtoutput.Text = result
End Sub
Design a Vb application for Arithematic Functions
Dim x, y As Single
Private Sub comabs_Click(Index As Integer)
x = Val(Text1.Text)
y = Abs(x)
Text1.Text = CStr(y)
End Sub
Private Sub comclear_Click()
Text1.Text = " "
End Sub
Private Sub comexpo_Click(Index As Integer)
x = Val(Text1.Text)
y = Exp(x)
Text1.Text = CStr(y)
End Sub
Private Sub comfix_Click(Index As Integer)
x = Val(Text1.Text)
y = Fix(x)
Text1.Text = CStr(y)
End Sub
Private Sub comlog_Click(Index As Integer)
x = Val(Text1.Text)
y = Log(x)
Text1.Text = CStr(y)
End Sub
Private Sub Command1_Click(Index As Integer)
x = Val(Text1.Text)
y = Cos(x * 3.14159 / 180)
Text1.Text = CStr(y)
End Sub
Private Sub comround_Click(Index As Integer)
Dim z As Single
x = Val(Text1.Text)
z = Round(x, 3)
Text1.Text = CStr(z)
End Sub
Private Sub comsin_Click(Index As Integer)
x = Val(Text1.Text)
y = Sin(x * 3.14159 / 180)
Text1.Text = CStr(y)
End Sub
Private Sub comsqr_Click(Index As Integer)
x = Val(Text1.Text)
y = Sqr(x)
Text1.Text = CStr(y)
End Sub
Private Sub comtan_Click(Index As Integer)
x = Val(Text1.Text)
y = Tan(x * 3.14159 / 180)
Text1.Text = CStr(y)
End Sub
Combobox example to insert items and forward the items to the list and find the count
Dim sd As String
Private Sub Command1_Click()
sd = Combo1.Text
MsgBox ("you are selected " & sd)
End Sub
Private Sub Command2_Click()
Dim f As Integer
sd = Combo1.Text
List1.AddItem (sd)
f = List1.ListCount
MsgBox ("the number of items" & f)
End Sub
Private Sub Form_Load()
Combo1.AddItem "apple"
Combo1.AddItem "Mango"
Combo1.AddItem "Grapes"
Combo1.AddItem "Guava"
Combo1.AddItem "Custard Apple"
End Sub
Example1
Private Sub Command1_Click()
Dim i As Integer
Print "welcome"
For i = 1 To 9
FontSize = 10 + i
ForeColor = QBColor(i)
Print "welcome"
Next i
End Sub
Example 2
Private Sub Command1_Click()
Dim i, j As Integer
For i = 1 To 5
For j = 1 To i
Print j;
Next j
Next i
End Sub
Example 3
Private Sub Command1_Click()
Dim i, j, n As Integer
n = InputBox("enter n", "pattern")
For i = 1 To n
Print i;
Next j
Print
Next i
Print
End Sub
Loops repeat programming statements
according to specific condition.
There are
1.Do while
2 Do until
Do while loop: In this loop the statements
will be implemented and repeated whenever
the condition satisfied
syntax:
Do while condition
Statements
Loop
Write a program to print (hello) five times
with its numbering using dowhile loop.
Dim i as integer
Private Sub Command1_Click ()
i = 1
Do while i <= 5
Print "hello"; i
i = i + 1
Loop
End Sub
ex2: print n even numbers
2-Do until loop: In this loop the statements will be implemented and repeated when
ever the condition not satisfied, (i.e) the loop will be stopped when the condition
satisfied.
syntax:
Do until condition
Statements
Loop
Write a program to print (hello) five times with its numbering using do
until loop.
Dim i as integer
Private Sub Command1_Click ()
i = 1
Do until i > 5
Print "hello"; i
i = i + 1
Loop
End Sub
Used for applying many statements depending on one variable.
syntax:
Select case variable
Case value1
statements
Case value2
Statements
.
.
.
Case value n
Statements
Case else
Statements
End select
-->Conditional loop
Loops repeat programming statements
according to specific condition.
There are
1.Do while
2 Do until
Do while loop: In this loop the statements
will be implemented and repeated whenever
the condition satisfied
syntax:
Do while condition
Statements
Loop
Write a program to print (hello) five times
with its numbering using dowhile loop.
Dim i as integer
Private Sub Command1_Click ()
i = 1
Do while i <= 5
Print "hello"; i
i = i + 1
Loop
End Sub
ex2: print n even numbers
2-Do until loop: In this loop the statements will be implemented and repeated when
ever the condition not satisfied, (i.e) the loop will be stopped when the condition
satisfied.
syntax:
Do until condition
Statements
Loop
Write a program to print (hello) five times with its numbering using do
until loop.
Dim i as integer
Private Sub Command1_Click ()
i = 1
Do until i > 5
Print "hello"; i
i = i + 1
Loop
End Sub
-->Select statement
Used for applying many statements depending on one variable.
syntax:
Select case variable
Case value1
statements
Case value2
Statements
.
.
.
Case value n
Statements
Case else
Statements
End select
Ex:sum of n natural numbers using do-while loop
Private Sub run_Click()
Dim i, n, sum As Integer
n = Val(InputBox("enter the number"))
sum = 0
i = 1
Do While i <= n
sum = sum + i
i = i + 1
Loop
MsgBox ("sum of natural numbers" & sum)
End Sub
Dim i, n, sum As Integer
n = Val(InputBox("enter the number"))
sum = 0
i = 1
Do While i <= n
sum = sum + i
i = i + 1
Loop
MsgBox ("sum of natural numbers" & sum)
End Sub
Example of select case using option buttons
Private Sub Command1_Click()
Select Case True
Case Option1.Value = True
MsgBox (" sunday")
Case Option2.Value = True
MsgBox (" Monday")
Case Option3.Value = True
MsgBox ("Tuesday")
Case Option4.Value = True
MsgBox (" Wednesday")
Case Option5.Value = True
MsgBox (" Thurday")
Case Option6.Value = True
MsgBox (" Friday")
Case Option7.Value = True
MsgBox (" Saturay")
End Select
End Sub
Private Sub Command1_Click()
Dim i, n As Integer
Dim x, sum, av As Double
i = 1: sum = 0
n = CInt(Text1.Text)
Do While i <= n
x = Val(InputBox("enter number"))
sum = sum + x
i = i + 1
Loop
av = sum / n
Text2.Text = CStr(av)
End Sub
display student information
Private Sub Command1_Click()
Dim no, m1, m2, m3, total,avg As Integer
m1 = Val(Text4.Text)
m2 = Val(Text5.Text)
m3 = Val(Text6.Text)
total = m1 + m2 + m3
Text7.Text = total
avg = total / 3
Print avg
If avg >= 90 And avg < 100 Then
Text8.Text = "A+"
ElseIf avg >= 75 And avg < 90 Then
Text8.Text = "A"
ElseIf avg >= 60 And avg< 75 Then
Text8.Text = "B"
ElseIf avg >= 50 And avg < 60 Then
Text8.Text = "C"
ElseIf avg >= 40 And avg< 50 Then
Text8.Text = "D"
Else
Text8.Text = "FAIL"
End If
End Sub
-->Display the electricity bill of a customer
Dim amount, units, netamount, surcharge, totalamount As Single
Private Sub Command1_Click()
units = CInt(Text1.Text)
If units < 200 Then
amount = 1.2
ElseIf units >= 200 And units < 400 Then
amount = 1.5
ElseIf units >= 400 And units < 600 Then
amount = 1.8
Else
amount = 2
End If
netamount = units * amount
Text2.Text = netamount
If netamount > 300 Then
surcharge = netamount * 15 / 100
End If
netamount = netamount + surcharge
Text2.Text = netamount
If units < 100 Then
netamount = 100
Text2.Text = netamount
End If
MsgBox ("custm id " & Combo1.Text & vbCrLf & "custm name " & Combo2.Text & vbCrLf &"units"&units& vbCrLf &"net amount"&netamount)
End Sub
Private Sub Form_Load()
Combo1.AddItem "1001"
Combo1.AddItem "1002"
Combo1.AddItem "1003"
Combo1.AddItem "1004"
Combo1.AddItem "1005"
Combo2.AddItem "sunitha"
Combo2.AddItem "sekhar"
Combo2.AddItem "pooja"
Combo2.AddItem "raja"
Combo2.AddItem "mukesh"
End Sub
-->display employee details
Private Sub Combo1_Click()
MsgBox (Combo1.List(Combo1.ListIndex))
End Sub
Private Sub Command1_Click()
Dim empno, hra, da, sal, ta, comm As Integer
Dim netsal, basicsal, Gross As Single
comm = 800
hra = Val(Text4.Text)
da = Val(Text5.Text)
ta = Val(Text6.Text)
sal = Val(Text3.Text)
netsal = sal + hra + da + ta
Text7.Text = netsal
Gross = netsal / 12
Text8.Text = Gross
If sal > 40000 Then
basicsal = sal + comm
MsgBox ("basicsal" & basicsal)
End If
End Sub
Private Sub Command2_Click()
Dim id As Integer
Dim name, f As String
id = Text1.Text
name = Text2.Text
MsgBox ("empid " & id & vbCrLf & "emp name " & name)
MsgBox ("job " & Combo1.Text)
End Sub
Private Sub Form_Load()
Combo1.AddItem "manager"
Combo1.AddItem "asst.man"
Combo1.AddItem "hr"
Combo1.AddItem "clerk"
Combo1.AddItem "pune"
End Sub
DATA BASE PROGRAMS
using DATA control
Steps in creating the
database
1.Open a new Visual
Basic project.
2. Put a data control , located in the VB
toolbox on the form
3. Add different controls like labels and text
boxes to create the form
4. The fields used in the product information are productno,
productname, productprice
5. Form Design
6. Click on Add-ins, then go to visual datamanager
7. Click on file,then select New ,go to Microsoft
Access,select version 7.0MDB
8. Save the filename
9. Click the right button on properties and then select New
table
10. Give the tablename
11. Select “ ADDFILED” column
Name
Type
Size
Productno
Integer 2
Product name
Text 50
Price
Integer
2
12. Click on build table column
13. Go to Microsoft Access and insert rows in the table
DatabaseName is the name of the
database you want to use, and the RecordSource is the name of the table
in that database that you want to use.
14.On your form, create a text box for each
field in the product table, three fields
of the product table are pno, pname, and price.) Set the properties of
the three textboxes as follows:
Name
|
DataSource
|
DataField
|
Productno
|
Data1
|
Pno
|
Productname
|
Data1
|
Pname
|
productprice
|
Data1
|
price
|
15.Save and run the
project. Use the arrows on the data control to scroll through the data.
Code for ADD, Delete, Save, first,last, previous,next
Output
Database programs using ADO Control
1. Select Microsoft ADO Control 6.0(OLEDB)
from components .Then Click Apply and OK
2. It will appear on the Toolbox, then
drag ADO control on to the form
3.
. Add different controls
like labels and text boxes to create the form
4.
. The fields used in the product information are
studentno, studentname,Address,Mobileno,EMAIL-ID
5.
Form
Design
6. Go to Microsoft Access and insert rows in the table
DatabaseName is the name of the
database you want to use, and the RecordSource is the name of the table
in that database that you want to use.
7.On your form, create a text box for each field
in the student table, three fields of
the student table are sno, sname,addr,pno,mail.) Set the properties of
the five textboxes as follows:
Name
|
Data Source
|
DataFiled
|
Studentno
|
ADODC1
|
Sno
|
Studentname
|
ADODC1
|
Sname
|
Address
|
ADODC1
|
Addr
|
Mobileno
|
ADODC1
|
Pno
|
EMAIL-ID
|
ADODC1
|
Mail
|
8.Write the code of movefirst,movelast,moveprevious,movenext,save,
delete
Write the code
9.. Search the database
of the student using studentno
Code of the search
record