35
Name:- programming in visual basic Question (1):- WAP to perform arithmetic operation uses command buttons. (Declare variables globally). Answer :- Form Layout Coding For The Program Dim n1 As Integer Dim n2 As Integer Dim r As Integer Private Sub Command1_Click() n1 = Val(Text1.Text) n2 = Val(Text2.Text) r = n1 + n2 Text3.Text = r End Sub C:\Program Files\vb1.prj B.Com- III Page 1 MAHANT LAXMINARAYAN DAS COLLEGE

Pro

Embed Size (px)

DESCRIPTION

kk

Citation preview

Name:-programming in visual basic

Question (1):- WAP to perform arithmetic operation uses command buttons. (Declare variables globally).

Answer:-Form Layout

Coding For The Program

Dim n1 As IntegerDim n2 As IntegerDim r As Integer

Private Sub Command1_Click()n1 = Val(Text1.Text)n2 = Val(Text2.Text)r = n1 + n2Text3.Text = rEnd Sub

Private Sub Command2_Click()n1 = Val(Text1.Text)n2 = Val(Text2.Text)r = n1 - n2Text3.Text = rEnd Sub

Private Sub Command3_Click()n1 = Val(Text1.Text)n2 = Val(Text2.Text)r = n1 * n2Text3.Text = rEnd Sub

Private Sub Command4_Click()n1 = Val(Text1.Text)n2 = Val(Text2.Text)r = n1 / n2Text3.Text = rEnd Sub

Private Sub Command5_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub

Output:-

Question (2):-WAP to take input of principal, rate & time and calculate simple interest & compound interest.

Answer:-Form Layout

Coding For The Program

Dim p As IntegerDim r As IntegerDim t As IntegerDim si As IntegerDim ci As Integer

Private Sub Command1_Click()

p = Val(Text1)r = Val(Text2)t = Val(Text3)si = (p * r * t) / 100Text4 = sici = (p * (1 + r / 100) ^ t) - pText5 = ciEnd Sub

Private Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""Text4 = ""Text5 = ""End Sub

Output:-

Question (3):- Write a program to take input of x and print table of x in the following format.

X * 1 = X X * 2 = 2X ----------- ----------- X * 10 = 10*X

Answer:- Form Layout

Coding section:-Dim x As IntegerPrivate Sub Command1_Click()Form1.Clsx = InputBox("Enter The Value of X ")For i = 1 To 10 Step 1Print x; "*"; i; "="; i * xNext iEnd Sub

Private Sub Command2_Click()EndEnd Sub

Output:-

Question (4):- Design an interface, which will appear like mark sheet. It will take input of marks in five subjects and calculate total marks and percentage then provide grade according to following criteria. (Using nested if) ( Use tab index property to move focus ).If % Then Grade> = 90A+> = 75 & < 90 A> = 60 & < 75B> = 45 & < 60COtherwise FAnswer:- Form Layout

Coding For The Program

Dim a#, b#, c#, d#, e#, total#, per#

Private Sub Command1_Click()a = Val(Text3.Text)b = Val(Text4.Text)c = Val(Text5.Text)d = Val(Text6.Text)e = Val(Text7.Text)total = (a + b + c + d + e)Text8.Text = totalper = total / 5Text9.Text = per & "%"

Select Case perCase 90 To 100 Label11.Caption = "A+"Case 75 To 89Label11.Caption = "A"Case 60 To 74Label11.Caption = "B"Case 45 To 59Label11.Caption = "C"Case ElseLabel11.Caption = "F"End SelectEnd Sub

Private Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""Text6.Text = ""Text7.Text = ""Text8.Text = ""Text9.Text = ""Label11.Caption = ""

End Sub

Output:-

Question (5):- WAP to illustrate all functionalities of list box and combo box.Answer:-Form Layout

Coding For The Program

Private Sub cmdadditem1_Click()Combo1.AddItem (Combo1)End Sub

Private Sub cmdadditem2_Click()List1.AddItem (Text1.Text)Text1 = ""End Sub

Private Sub cmdclearcombo_Click()Combo1.ClearEnd Sub

Private Sub cmdclearlist_Click()List1.ClearEnd Sub

Private Sub cmdexit_Click()EndEnd Sub

Private Sub cmdremoveitem2_Click()On Error Resume NextList1.RemoveItem List1.ListIndexEnd Sub

