Lesson topic: Graphic methods and procedures (2 hours
The purpose of the lesson: Learn to use graphics files, use methods, and write procedures in VisualBasic.
B) development of memory, thinking, creativity
B) to educate to write the names of methods, to use the program correctly in project creation
Type of lesson: traditional
Type of lesson: mixed
Lesson progress:
І. Organization
II. Ask questions to summarize the previous lesson:
1. How to check the error of simple programs?
2. What is the difference between error checking and step-by-step testing?
3. What are the errors in the program?
4. How many types of errors are there in the program?
III. New lesson
VisualBasic offers 3 ways to use graphics files:
v In images embedded in any graphics editor and in computer memory
You can insert files into the PictureBox graphic window on the form by copying the saved graphic files or linking to the address.
v ToolBox tool - by inserting the Line and Shape controls from the toolbar.
v You can draw points, lines, rectangles, circles, ellipses, angles, and arcs on shapes and PictureBox objects using graphical methods. We write a procedure using graphical methods to draw graphic forms.
Scale methodoffers new coordinates. When using the Scale method, the PictureBox and the shape have absolute coordinates, the size (width and height) of which is measured in a special type of unit.
Writing a scale method
[object
name] Scale (X1, Y1) - (X2, Y2)
Scale method Scale method shifted
coordinate system of the coordinates of the number
X1, Y1 - coordinates of the upper left corner of the object, X2, Y2 - coordinates of the lower right corner of the object. For example: Picture1.Scale (-10.5) - (10.5)
Pset method allows you to draw a dot on the object, write the Pset method
[object name]. Pset (X, Y) [, color]
Since the name of the object is not specified here, the Pset method is applied to the form, the coordinates of the points on the object (X, Y), the color is coded as Long. The value of the DrawWidth property can be integers 1, 2, 3 by default equal to 1. For example, Picture1. DrawWidth = 2
Line method draws straight lines and painted or unpainted rectangles on the object.
Line method writing:
[object name] .Line (X1, Y1) - (X2, Y2) [, color] [, symbol]
Here the first rectangle and the second colored rectangle are drawn. If you use the B symbol, the property that does not have a rectangle automatically accepts FillStyle = 1 (transparent). If we change this property, then the inside of the rectangle is painted, the property
FillStyle = 0 [,] [, label],If the symbol is not a color, the comma can be removed, then the symbol is taken as a color. You can change the thickness of the contours of a line or rectangle using the DrawWidth property.
The symbol is a symbol of B or BF.
Circle method We use the Circle method to draw a circle, arc, ellipse, sector on an object.
Circle method writing:
[object name] Circle (X, Y), radius [, color] [, 1st angle, 2nd angle]
[, compression ratio]]]
Since the name of the object is not specified here, the shape uses the Circle method, where (X, Y) is the center point of the circle or ellipse, the color is coded by the number Long, if the color is not specified, it corresponds to the ForeColor property, 1st angle, 2nd angle - arc and circle initial and final angles, units of measurement are measured in radians in the range from 0 to 2. If the value of the angle is not equal to 0 and has a minus sign in front of it, then the non-arc sector is drawn. When you draw an arc or sector, the movement is counterclockwise, and when you draw a circle or ellipse, the value of the angles is not recorded.
The compression ratio is a symbol.
If the given value is greater than 1, a vertical ellipse is drawn, if the given value is less than 1, a horizontal ellipse is drawn, ie the degree of elongation is determined by the compression factor. If there is no compression ratio, a circle is drawn.
Color rendering
In VisualBasic, you can color with 8 constants.
Color |
Constants |
Numerical value |
See |
vbBlack |
0 |
Red |
vbRed |
255 |
Green |
vbGreen |
65280 |
Yellow |
vbYellow |
65535 |
Blue |
vbBlue |
16611680 |
Bluish purple |
vbMagneta |
16611935 |
Light blue |
vbCyan |
16666960 |
White |
vbWhite |
16666215 |
Color rendering using the QBCOLOR function
The QBCOLOR function consists of the argument C of integers covering the range from 0 to 15. Returns the code of the given numeric values (which are numeric type Long).
For example: QBCOLOR (13) - Purple (vbMagneta)
Practical work on the computer.
1. Insert the
Command Button and PictureBox into the form, and type the following procedure.
Private Sub Command1_Click ()
Picture1.Scale (-15,15) - (15, -15)
Picture1.DrawWidth = 15
Picture1.Pset (0, 0), vbRed
Picture1.Pset (-8.8)
Picture1.Pset (8, -8)
End Sub
2. Private Sub Command1_Click ()
Picture1.Scale (-15,15) - (15, -15)
Picture1.DrawWidth = 3
Picture1.Line (-10, 10) - (10, -10)
Picture1.Line (0, 0) - (10, 10),, B
Picture1.FillStyle = 0
Picture1.FillColor = vbGreen
Picture1.Line (-8, -5) - (8, - 8), vbWhite, B
End Sub
3. Private Sub Command1_Click ()
Picture1.BackColor = vbWhite
Picture1.DrawWidth = 3
Picture1.Scale (-50, 50) - (50, -50)
Picture1.Circle (-30, 30), 15, vbRed
Picture1.FillStyle = 0
Picture1.FillColor = vbGreen
Picture1.Circle (-30, 0), 13, vbRed
Picture1.Circle (-30, -30), 15, vbBlack,,, 2.
Picture1.Circle (30, 30), 15, vbYellow,,, 0.5
Picture1.Circle (30, 5), 10, vbBcyan, 2, 5
Picture1.FillStyle = 1
Picture1.Circle (30, -30), 15, vbBcyan, -1, -5
End Sub
ToQuestions to ask:
1. How many ways does VisualBasic offer to use graphics files?
2. How is the graphics method different from graphics files?
3. What is the difference between PictureBox and Image?
4. What graphic methods do you know?
5. What functions are used when writing a graphics procedure?
Check yourself!
1. What is the function of the Line method?
A) draws straight lines and rectangles, painted or unpainted inside.
B) the given elements are written to the file sequentially with a comma
B) in quotation marks
B) data written by the print method
D) elements “; ”Or“: ”
2. What is a sign -
A) decrees
B) texts
B) files
B) the symbols b or bf
D) numbers
3. What method do we use to draw a circle, arc, ellipse, sector on the object?
A) Circle method
B) Line method
B) ForeColor method
C) DrawWidth method
D) BackColor method
4. What is the compression ratio -
A) negative sign
B) positive sign
B) data
C) files
D) decrees
5. How many ways does VisualBasic offer to use graphics files?
A) 4
B) 2
B) 3
C) 5
D) 1
Homework:
1. § 19 to state the theoretical understanding of the topic.
2. Draw a house using graphic methods.
Evaluation.
Lesson topic: Step-by-step method
The purpose of the lesson: to teach students to correct errors in Visual Basic during large and complex procedures
Development: To increase the student's interest in the subject, combining enthusiasm and ability for each lesson.
Upbringing: Educate each student to business, realism, solidarity.
Type of lesson: traditional
Type of lesson: new knowledge
Lesson progress:
І. Organization
II. New lesson
When you create a project with a large and complex procedure in VisualBasic, the project cannot be error-free. Therefore, VisualBasic offers a step-by-step error checking method. Error testing consists of 4 stages:
1. Check the truth for errors
2. Search for an error
3. Search for the cause of the error
4. Error correction.
There are 2 types of errors in the program: syntactic, logical. If you use VisualBasic, you may encounter these errors:
Project: "Finding the arithmetic mean of a number"
1. Save the project as "Error Search".
2. Enter the command button CommandButton, two textBox buttons and the Label button on the form.
3. In the form, type frtcycle, cmdcycle, txtnumber, txtone in the Name properties of the buttons.
4. Give the first text button (txtsan), the Multiline property True, and the ScrollBars property 2 (Vertical).
5. In the Name property of the command button, type "Start typing". Type "Numbers to enter" on the first record button and "Average" on the second record button.
Type the following procedure:
Private Sub cmdCycle _Click ()
Dim N As Integer
Dim kos as single, or As Single
Dim P As String
Txtsan.text = ”“
Kos = 0: N = 0
P = InputBox ("Click 'OK' after entering a number, click 'Cancel' when entering," enter the next number ")
Do until P = ”“ 'The cycle continues until you click the “Cancel” button.
N = N + 1
Txtsan.txt = Txt.san.text + P + ”“ Kos = kos + Val (P)
P = InputBox ("Click 'OK' after entering a number, click 'Cancel' when entering," enter the next number ")
Loop
If N = 0 Then
MsgBox “”
Else
Or = kos / N
Text = Str (or)
End If
EndSub
We enter a special error in the program:
Ø Do until P = ”” change the line to Do untile P = ”“.
Ø A dialog box appears on the screen.
Ø If you want to correct the error, click OK, if the error is not clear, click Help or F1.
Ø Please correct the error. This error occurs because, for example, the file name is not displayed correctly in the internal event.
Ø Loop Remove the word, an error message will appear.
Ø Check for errors and see if the program runs. To do this, press the F5 key.
Ø Remove the word if if. An error message window appears.
Ø Please correct the error.
The complexity of such errors is a logical error. The logic error is due to the algorithm not being set up correctly or the input parameter not being given correctly.
You can check the error of simple programs using the "step-by-step method".
Task:
· N = N + 1Remove the path from the program as if you forgot, run the program, enter three numbers, click Cancel. The system reports an error.
· Debug From the menu, start the program by clicking Step Into or F8.
· The project shows the first line in yellow.
· Private Sub Command1_Click ()
· All you have to do is hover your mouse over the variable to see what the values of the variables in the program are equal to
· Start the program with the F8 key.
· P = InputBox ("Click 'OK' after entering the number, click 'Cancel' when entering the input," enter the next number "), press F8.
· The number entry window appears on the screen. Enter the number "10" and click OK.
· F8 Click to check the value of the variable P.
· Р You must specify 10 for the variable.
· Press F8 until P = InputBox (click 'OK' after entering the number, click 'Cancel' when finished, 'Enter the next number').
· Check the variable Kos, it should be equal to 10.
· F8 Click, the resulting Number Input window will appear, click Cancel, the Loop line will be highlighted.
· F8 Click the button.
· "Do until P =" "'The loop continues until you click" Cancel "." The path is different, change this path. Do until P = ”“ 'Clicking the “Cancel” button stops the cycle.
· F8 Click the button.
· If N = 0 The line is different, we check that N = 0, the next time you press F8, the message "no number entered" appears.
· F8 Click End If the following EndSub rows are different.
· We will check for errors, there may be a delay in the program.
· Then we change the line Do until P = ”“ to the line Do.
· Run the program, enter the number and click Cancel, repeat this, the program will pause, press Ctrl + Break to interrupt the program. After that, the loop path is different. If we use another step-by-step check in the program, we will see that the line after Loop is different.
·
Control questions:
1. How to check the error of simple programs?
2. What is the difference between error checking and step-by-step testing?
3. What are the errors in the program?
4. How many types of errors are there in the program?
5.
Homework: preparation for theoretical understanding
Evaluation.
Project: "Finding the arithmetic mean of a number"
1. Save the project as "Error Search".
2. Enter the command button CommandButton, two textBox buttons and the Label button on the form.
3. In the form, type frtcycle, cmdcycle, txtnumber, txtone in the Name properties of the buttons.
4. Give the first text button (txtsan), the Multiline property True, and the ScrollBars property 2 (Vertical).
5. In the Name property of the command button, type "Start typing". Type "Numbers to enter" on the first record button and "Average" on the second record button.
Type the following procedure:
Private Sub cmdCycle _Click ()
Dim N As Integer
Dim kos as single, or As Single
Dim P As String
Txtsan.text = ”“
Kos = 0: N = 0
P = InputBox ("Click 'OK' after entering a number, click 'Cancel' when entering," enter the next number ")
Do until P = ”“ 'The cycle continues until you click the “Cancel” button.
N = N + 1
Txtsan.txt = Txt.san.text + P + ”“ Kos = kos + Val (P)
P = InputBox ("Click 'OK' after entering a number, click 'Cancel' when entering," enter the next number ")
Loop
If N = 0 Then
MsgBox “”
Else
Or = kos / N
Text = Str (or)
End If
EndSub
We enter a special error in the program:
Ø Do until P = ”” change the line to Do untile P = ”“.
Ø A dialog box appears on the screen.
Ø If you want to correct the error, click OK, if the error is not clear, click Help or F1.
Ø Please correct the error. This error occurs because, for example, the file name is not displayed correctly in the internal event.
Ø Loop Remove the word, an error message will appear.
Ø Check for errors and see if the program runs. To do this, press the F5 key.
Ø Remove the word if if. An error message window appears.
Ø Please correct the error.
You can check the error of simple programs using the "step-by-step method".
Task:
· N = N + 1Remove the path from the program as if you forgot, run the program, enter three numbers, click Cancel. The system reports an error.
· Debug From the menu, start the program by clicking Step Into or F8.
· The project shows the first line in yellow.
· Private Sub Command1_Click ()
· All you have to do is hover your mouse over the variable to see what the values of the variables in the program are equal to
· Start the program with the F8 key.
· P = InputBox ("Click 'OK' after entering the number, click 'Cancel' when entering the input," enter the next number "), press F8.
· The number entry window appears on the screen. Enter the number "10" and click OK.
· F8 Click to check the value of the variable P.
· Р You must specify 10 for the variable.
· Press F8 until P = InputBox (click 'OK' after entering the number, click 'Cancel' when finished, 'Enter the next number').
· Check the variable Kos, it should be equal to 10.
· F8 Click, the resulting Number Input window will appear, click Cancel, the Loop line will be highlighted.
· F8 Click the button.
· "Do until P =" "'The loop continues until you click" Cancel "." The path is different, change this path. Do until P = ”“ 'Clicking the “Cancel” button stops the cycle.
· F8 Click the button.
· If N = 0 The line is different, we check that N = 0, the next time you press F8, the message "no number entered" appears.
· F8 Click End If the following EndSub rows are different.
· We will check for errors, there may be a delay in the program.
· Then we change the line Do until P = ”“ to the line Do.
· Run the program, enter the number and click Cancel, repeat this, the program will pause, press Ctrl + Break to interrupt the program. After that, the loop path is different. If we use another step-by-step check in the program, we will see that the line after Loop is different.
Материалы на данной страницы взяты из открытых источников либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.