65
CODING 1. WAP of Mousedown and Mouseup event in which it is shows in a textbox wheither a mousedown or a mouseup event is invoked. Private Sub Command1_Click() Text1.Text = "" End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Text = "" Text1.Text = "mousedown event" End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Text = "" Text1.Text = "mouseup event” End sub

p coding

Embed Size (px)

DESCRIPTION

dsfdfdh

Citation preview

CODING

1. WAP of Mousedown and Mouseup event in which it is shows in a textbox wheither a mousedown or a mouseup event is invoked.Private Sub Command1_Click()Text1.Text = ""End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Text1.Text = ""Text1.Text = "mousedown event"End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Text1.Text = ""Text1.Text = "mouseup eventEnd sub

2.WAP of Gotfocus event shows the application of gotfocus event. There are some objects on the form of the project.when an object gets the focus,the forms background color is changed. Private Sub Command1_GotFocus() Form1.BackColor = vbGreen End Sub Private Sub Command2_GotFocus() Form1.BackColor = vbBlue End Sub Private Sub Picture1_GotFocus() Form1.BackColor = vbBlack End Sub Private Sub Text1_GotFocus() Form1.BackColor = vbRed End Sub

3.WAP for how the option explicit statement works.Option ExplicitPrivate Sub Command1_Click()Dim n As Integern = 30Print n + 1End Sub

4.WAP for general declaration which shows what actually happens when a variable is declared in the declaration section.Dim n As IntegerPrivate Sub Command1_Click()n = 5Print nEnd SubPrivate Sub Command2_Click()Print n + 5End Sub

5.WAP of static variable.This program displays the number of clicks the user has made.that means it counts the user clicks. Private Sub Command1_Click() Static n As Integer n = n + 1 Print n End Sub

6.WAP for set properties which shows several useful properties.Private Sub Command1_Click()'backcolor and forecolor propertiesLabel1.BackColor = vbRedLabel1.ForeColor = vbBlueForm1.BackColor = vbGreenText1.BackColor = vbBlackText1.ForeColor = vbYellowFrame1.BackColor = vbCyanFrame1.ForeColor = vbpink'front propertiesText1.FontSize = 16Text1.FontItalic = TrueText1.Font = "tahoma"'caption propertyLabel1.Caption = "name"End Sub

7.WAP which demonstrates the password char properties of textbox.IF correct password is entered,the program displaya success message . This is a very important concept as it can be implemented in some real life software projects.Private Sub Command1_Click()If Text1.Text = "12345" ThenMsgBox "successful!!!", vbInformation, ""ElseMsgBox "incorrect password!", vbCritical, ""End IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""End Sub

8.WAP for form.Private subform_load()Form1.showPrintWelcome to vb End sub

9.WAP for textbox which shows how text is displayed in the textbox object.Private Sub Command1_Click()Text1.Text = "Hello"End SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Command3_Click()Text1.Text = ""End Sub

10.WAP to display the message taken from a textbox.Private Sub Command1_Click()Dim n As Stringn = Text1.TextPrint nEnd SubPrivate Sub Command2_Click()ClsEnd Sub

11.WAP to print something.Private Sub Form_activate()Print 20 + 10Print 20 - 10Print 20 * 10Print 20 / 10End Sub

12.WAP to add string.Private Sub Form_Activate()A = "Prachi"B = "likes"C = "studying"Print A & B & CEnd Sub

13.WAP to add values in textbox1 and textbox2.Private Sub Command1_Click()Sum = Val(Text1.Text) + Val(Text2.Text)Text3.Text = SumEnd sub

14.WAP for Default and Cancel property in which when we press enter from the keyboard a particular message is displayed.Private Sub Command1_Click()MsgBox "you have pressed the default button!", vbInformation, ""End SubPrivate Sub Command2_Click()EndEnd Sub

15.WAP for Inputbox or Msgbox in which a no. is taken as input and the same is shown in msgbox.Private Sub Form_Load()n = InputBox("enter a no.")MsgBox "you entered" & nEnd Sub

16.WAP in which two numbers are entered through input box,and the sum is shown in the msgbox.Private Sub Command1_Click()a = Val(InputBox("enter the value of a", "input value"))b = Val(InputBox("enter the value oif b", "input value"))MsgBox "The sum is" & a + b, vbinformattion, "input"End Sub

17.WAP shows how to show msg in picture Box.The print and cls methods are used.Private Sub Command1_Click()Picoutput.Print "Hello!"End SubPrivate Sub Command2_Click()Picoutput.Print "Welcome to VB"End SubPrivate Sub Command3_Click()Picoutput.ClsEnd Sub

