Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 - Visual Basic Schneider

Similar presentations


Presentation on theme: "Chapter 6 - Visual Basic Schneider"— Presentation transcript:

1 Chapter 6 - Visual Basic Schneider
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 3

4 Chapter 6 - Visual Basic Schneider
Program 2 color Create a program that add three Commands Button control tools, clicking one of these tools will change the Form1 background color.Change the properties of each command button as following: 1 st command button 2 nd 3 rd Name cmdBlue cmdGreen cmdRed Caption Blue Green Red Chapter 6 - Visual Basic Schneider

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

6 Program 3 In this application use the Label tool and the Mouse Move Event, then write a code to: Allow the tool Text Color to be changed into yellow when the mouse pointer moves over it Steps: Add a Label tool and change its Caption property 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 Chapter 6 - Visual Basic Schneider
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 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

10 Chapter 6 - Visual Basic Schneider
lblName lblAge Chapter 6 - Visual Basic Schneider

11 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

12 Chapter 6 - Visual Basic Schneider
Program 5 Chapter 6 - Visual Basic Schneider

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

14 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

15 Chapter 6 - Visual Basic Schneider
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 Tool Name Prefix Combo box cbo Check box chk
Command button cmd Directory list box dir Drive list box drv File list box fil Frame fra Form frm Grid grd Horizontal scrollbar hsb Image img Label lbl

19 . Tool Name Prefix line lin List Box list Menu mnu Ole client ole
Option Button opt Picture Box pic Shape Timer shp tmr

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

21 Control Structures Selection Logic Structure
F condition THEN statement IF condition THEN           statement(s) END IF           statement(s)1 ELSE           statement(s)2 Chapter 6 - Visual Basic Schneider

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

23 Chapter 6 - Visual Basic Schneider
Factorial Chapter 6 - Visual Basic Schneider

24 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

25 Chapter 6 - Visual Basic Schneider
Calculator Chapter 6 - Visual Basic Schneider

26 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 . Chapter 6 - Visual Basic Schneider

27 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

28 Chapter 6 - Visual Basic Schneider
Pass word Chapter 6 - Visual Basic Schneider

29 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

30 Chapter 6 - Visual Basic Schneider
17/5/ 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 صناديق اظهار الرسائل
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) MsgBox Message, Symbol, Title

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 Function P 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-334 Project – Components – Common Dialogue Control 6 Components – OK – Common Dialogue Control
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


Download ppt "Chapter 6 - Visual Basic Schneider"

Similar presentations


Ads by Google