Write a visual basic code for cmdcalculate that calculates the total ,percentage and Status. If the percentage is greater than 40 then status is passed else status is failed
' Program to analyse student result
' Displaying Passed or Failed stutus
Private Sub Command1_Click()
Dim m1, m2, m3, m4 As Integer
Dim tot As Integer
Dim per As Single
m1 = Val(Text3.Text)
m2 = Val(Text4.Text)
m3 = Val(Text5.Text)
m4 = Val(Text6.Text)
tot = m1 + m2 + m3 + m4
per = tot / 4
Text7.Text = tot
Text8.Text = per
If (per >= 40) Then
Text9.Text = "Passed"
Else
Text9.Text = "Failed"
End If
End Sub
Write a visual basic code to perform the following mathematical operations when the respective command buttons are pressed.
' VB applications for mathematical operation
Dim num1 As Integer 'Declare the first number
Dim num2 As Integer 'Declare the second number
Dim output As Integer 'Declare the variable for result
Private Sub cmdAdd_Click()
output = Val(txtInput1) + Val(txtInput2)
txtResult.Text = " "
txtResult = output
End Sub
Private Sub cmdSub_Click()
' Subtracting two numbers
output = Val(txtInput1) - Val(txtInput2)
txtResult.Text = " "
txtResult = output
End Sub
Private Sub cmdMult_Click()
'Multiplying two numbers
output = Val(txtInput1) * Val(txtInput2)
txtResult.Text = " "
txtResult = output
End Sub
Private Sub cmdDiv_Click()
'Dividing two numbers
output = Val(txtInput1) / Val(txtInput2)
txtResult.Text = " "
txtResult = output
End Sub
Private Sub cmdClear_Click()
txtInput1 = " "
txtInput2 = " "
txtResult.Text = " "
txtInput1.SetFocus 'After clearing the text boxes the focus will transfer to txtInput1
End Sub
Private Sub cmdExit_Click()
End 'Terminate the mathematical operations
End Sub
Write a visual basic code that displays
Student grade is A if opt80 is selected
Student grade is B if opt70 is selected
Student grade is C if opt60 is selected
Student grade is D if opt50 is selected
Private Sub cmdGrade_Click()If optOne.Value = True Then
lblstudGrade = "Student grade is A"
End If
If optTwo.Value = True Then
lblstudGrade = "Student grade is B"
End If
If optThree.Value = True Then
lblstudGrade = "Student grade is C"
End If / If optFour.Value = True Then
lblstudGrade = "Student grade is D"
End If
End Sub
Private Sub form_load()
optOne.Value = False
optTwo.Value = False
optThree.Value = False
optFour.Value = False
End Sub
Write a visual basic code that accepts the radius of a circle in txtradius and calculates the
Private Sub Command1_Click()
Dim r As Integer
r = Text1.Text
'Calculating perimeter of circle
Text2.Text = Val(r) * 2
'Calculating area of circle
Text3.Text = 3.14 * r ^ 2
'Calculating circumference of circle
Text4.Text = 2 * 3.14 * r
End Sub
Private Sub fontChk1_Click()If fontChk1.Value = 1 Then
txtSName.FontBold = True
Else
txtSName.FontBold = False
End If
End Sub
Private Sub fontChk2_Click()
If fontChk2.Value = 1 Then
txtSName.FontItalic = True
Else
txtSName.FontItalic = False
End If
End Sub
Private Sub fontChk3_Click()
If fontChk3.Value = 1 Then
txtSName.FontUnderline = True
Else
txtSName.FontUnderline = False
End If
End Sub / Private Sub colChk1_Click()
If colChk1.Value = 1 Then
txtSName.ForeColor = &HFF&
Else
txtSName.ForeColor = &H0&
End If
End Sub
Private Sub colChk2_Click()
If colChk2.Value = 1 Then
txtSName.ForeColor = &HC000&
Else
txtSName.ForeColor = &H0&
End If
End Sub
Private Sub colChk3_Click()
If colChk3.Value = 1 Then
txtSName.ForeColor = &HC00000
Else
txtSName.ForeColor = &H0&
End If
End Sub
Private Sub colChk4_Click()
If colChk4.Value = 1 Then
txtSName.ForeColor = &HFFFF&
Else
txtSName.ForeColor = &H0&
End If
End Sub
Private Sub cmdCapital_Click()
' ListIndex is the property of listbox.
' The index position starts from 0.
If lstStates.ListIndex = 0 Then
MsgBox "Area-300000, Capital - Hyderabad, Languages - Telgu and Urdu"
End If
If lstStates.ListIndex = 1 Then
MsgBox "Area-84,000, Capital - Itanagar, Languages - Monpa, Miji, Aka, Sherdukpen"
End If
If lstStates.ListIndex = 2 Then
MsgBox "Area-78,000, Capital - Dispur, Language - Assamese"
End If
If lstStates.ListIndex = 3 Then
MsgBox "Area-174,000, Capital - Patna, Language - Hindi"
End If
If lstStates.ListIndex = 4 Then
MsgBox "Area-135100, Capital - Raipur, Language - Hindi"
End If
If lstStates.ListIndex = 5 Then
MsgBox "Area-1,500, Capital - Delhi, Language - Hindi"
End If
If lstStates.ListIndex = 6 Then
MsgBox "Area-4000, Capital - Panaji, Languages - Konkani, Marathi, Gujarati"
End If
If lstStates.ListIndex = 7 Then
MsgBox "Area-200,000, Capital - Gandhinagar, Language - Gujarati"
End If
If lstStates.ListIndex = 8 Then
MsgBox "Area-44,212 Capital - Chandigarh, Languages - Haryanvi ( a dialect of Hindi), Hindi, Punjabi"
End If
If lstStates.ListIndex = 9 Then
MsgBox "Area-56,000, Capital - Shimla, Languages - Pahari, Hindi"
End If
Private Sub cmdExit_Click()
End ' Terminates the application
End Sub
Private Sub cmdCheck_Click()
ch = Text1.Text
Select Case ch
Case "A", "E", "I", "O", "U"
MsgBox ("It is an uppercase vowel")
Case "B" To "Z"
MsgBox ("It is an uppercase consonant")
Case Else
MsgBox ("It is not an uppercase character")
End Select
End Sub
Private Sub cmdCalc_Click()
Dim principal As Double
Dim interest As Double
Dim time As Integer
Dim result As Double
Dim valX As Double
principal = txtPrin.Text
interest = txtRate.Text
time = txtTime.Text
result = (principal * interest * time) / 100
txtResult.Text = result ' Displays the result in txtResult input box
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdMax_Click()
Dim num1, num2, num3 As Single
num1 = Val(text1)
num2 = Val(text2)
num3 = Val(text3)
If num1 > num2 And num2 < num3 Then
lblResult.Caption = "First number " & num1 & " is maximum"
End If
If num2 > num3 And num2 > num1 Then
lblResult.Caption = "Second number " & num2 & " is maximum"
End If
If num3 > num1 And num3 > num2 Then
lblResult.Caption = "Third number " & num3 & " is maximum"
End If
End Sub
Private Sub cmdEvenOdd_Click()
Dim N As Integer
Dim teven, todd, num As Integer
teven = 0
todd = 0
N = Val(txtInput.Text)
For i = 1 To N
prompt = "Please enter a value = " & Str(i)
num = Val(InputBox(prompt))
lstEvenOdd.AddItem (num)
If num Mod 2 = 0 Then
teven = teven + 1
Else
todd = todd + 1
End If
If num < Min Then
Min = num
End If
Next i
Text2.Text = teven
Text3.Text = todd
End Sub
Private Sub Command1_Click()
prime = 0
flag = True
i = 2
List1.Clear
List1.AddItem (2)
For prime = 0 To Val(Text1.Text) + 1
For j = 2 To i - 1
If i Mod j = 0 Then
flag = True
Exit For
Else
flag = False
End If
Next j
If flag = False Then
prime = prime + 1
List1.AddItem (i)
End If
i = i + 1
Next prime
End Sub
Dim opt1, opt2 As Integer
Private Sub cmdDiscount_Click()
Dim pname As String
Dim lprice, netprice As Double
pname = txtProduct.Text
lprice = Val(txtPrice.Text)
netprice = fun_netprice(lprice, op1, opt2)
txtNet.Text = netprice
End Sub
Private Sub optFes_Click()
If optFes.Value = True Then
opt2 = 1
Else
opt2 = 0
End If
End Sub
Private Sub optNonFes_Click()
If optNonFes.Value = True Then
opt1 = 1
Else
opt1 = 0
End If
End Sub
Function fun_netprice(lprice, opt1, opt2) As Double
If opt1 = 0 Then
lprice = lprice - (lprice * (10 / 100))
fun_netprice = lprice - (lprice * (7 / 100))
End If
If opt2 = 0 Then
fun_netprice = lprice - (lprice * (10 / 100))
End If
End Function
Private Sub cmdCalculateNet_Click()
Dim sal As Double
Dim da As Double
Dim hra As Double
Dim netsal As Double
sal = txtSalary.Text
netsal = net_sal(sal)
End Sub
Function net_sal(sal) As Double
If (sal < 2000) Then
da = sal * (10 / 100)
hra = sal * (5 / 100)
End If
If (sal >= 2000) And (sal < 4000) Then
da = sal * (25 / 100)
hra = sal * (15 / 100)
End If
If (sal >= 4000) And (sal < 8000) Then
da = sal * (30 / 100)
hra = sal * (25 / 100)
End If
If (a >= 8000) Then
da = sal * (40 / 100)
hra = sal * (30 / 100)
End If
txtDa.Text = da
txtHra.Text = hra
netsal = sal + da + hra
txtNetSal.Text = netsal
End Function
CREATE TABLE TEACHER
(TNO CHAR(4) PRIMARY KEY NOT NULL,
TNAME CHAR(20),
TADDRESS CHAR(25),
SALARY NUMBER(7,2) CHECK (SALARY BETWEEN 5000 AND 10000),
DEPT_NO CHAR(4) CONSTRAINT TEACH_DEPT
REFERENCES DEPARTMENT(DEPT_NO),
DOJ DATE DEFAULT SYSDATE,
UNIQUE (TNO, TNAME));
CREATE TABLE BUS
(BUSNO NUMBER(4) PRIMARY KEY,
ORIGIN VARCHAR2(10) NOT NULL,
DEST VARCHAR2(10) NOT NULL,
RATE NUMBER(5,2) NOT NULL,
KM NUMBER(5) CHECK (KM > 200),
TIME NUMBER(5,2) DEFAULT 12,
TYPE VARCHAR2(4));
CREATE TABLE BANK
(ACC_NO NUMBER(8) NOT NULL,
TRAMOUNT NUMBER(8,2) CHECK (TRAMOUNT > 0),
TRDATE DATE,
TRTYPE CHAR(1),
CNO NUMBER(4),
CONSTRAINT CUST_TR FOREIGN KEY (CNO) REFERENCES CUST(CNO));
Write a PL/SQL block to check whether the number is prime or not.
DECLARE
n number(3);
i number(3) := 2;
flag number(3);
begin
n := #
while (i < n) loop
if (mod(n, i) = 0) then
flag := 1;
exit when flag = 1;
end if;
i := i + 1;
end loop;
if (flag = 1) then
DBMS_OUTPUT.PUT_LINE('The number is not prime');
else
DBMS_OUTPUT.PUT_LINE('The number is prime');
end if;
end;
/* Procedure to modify employee salary */
CREATE OR REPLACE PROCEDURE EDSAL (EID EMPLOYEE.ID%TYPE)
IS
V_SAL EMPLOYEE.SALARY%TYPE;
BEGIN
SELECT SALARY INTO V_SAL FROM EMP WHERE ID = EID;
IF V_SAL <5000 THEN
UPDATE EMPLOYEE SET SALARY =SALARY*1.15 WHERE ID = EID;
END IF;
END;
Trigger when an employee information is changed */
CREATE OR REPLACE TRIGGER restrict_salary
BEFORE UPDATE OR INSERT ON EMPLOYEE
FOR EACH ROW
WHEN (new.empsal > 10000)
BEGIN
raise_application_error (-20001, 'Salary should not exceet 10000');
END;
PL/SQL block to create a cursor for reading D02 department record */
DECLARE
CURSOR teach_cursor IS
SELECT tno, tname, salary, dept_no
FROM TEACHER;
BEGIN
FOR teach_record IN teach_cursor LOOP
--implicit open and implicit fetch occur
IF teach_record.dept_no != 'D02' THEN
dbms_output.put_line(teach_record.TNO || ' ' || teach_record.TNAME || ' '
|| teach_record.SALARY);
END IF;
END LOOP; -- implicit close occurs
END;