18.WAP for largest no. among three using if-else.Private Sub Command1_Click()Dim a, b, c As Integera = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)If a > b And b > c ThenText4.Text = aElseIf b > a And b > c ThenText4.Text = bElseText4.Text = cEnd IfEnd Sub

19.WAP tells length of string.Private sub cmdstart_click()Dim word as string,N as integerWord=inputbox(Enter the word,Input)N=Len(word)Select case NCase 0Printyou have not entered wordCase 1PrintThis is a one letter wordCase 2Print This s a two letter wordEnd selectEnd sub

20.WAP to show your name.Dim firstname 'secondname'thirdname as stringPrivate Sub Command1_Click()firstname = Text1.Textsecondname = Text2.Textyourname = firstname + " " + secondnameText3.Text = yournameEnd Sub

21.WAP for password for DO.Loop.The loop continues until password matches.Private Sub Form_Load()Doa=Inputbox(Enter the password)if a=visual thenmsgboxAccess granted!!!elsemsgboxAccess denied..pleas try againend ifLoop until a=visualEnd Sub

22.WAP which formats text in a label control using option button controls.Private Sub Option1_Click()Label1.ForeColor = vbBlueEnd SubPrivate Sub Option2_Click()Label1.ForeColor = vbGreenEnd SubPrivate Sub Option3_Click()Label1.ForeColor = vbCyanEnd Sub

23.WAP for check box controls and makes some orders of restaurant.Private Sub Command1_Click()Dim total As Integertotal = 0Tea = ""Sandwich = ""Pizza = ""If Check1.Value = 1 ThenTea = "Tea,"total = total + 5End IfIf Check2.Value = 1 ThenSandwich = "Sandwich,"total = total + 20End IfIf check3Pizza.Value = 1 ThenPizza = "Pizza,"total = total + 50End IfMsgbox"you have ordered"Tea&Sandwich&Pizza"and the total price is"&total,vbinformation,"Thanks"End Sub

24.WAP which teaches you how to make a shortcut key in vb.The program enables you to make form green by pressing ctrl+G.Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = vbKeyG And Shift = vbCtrlMask ThenForm1.BackColor = vbGreenEnd IfEnd Sub

25.WAP for use of timer control to show digital clock.Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()Text1.Text = 10End Sub

26.WAP to show a pop menu on the form.Private Sub Blue_Click()Form1.BackColor = vbBlueEnd SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = vbRightButton ThenPopupMenu mnucolorsEnd IfEnd SubPrivate Sub Green_Click()Form1.BackColor = vbGreenEnd SubPrivate Sub Red_Click()Form1.BackColor = vbRedEnd SubPrivate Sub White_Click()Form1.BackColor = vbWhiteEnd SubPrivate Sub Yellow_Click()Form1.BackColor = vbYellowEnd Sub

27.WAP for login.Private Sub Command1_Click()If Text1.Text = "" ThenMsgBox "Enter the username!" 'vbexclamation,""Exit SubEnd IfIf Text2.Text = "" ThenMsgBox "Enter Password!", vbExclamation, ""Exit SubEnd IfIf Text1.Text = "prachi" And Text2.Text = "12345" ThenForm1.ShowUnload MeElse: MsgBox "username or password,or both are wrong!", vbExclamation, ""End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub

28.WAP of Lostfocus shows which command button among two has lost the focus.Private Sub cmd_Lostfocus()Msgboxcommand1 has lost the focusEnd Sub

29.WAP for mouse capture which show x,y coordinates of the mouse pointer while you move the mouse on the form and shows which mouse button has been pressed.Private Sub Form_mouseDown()If Button and vbLeftButton thenlblmouseButton.caption=LeftlblmouseButton.caption=RightlblmouseButton.caption=Middleend iflblx.caption=xlbly.caption=yend subPrivate Sub Form_mousemove()lblx.caption=xlbly.caption=yEnd Sub

30.WAP to add,substract,multiply and divide two numbers.Private Sub Command1_Click()Me.Text3.Text = Val(Text1.Text) + Val(Text2.Text)Me.Text4.Text = Val(Text1.Text) - Val(Text2.Text)Me.Text5.Text = Val(Text1.Text) * Val(Text2.Text)Me.Text6.Text = Val(Text1.Text) / Val(Text2.Text)End SubPrivate Sub Form_Load()MsgBox ("Hello Welcome to perform operations")End Sub

