440 likes | 451 Views
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.
E N D
Visual basic 6 Programs Chapter 6 - Visual Basic Schneider
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
. Private Sub Label1_click() End Sub ------------------------------------------ Private Sub cmdFinish_click() End End Sub 3
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
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
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)
code Private sub lblYellow_MouseMove(Button As Integer, Shift As Integer, X As single, y As Single) lblYellow.ForeColor= vbYellow End Sub
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
. • 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
lblName lblAge Chapter 6 - Visual Basic Schneider
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
Program 5 Chapter 6 - Visual Basic Schneider
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
. 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
Addition Chapter 6 - Visual Basic Schneider
Write this code in command1_click Chapter 6 - Visual Basic Schneider
Write this code in command2_click Private Sub Command2_click( ) End End Sub Chapter 6 - Visual Basic Schneider
11/5/1435 Tuesday Lecture 4 Chapter 6 - Visual Basic Schneider
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
. IF condition1 THEN statement(s) ELSEIF condition2 THEN statement(s) ELSEIF condition3 THEN statement(s) … END IF Chapter 6 - Visual Basic Schneider
Factorial Chapter 6 - Visual Basic Schneider
. 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
Calculator Chapter 6 - Visual Basic Schneider
. 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
. 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
Pass word Chapter 6 - Visual Basic Schneider
. 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
17/5/1435 Tuesday Lecture Chapter 6 - Visual Basic Schneider
P 325 Dialogue Boxesصناديق الحوار Q: Mention Types of Dialogue Boxes • Message Boxes [MsgBox] • Input Boxes • Built-in Dialogues
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)
. Private Sub Command1 Click( ) Symbol = 1 MsgBox”A message Box”, Symbol, “Example” End Sub
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)
. 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
Input Box FunctionP 330دالة صندوق الإدخال Q:Write a general format for the Input Box Function Sentence Variable = InputBox(Message, Title)
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
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
Built-in Dialogue Boxesصناديق الحوار الجاهزة Q: Mention four types of Built-in Dialogue Boxes that VB provides • File Dialogue • Font Dialogue • Color Dialogue • Printer Dialogue
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
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
Color Dialogصندوق حوار الألوان Private Sub Command1_Click( ) CommonDialog.Flags = CdlCCRGBInit CommonDialog1.ShowColor Text1.ForeColor = CommonDialog1.color End Sub
. Private Sub Command1_Click( ) CommonDialog.Flags = CdlCCRGBInit CommonDialog1.ShowPrinter Text1.ForeColor = CommonDialog1.color End Sub