1 / 43

Visual basic 6

Visual basic 6. Programs. Program 1. Create a project that add a command button Change its caption to (ok), and its Name to ( cmdfinish ) Add a Label Button and change its caption to ( Welcome ) Write a code in the command button to end the application.

chaug
Download Presentation

Visual basic 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual basic 6 Programs Chapter 6 - Visual Basic Schneider

  2. Program 1 Create a project that • add a command button • Change its caption to (ok), and its Name to (cmdfinish) • Add a Label Button and change its caption to (Welcome ) • Write a code in the command button to end the application

  3. . Private Sub Label1_click() End Sub ------------------------------------------ Private Sub cmdFinish_click() End End Sub 3

  4. Program 2 color Create a program that addthree Commands Button control tools, clicking one of these tools will change the Form1 background color.Change the properties of each command button as following: ------------------------------------------------- Chapter 6 - Visual Basic Schneider

  5. Code Private Sub cmdBlue_click() Form1.BackColor= vbBlue End Sub ----------------------------------------- Private Sub cmdGreen_click() Form1.BackColor= vbGreen End Sub ---------------------------------------- Private Sub cmdRed_click() Form1.BackColor= vbRed End Sub

  6. Program 3 In this application use the Label tool and the Mouse Move Event, then write a code to: Allow the tool TextColor to be changed into yellow when the mouse pointer moves over it -------------------------------------------------- Steps: Add a Label tool and change its Captionproperty to (Yellow Color), and its Name to (lblYellow)

  7. code Private sub lblYellow_MouseMove(Button As Integer, Shift As Integer, X As single, y As Single) lblYellow.ForeColor= vbYellow End Sub

  8. Program 4 I n this application we will work with the Text Box Tool: Steps: • Start a new Project • Create a Text tool. • Delete the word Text from the Text property. • Change the Name property to be txtFont Chapter 6 - Visual Basic Schneider

  9. . • Double click the Font property for the TextBox so the Font Dialogue box appears • Select 18 Size and a Bold Italic Font Size and let the Font Style be Arial and click OK • Execute the program then enter any text in the Text Box • Add another TextBox tool change its name property to txtAge Chapter 6 - Visual Basic Schneider

  10. lblName lblAge Chapter 6 - Visual Basic Schneider

  11. Program 5 Create a new project: • Change the title bar for the form to My First Program(using caption property) • Add a command button, change its caption to Change Properties • Write a code that changes form properties to the followings: • Width=400, Height = 600 • Top = 0, Left = 0 • BackColor= RGB(100,100,200) Chapter 6 - Visual Basic Schneider

  12. Program 5 Chapter 6 - Visual Basic Schneider

  13. Program 6Q: Write a vbcode in the MouseMove event that gives the following shape when executed,then explain the code in arabic Chapter 6 - Visual Basic Schneider

  14. . Code: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)  Line (0, 0)-(X, Y) End Sub ---------------------------------------------- Chapter 6 - Visual Basic Schneider

  15. Addition Chapter 6 - Visual Basic Schneider

  16. Write this code in command1_click Chapter 6 - Visual Basic Schneider

  17. Write this code in command2_click Private Sub Command2_click( ) End End Sub Chapter 6 - Visual Basic Schneider

  18. Naming Controls

  19. .

  20. 11/5/1435 Tuesday Lecture 4 Chapter 6 - Visual Basic Schneider

  21. Control StructuresSelection Logic Structure I • F condition THEN statement • IF condition THEN           statement(s) END IF • IF condition THEN           statement(s)1 ELSE           statement(s)2 END IF Chapter 6 - Visual Basic Schneider

  22. . IF condition1 THEN           statement(s) ELSEIF condition2 THEN           statement(s) ELSEIF condition3 THEN           statement(s) … END IF Chapter 6 - Visual Basic Schneider

  23. Factorial Chapter 6 - Visual Basic Schneider

  24. . Private Sub Command1_click( ) Dim n As Integer Dim i As Integer Dim s As Long s = 1 n = Val(Text1.Text) For i = 1 To n s = s * i Next i Text2.Text = s End sub Chapter 6 - Visual Basic Schneider

  25. Calculator Chapter 6 - Visual Basic Schneider

  26. . Private Sub Command_click( ) Dim A,B A=Val(Text1.text) B=Val(Text2.text) If Option1.Value=True Then Text3.Text=A + B End if If Option2.Value=True Then Text3.Text=A - B End if Chapter 6 - Visual Basic Schneider

  27. . If Option3.Value=True Then Text3.Text=A * B End if If Option4.Value=True Then Text3.Text=A / B End Sub Chapter 6 - Visual Basic Schneider

  28. Pass word Chapter 6 - Visual Basic Schneider

  29. . Private Sub Command1_click( ) If Text1.Text="8k5" Then MsgBox “Hello in the program”, vbInformation Form2.Show Unload me Else MsgBox "Wrong pass Word”,vbCritical End if End Sub Chapter 6 - Visual Basic Schneider

  30. 17/5/1435 Tuesday Lecture Chapter 6 - Visual Basic Schneider

  31. P 325 Dialogue Boxesصناديق الحوار Q: Mention Types of Dialogue Boxes • Message Boxes [MsgBox] • Input Boxes • Built-in Dialogues

  32. Messages Boxesصناديق اظهار الرسائل MsgBox Message, Symbol, Title Q:Write a general format for the message Box(box(sentence P (325 Q: Create a New Project, add a command button then adjust its caption and let it MBOX and Box’s Title to Example and it shows OK button only P(327) Q: Create a Message Box, which contains the question mark icon and OK and Cancel buttons P(328)

  33. . Private Sub Command1 Click( ) Symbol = 1 MsgBox”A message Box”, Symbol, “Example” End Sub

  34. MsgBox Functionالإدخال عبر دالة صندوق الرسائل P 329 Q:Write a general format for the message box Function Sentence Q: Design a MsgBox (using a function)that shows: • Click yes to quit (Message) • Write a VB code that enables you to quit the program when clicking Yes button Variable = MsgBox ( Message, Symbol, Title)

  35. . Private Sub Command1_Click Dim Symbol As Integer Dim Res As Integer Symbol = 36 ‘(32+4) Res = MsgBox(“Click Yes to Quit” , Symbol, “Quit”) If Res = 6 Then End End Sub

  36. Input Box FunctionP 330دالة صندوق الإدخال Q:Write a general format for the Input Box Function Sentence Variable = InputBox(Message, Title)

  37. Page 3 31 Q: Create a project that uses two Input Boxes Num1 , Num2 then enter any two values, find the sum and receive the result in a label Tool

  38. P 331 Private Sub Form_Load( ) Dim Num1 As Integer Dim Num2 As Integer Dim Sum As Integer Num1 = Val(InputBox(“enter first number”,”Num1”)) Num2 = Val(InputBox(“enter second number”, ”Num2”)) Sum = Num1+Num2 Label1.Caption = Label1.Caption&Str(Sum) End Sub

  39. Built-in Dialogue Boxesصناديق الحوار الجاهزة Q: Mention four types of Built-in Dialogue Boxes that VB provides • File Dialogue • Font Dialogue • Color Dialogue • Printer Dialogue

  40. P 333-334Project – Components – Common Dialogue Control 6Components – OK – Common Dialogue Control P 335 • File Dialogue Private Sub Command1_Click( ) Common Dialog1.showOpen If CommonDialog1.FileName = “ “ Then Text1.Text = “No File is Selected” Else Text1.Text = CommonDialog1.FileName End if End Sub

  41. Font Dialogueصندوق حوار الخط P336 Private Sub Command_Click( ) CommonDialog.Flag = 1 ‘ Screen Fonts CommonDialog1.ShowFont Text1.FontName=CommonDialog1.FontName Text1.FontSize = CommonDialog1.FontSize Text1.FontBold = CommonDialog1.FontBold End Sub

  42. Color Dialogصندوق حوار الألوان Private Sub Command1_Click( ) CommonDialog.Flags = CdlCCRGBInit CommonDialog1.ShowColor Text1.ForeColor = CommonDialog1.color End Sub

  43. . Private Sub Command1_Click( ) CommonDialog.Flags = CdlCCRGBInit CommonDialog1.ShowPrinter Text1.ForeColor = CommonDialog1.color End Sub

More Related