31.WAP to show the working of Timer.Private Sub Timer1_Timer()If Shape1.Visible = True ThenShape2.Visible = TrueShape1.Visible = FalseShape3.Visible = FalseElseIf Shape2.Visible ThenShape3.Visible = TrueShape2.Visible = FalseShape1.Visible = FalseElseIf Shape3.Visible ThenShape1.Visible = TrueShape2.Visible = FalseShape3.Visible = FalseEnd IfEnd Sub

32.WAP to print following series:112123123412345

Private Sub Form_Click()For r = 1 To 5For c = 1 To rPrint c;NextPrintNextEnd Sub33.WAP to print a table on the form.Private Sub Command1_Click()For k = 1 To 10Print Val(Text1.Text) * kNextEnd Sub

33.WAP which accepts a no. and multiply it by 2.Private sub form_Load()Dim num as integer,ans as integerNum=Inputbox(Enter a number)If num>0 ThenAns=num*2ElseUnload meEndifTet1.text=ansForm1.Backcolor=vbBlueEnd Sub

34.WAP which accept a no. and display the no. of digit places.Dim a as integerPrivate sub command1.click()If a10 and a1000 and a 0 Thenans = num * 2ElseUnload MeEnd IfText1.Text = ansForm1.BackColor = ubblueEnd Sub

45. Create an application using function to calculate Compound Interest. Private Sub Command1_Click()p = Text1.Textr = Text2.Texty = Text3.Textci = intrest(p, r, y)Text4.Text = ciEnd Sub

Private Sub Command2_Click()Unload MeEnd Sub

Public Function intrest(ByVal pri As Double, ByVal rat As Double, ByVal yr As Double)Dim p, r, y, ci As DoubleDim re As Doublere = (1 + (rat / 100)) ^ yrre = pri * reintrest = reEnd Function

Private Sub Form_Load()Form1.BackColor = vbRed End Sub

46. Create an application in using function to swap the values.Private Sub Command1_Click()Unload MeEnd Sub

Private Sub Command2_Click()Dim a As IntegerDim b As IntegerDim c As Integera = Text1.Textb = Text2.TextText1.Text = ""Text2.Text = ""c = swap(a, b, c)End Sub

Public Function swap(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integerz = xx = yy = zText1.Text = xText2.Text = yEnd Function

Private Sub Form_Load()Me.BackColor = vbGreenEnd Sub 47. Create two forms to display details from the table product and supplier of the database. Display these via menu option of MDI application.FOR MDI FORM:-Private Sub ex_Click()Unload MeEnd SubPrivate Sub pro_Click()Form1.ShowEnd SubPrivate Sub sup_Click()Form2.ShowEnd Sub

FOR SUPPLIER FORM:-Private Sub Command1_Click()Unload MeEnd SubPrivate Sub Form_Load()Me.BackColor = vbYellowEnd Sub

FOR PODUCT FORM:-Private Sub Command1_Click()Unload MeEnd SubPrivate Sub Form_Load()Me.BackColor = vbGreenEnd Sub

48. Create an application that determine the future value of an investment at a given rate for a given number of years, and display the future value in currency format.Private Sub Command1_Click()Dim amt As Integer, rate As Integer, fvalue As Long, time As Integeramt = Text1.Textrate = Text2.Texttime = Text3.Textfvalue = amt * (1 + rate / 100) ^ timeText4.Text = FormatCurrency(fvalue, -1)End Sub

Private Sub Command2_Click()Me.Text1.Text = ""Me.Text2.Text = ""Me.Text3.Text = ""Me.Text4.Text = ""Me.Text1.SetFocusEnd Sub

Private Sub Command3_Click()Unload MeEnd Sub

Private Sub Form_Load()Me.BackColor = vbGreenEnd Sub

49. Create an application using array of option control for changing the form back color.Dim m As LongPrivate Sub Command1_Click()Me.BackColor = mEnd Sub

Private Sub Command2_Click()Unload MeEnd Sub

Private Sub Option1_Click(Index As Integer)Select Case IndexCase 0: m = vbRedCase 1: m = vbBlueCase 2: m = vbGreenCase 3: m = vbYellowCase 4: m = vbBlackCase 5: m = vbWhiteEnd SelectEnd Sub

50. Create an application using data grid control show the details of the table book. Private Sub Form_Load()Me.BackColor = vbBlueEnd SubPrivate Sub mnu_ex_Click()Unload MeEnd Sub