Private Sub cmdrermoveitem1_Click()On Error Resume NextCombo1.RemoveItem Combo1.ListIndexEnd Sub

Private Sub Command1_Click()Combo1.ClearEnd Sub

Output:-

Question (6):- WAP using check boxes for following font effects.BoldItalicUnderline Increase font sizeDecrease font sizeFont color

Answer:- Form Layout

Coding For The Program

Private Sub Check1_Click()If Check1.Value = vbChecked ThenText1.FontBold = TrueElseText1.FontBold = FalseEnd IfEnd Sub

Private Sub Check2_Click()If Check2.Value = vbChecked ThenText1.FontItalic = TrueElseText1.FontItalic = FalseEnd IfEnd Sub

Private Sub Check3_Click()If Check3.Value = vbChecked ThenText1.FontUnderline = TrueElseText1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Check4_Click()If Check4.Value = 1 ThenCheck5.Value = 0Check6.Value = 0Text1.FontSize = 8ElseText1.FontSize = 8End IfEnd Sub

Private Sub Check5_Click()If Check5.Value = 1 ThenCheck4.Value = 0Check6.Value = 0Text1.FontSize = 12ElseText1.FontSize = 8End IfEnd Sub

Private Sub Check6_Click()If Check6.Value = 1 ThenCheck4.Value = 0Check5.Value = 0Text1.FontSize = 14ElseText1.FontSize = 8End IfEnd Sub

Private Sub Check7_Click()If Check7.Value = 1 ThenCheck8.Value = 0Check9.Value = 0Text1.ForeColor = vbRedElseIf Check7.Value = 0 And Check8.Value = 0 And Check9.Value = 0 ThenEnd IfEnd Sub

Private Sub Check8_Click()If Check8.Value = 1 ThenCheck7.Value = 0Check9.Value = 0Text1.ForeColor = vbBlueElseIf Check7.Value = 0 And Check8.Value = 0 And Check9.Value = 0 ThenText1.ForeColor = vbResCursorEnd IfEnd Sub

Private Sub Check9_Click()If Check9.Value = 1 ThenCheck8.Value = 0Check7.Value = 0Text1.ForeColor = vbGreenElseIf Check7.Value = 0 And Check8.Value = 0 And Check9.Value = 0 ThenText1.ForeColor = vbResCursorEnd IfEnd Sub

Output:-

Question (7):- WAP to change back color of any control (label, textbox) using scroll box.Answer:-Form Layout

Coding section:-Private Sub HScroll1_Change()Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)End Sub

Private Sub HScroll2_Change()Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)End Sub

Private Sub HScroll3_Change()Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)End SubOutput:-

Question (8):- WAP to search an element for a one dimension static array.

Answer:-Form Layout

Coding section:-

Dim a(5) As IntegerDim num As IntegerDim f As Integer

Private Sub Command1_Click()num = Input Box("enter number to be searched")For i = 1 To 5 Step 1If num = a(i) Thenpos = if = 1End IfNextIf f = 0 ThenPrint "element" & num; "not found"ElsePrint "element found at" & pos; , "position"End IfEnd Sub

Private Sub Command2_Click()i = 0For i = 1 To 5 Step 1a(i) = Input Box("enter array elements")Print "element =" & a(i)PrintNext iEnd Sub

Output:-

Question (9):- WAP to illustrate call by value and call by reference ( to swap to values).

Answer:-Form Layout

Coding section:-Dim x As IntegerDim y As Integer

Private Sub swapv(ByVal a As Integer, ByVal b As Integer)t = aa = bb = tText3.Text = aText4.Text = bEnd Sub

Private Sub swapr(ByRef a As Integer, ByRef b As Integer)t = aa = bb = tText3.Text = aText4.Text = bEnd Sub

Private Sub Command1_Click()x = Val(Text1.Text)y = Val(Text2.Text)Call swapv(x, y)Print xPrint y

End Sub

Private Sub Command2_Click()x = Val(Text1.Text)y = Val(Text2.Text)Call swapr(x, y)Print xPrint yEnd Sub

Output:-

Question (10):- Write a program to calculate factorial of a number using user defined function.Answer:-Form Layout

Coding section

Dim n As IntegerDim d As IntegerPrivate Sub Command1_Click()n = InputBox("enter no.", "processing", "0")d = fact(n)Text1.Text = dEnd Sub

Public Function fact(num As Integer) As IntegerIf num