Antipyretics for children are prescribed by a pediatrician. But there are emergency situations for fever when the child needs to be given medicine immediately. Then the parents take responsibility and use antipyretic drugs. What is allowed to give to infants? How can you bring down the temperature in older children? What medicines are the safest?
Mike McGrath “Visual Basic Programming for Beginners” Eksmo, 2017, 192 pages (25.0 mb. pdf)
The book is a step-by-step programming tutorial for Visual Basic (VB) for beginners. Applications written in this language work both with Microsoft Office and on the Internet, which greatly expands its capabilities. Full and understandable instructions are given for those who will independently learn the VB language. Using illustrative examples, the author explains how to easily, with minimal effort, master the basics of programming in Visual Basic and start developing your own programs for Windows. With the help of the developed programs, you can automate the work of your computer and increase its performance. All examples in the book are designed to visual studio 2017. This is a professional development environment for Visual C++, Visual , Visual J# and Visual Basic.
Microsoft Visual Studio Express is a simplified version of Visual Studio (missing some features) designed specifically for those who are learning to program. Unlike a full-featured Visual Studio product, Visual Studio Express is absolutely free program. With this environment, you can create Windows applications using the Visual Basic language (or other languages) to develop code. The book is addressed to novice developers. ISBN 978-5-699-81136-6
1. First steps
Introduction
Install Visual Studio
Exploring the Development Environment
Create a new project
Adding a visual control
Adding function code
Saving projects
Reopening projects
Conclusion
2. Setting parameters
Form Properties
First Encounter with the Properties Panel
Editing Property Values
Property value encoding
Applying Calculated Values
Applying Custom Values
Data Entry Request
Setting Dialog Box Properties
Conclusion
3. Using controls
Tab order
Button control
TextBox Control
ComboBo Control
Label control
PictureBox Control
ListBox control
CheckBox Control
RadioButton control
WebBrowser control
Timer control
Conclusion
4. Language learning
Program elements
Declaring Variable Types
Understanding Variable Scope
Working with arrays of variables
Arithmetic and logical operations
Code branching
Looping code
Calling Object Methods
Create a subroutine
Passing parameters
Creating a Function
Mathematical calculations
Random number generation
Conclusion
5. Build Applications
Program Plan
Assigning static properties
Interface design
Initializing dynamic properties
Adding uptime functionality
Program testing
Application publishing
Conclusion
6. Solution of problems
Error detection in real time
Fixing compilation errors
Debugging code
Setting breakpoints for debugging
Run-time error detection
Catching Runtime Errors
Get help
Conclusion
7. Expanding the interface
Color, Font, and Image Selection Dialog Boxes
Open, Save, and Print Dialog Boxes
Creating an application menu
How to make the menu work
Adding more forms
Managing Multiple Forms
Playing sounds
Media playback
Conclusion
8. Creating Visual Basic Scripts
Introduction to VBA macros
Creating Word Macros
Create Excel Macros
Running complex macros
Declaring Variables
Input validation
Merging text files
Extracting data from the registry
Conclusion
9. Working with data
Reading text files
Stream reading lines of text
Reading Excel Spreadsheets
Reading XML Files
Create an XML dataset
Conclusion
10. Using Databases
Introduction to databases
Database Design
Database creation
Adding tables to the database
Defining Table Columns
Creating Table Links
Entering tabular data
Create datasets
Adding Data Controls
Creating Data Links
Create your own queries
Conclusion
Subject index
Before you start programming directly, you need to learn how to use the environment of the language proposed for learning. And since it is in Russian, it will not be difficult. | So, we have to find out: | where to get Russian BASIC; | how to launch it and get started;
How to enter program text in the editor window
The cursor blinks in the editor window - a horizontal luminous dash indicating where the text of the program will be entered when typing it from the keyboard. | If you notice that you typed something incorrectly, there are several ways to correct your mistakes. | Removing extra characters.
Launching the program for execution. Saving and opening files in BASIC.
How to run the program? When you have written a program and want to see what, in fact, came out of it, you must press the F5 key. The program will be executed if there are no syntax errors, and then you will see the results of its work and the message at the bottom of the screen "To continue, press any key."
Language alphabet. Variable and what changes in it.
In any textbook of a foreign language, its alphabet is first given, that is, a set of symbols for writing words, sentences and all kinds of concepts of this language. The BASIC language also has an alphabet, which contains the following characters:
Arithmetic in Basic
Before moving on ("How difficult it is to move on" - from a song by Boris Grebenshchikov), it is necessary to recall that in those distant times, when algorithmic languages were just emerging, and the phrase "personal computer" caused those who heard him to doubt his sanity who said, so, in those very days it was believed that a computer (from the English compute - to calculate), i.e.
assignment operator. The syntax of the assignment operator.
Imagine that you have developed an algorithm, thought through which variables will participate in it, came up with names for them, and what's next? How to tell the computer their values? How to change these values? So, we get acquainted with the first operator of the BASIC language - the assignment operator.
Displaying the results
So far, we have entered the original data into the computer using the assignment operator. Other input methods will be discussed in one of the following chapters. | Now I want to consider the more important at first component of BASIC - the output of the results obtained on the monitor screen, as well as the output of all kinds of text messages. That is, we are introduced to the powerful print statement.
BASIC Standard Functions
Before we forget elementary arithmetic in BASIC and the output of results (I hope you can do it, and in a finished, beautiful form with hints), you need to familiarize yourself with the standard functions of the BASIC language in order to fully experience its computational abilities.
Displaying data at a given location on the screen
A computer screen in text mode is a conditional grid of columns and rows. In standard mode, there are 80 such columns (i.e., no more than 80 characters can fit in a line), and 25 rows. | BASIC has an operator that allows you to control the output of data on the screen, which significantly increases the user's perception of programs.
We enter data. INPUT statement.
What is good about BASIC? The fact that it allows you to write programs that are very user-friendly, asking him for parameters peculiar only to him and solving the task for very specific data of a very specific person or any other object.
DATA and READ statements
There is another way to enter data. It is applied in the event that these data are known in advance. Then we organize a kind of warehouse in the program (using the data operator), and then, using the read operator, we sequentially read this data into the requested variables in which they are stored and processed.
Visual Basic 6.0 - Tutorial for beginners - Lukin S.N. - 2001.
This is a tutorial. That is, the book was written with the expectation that, having studied it without outside help, you will be able to write programs in Visual Basic without outside help and execute them on a computer without outside help. The author has made special efforts to make the presentation understandable. Everything is explained with examples. Consideration of almost every topic ends with tasks for drawing up a program (there are 132 such tasks in total). The vast majority of tasks are provided with answers, so that the reader can effectively control the assimilation of the material.
If you want to learn how to program, but have never written a single program in your life and have a poor idea of how a computer works, read this book from beginning to end - you will learn to program and learn everything you need about a computer device.
If you are interested in programming games, then know that this book is focused on this. After studying it, you will be quite ready to create your own games like sea battle, tic-tac-toe, tank battle (where many tanks move across a square field), shooting games. However, more about the games - below.
Let's say you're a high school student or a first-year student of Visual Basic programming, and you're about to take an exam on it. You feel that you are "at zero" and DON'T UNDERSTAND ANYTHING and don't even know where to start. In this case, by studying the book and completing the tasks given in it, you will have a solid knowledge of the basics of Visual Basic. Is that enough?. After all, Visual Basic is a rich Christmas tree, on which there are a great many toys. My book tells everything you need for a beginner: about the trunk and main branches of the Christmas tree, about how toys are attached to the branches, the most interesting toys are considered. However, where is the guarantee that your teacher does not prefer others? Maybe take a thicker book?
If you take any of the thickest books on Visual Basic, then you will certainly not find everything that is required of you. There are too many toys in Visual Basic even for a three-volume book. So learn the basics of Visual Basic first with a book like this one. Then either try to find a thick book that talks specifically about what you need, or use the Help system for this. It is difficult to read a thick book right away - it is usually not intended for beginners, even if it claims the opposite. However, a thick book may not be needed - this book covers everything that a reasonable teacher might ask in the first year of study.
If you are an experienced programmer in visual development environments, but want to learn Visual Basic as well, you do not need this book - the presentation is intended for beginners.
If you do not have a computer at hand, then you are in trouble. Without a computer, with only one book, you can only learn how to write a program text on paper. Of course, and this is a lot, but it is reminiscent of reading on an empty stomach, when the refrigerator is empty, the recipe for making a luxurious steak. In the visual programming environment for Windows, which is Visual Basic, program text is far from everything.
The book teaches not only to write programs, but also to execute programs on a computer. All you need to know ahead of time is where the computer's power button is. Everything else in the book is explained, including how to install Visual Basic on your computer.
Chapter 0. Preface 8
0.1. Who is this book for? eight
0.2. Tasks, games. eight
0.3. Why Visual Basic? 9
0.4. What kind of computer do you need and what version of Visual Basic? ten
0.5. Summary with 10 recommendations
Part I Programming without programming 12
Chapter 1 First Steps 13
1.1. What is a program? 13
1.2. Not a program, but a project 14
1.3. First steps - by the handle 14
Launching Visual Basic 14
Placing objects on form 15
Writing a Program 16
Saving, creating, opening, closing a project 17
How to Respond to Visual Basic Error Messages 18
Chapter 2. Project - "Calculator" 20
2.1. Task for project 20
2.2. We design 20
2.3. Properties of Forms and Controls 21
2.4. Names and inscriptions 21
2.5. Programming. Project ready 22
2.6. Some other properties of objects 23
2.7. Putting a photo on the calculator 24
2.8. Music in project 24
Music in buttons 25
Playing Audio CDs 26
Player of your favorite hits 26
2.9. Coordinate system 27
2.10. Message output - MsgBox 28
2.11. User menu 28
2.12. Cinema in Project 30
2.13. Something needed in the end 30
Comments 30
Moving a long statement to the next line 31
Writing Multiple Statements on One Line 31
Turning our calculator into an independent program 31
How we will further improve our calculator 31
Chapter 3 Working with Visual Basic 32
3.1. What you need to know and be able to before you sit down at the computer 32
3.2. Installing Visual Basic 32
3.3. How to work on a project in Visual Basic 33
3.4. Loading and Exiting Visual Basic 33
3.5. Save the project to disk. Loading a project from disk 33
3.6. Visual Basic 35 windows
3.7. Visual Basic 36 main menu
Toolbar 37
3.8. Transferring your project to other computers 37
Part II. Visual Basic Programming - First Level 40
Chapter 4 Variables 41
4.1. Variables. Assignment operator 41
4.2. Declaring Variables 43
InputBox 43
Data types 44
Variables and memory 45
What does the assignment operator do with memory 46
interrupt mode. Step by step program execution 46
4.3. More about names 48
4.4. Maths. Writing arithmetic expressions 48
4.5. Data types and calculation precision 50
Integer and Long - integers 50
Single and Double - decimals 50
Whole numbers or decimals? Numeric type Currency 51
Not So Obsolete Ways of Declaring Variables 51
Formatting the result 51
4.6. How to create a simple computing project 52
4.7. String variables 54
4.8. How to display information with the Print 55 statement
4.9. Dialogue with a computer 56
4.10. How to display information in a text field 57
4.11. Let's look around 57
Chapter 5 Branching Programs 58
5.1. What is choice (branching) 58
5.2. The Conditional If Statement or How the Computer Makes Choices 58
5.3. Rules for writing a single-line operator If 60
5.4. Random variables 61
5.5. Multiline If 62
5.6. Program step recording 64
5.7. Nested if statements. Boolean operations and expressions 64
Nested If Statements 64
Logic operations 65
Boolean expressions 65
5.8. Select Case 66 Variant Operator
5.9. Improving the calculator. 68
Checking if numbers are entered in a text field 68
Division-by-zero prohibition 69
We put the password on the calculator 69
5.10. Function MsgBox 70
Chapter 6 Cyclic Programs 72
6.1. GoTo jump statement. Cycle. Tags 72
Moving objects around the screen 74
6.2. Exit Loop with If 74
6.3. Loop statements Do 75
Do... operator. loop 75
Do... operator. Loop While 76
Do... operator. Loop Until 76
Do While... statement. Loop 77
The Do Until ... statement. Loop 77
Difference between Do 78 operator options
Exit Do Statement 78
Obsolete Loop Statement 79
6.4. For 79 loop statement
Exit For 80 Statement
6.5. Let's look around 81
Chapter 7 Debugging a Program 82
7.1. Error types. Error messages. 82
7.2. Program debugging. Debug windows. Debugging modes. 82
Chapter 8 Typical Small Programs 86
8.1. Calculating cyclic program 86
8.2. The role of errors 86
8.3. Counters 87
8.4. Totalizers 88
8.5. Embedding loops in branches and vice versa 89
8.6. Nested Loops 89
8.7. Finding the maximum of 90 numbers
Chapter 9 Graphics 92
9.1. Objects. Their properties, their events, their methods 92
9.2. Three Ways to Draw 93
9.3. Method One - Loading Pre-made Images in Visual Basic 94
Image File Types 94
Adjusting Image Sizes 94
9.4. Method 2 - Line and Shape Objects 96
9.5. Mutual overlap of objects. ZOrder Method 96
9.6. Color in Visual Basic 97
9.7. Method 3 - Draw using graphic methods 98
Method Pset 100
Line 100 method
Circle 101 Method
CurrentX, CurrentY, Step 101
Method Cls 102
Method Point 102
PaintPicture Method 102
9.8. Using Variables in Drawing 103
9.9. Using Random Variables in Drawing 105
Chapter 10 Procedures 106
10.1. Why user procedures are needed 106
10.2. Stop, End and Exit Sub Statements 108
10.3. Variables instead of numbers 110
10.4. Constants 111
10.5. Procedures with parameters 111
Parameter types 113
Chapter 11. Working with the timer, time, dates 115
11.1. Data type Date 115
Date and Time Functions 116
11.2. Timer 117
Cycle without cycle 117
11.3. Project "Alarm clock-stopwatch" 118
Getting to know the Boolean 121 type
Making an alarm clock 121
Introducing the enumerated data type 124
Timer and Simulation 126
11.4. Animation 127
Animation using graphic methods 127
Moving objects 127
"Moving" the properties of objects 128
Cartoon 128
About transparent color 129
Chapter 12 Working with the Mouse and Keyboard 130
12.1. Mouse operation 130
MouseDown and MouseUp Events 130
MouseMove event 131
Mouse draws 132
12.2. Keyboard operation 132
KeyDown and KeyUp events 132
12.3. Project - Racing (game) 133
12.4. Task for the game “Torpedo attack 140
Part III. Visual Basic Programming - Second Level 141
Chapter 13 Arrays 142
13.1. Variables with indices 142
13.2. One-Dimensional Arrays of Variables 142
13.3. 2D arrays 144
13.4. What are arrays 145
13.5. Using Arrays in Game Programming 145
13.6. Control Arrays 147
Chapter 14
14.1. Type Variant 149
14.2. Custom Data Type 149
14.3. Collections 151
Object variables 151
Collections 152
14.4. Frame 153
Chapter 15 Controls 154
15.1. Checkbox 154
15.2. Switch (OptionButton) 155
15.3. Scrollbars (HScrollBar and VScrollBar) 156
15.4. Slider, Progress Bar 156
15.5. List (ListBox) and combo box (ComboBox) 157
List (ListBox) 157
ComboBox ("Dropdown" option) 157
ComboBox ("Simple Combo" variant) 158
ComboBox ("Dropdown Combo" variant) 158
Properties, events, and methods of the ListBox and ComboBox controls. 158
15.6. Introduction to other controls 159
MonthView and DTPicker controls 159
Up Down 160
Elements DriveListBox, DirListBox, FileListBox 160
RichTextBox 161
ListView and TreeView 161
Tab (TabStrip) and Status Bar (StatusBar) 161
MSChart 161
Picture Clip 161
Image Combo 161
MS Comm 161
Chapter 16 Lines, Files, Error Handling 162
16.1. Lines 162
ASCII table 163
16.2. Files 163
16.3. Shell function 167
16.4. Error processing. Statement On Error 167
Chapter 17. Functions. Procedure and Function Parameters 169
17.1. Functions. Function parameters 169
17.2. Local variables 170
Static variables 172
17.3. Arrays as parameters 172
17.4. Passing parameters by reference and by value 173
17.5. Induction. Recursion 173
17.6. Sorting 175
17.7. Objects as procedure parameters 176
Chapter 18
18.1. What is a Windows application "made of" 178
18.2. CommonDialog control 178
Example of opening and saving files using the Common Dialog element 179
18.3. Toolbar 180
18.4. Project - " Graphics editor" 182
Chapter 19 Projects with Multiple Forms and Modules 185
19.1. Working with multiple forms 185
19.2. Code modules 186
19.3. Project structure. Project Explorer window. 186
Working with multiple modules 186
Working with multiple projects 187
19.4. Visibility zones 187
Variable scopes 187
Procedure visibility zones 188
Scope of Constants and Types 188
19.5. Shading 189
19.6. Name prefixes 190
19.7. Why all these difficulties? 190
Chapter 20 User Objects 193
20.1. Encapsulation - "Object in a Case" 193
20.2. Game "Sachok". Problem Statement 194
20.3. Timer and general mechanics of project 195
20.4. Design phase 195
20.5. How to create objects 195
20.6. Creating a catcher 196
User object - brain without body 196
How to create an object by its class 196
20.7. We create a ball. Completing the project 199
20.8. More about objects 202
Form as object 202
Read-only properties 202
Inheritance, polymorphism 203
Chapter 21 Visual Basic and the Internet 204
21.1. Understanding the Internet, Web Pages, and HTML 204
21.2. Creating a Web Page 204
21.3. Script on Web page 205
21.4. Local Disk Access 207
21.5. Own browser 209
Chapter 22 Visual Basic and Databases 210
22.1. Understanding Databases 210
22.2. Create a database stub using Visual Data Manager 211
22.3. Working with databases. Data and DBGrid controls. SQL language. 212
Chapter 23
23.1. Visual Basic 215 Uncovered Features
ActiveX 215
Windows API 215
Multiple document interface - MDI 215
OLE 215
23.2. A moment between past and future 215
Appendix 1: Essential information about your computer and program 218
Chapter 24
24.1. What is a computer. First introduction to the program. 219
24.2. How a person communicates with a computer 220
Chapter 25. Programming and Programming 221
25.1. List of commands. Command and program modes 221
25.2. What is important to know about the 222 program
25.3. The concept of a procedure. Can a robot get smarter? 222
25.4. Computer program in machine language 223
25.5. Programming languages 223
25.6. An example of a real computer program in Logo 225
25.7. The sequence of the programmer's work on the computer 226
25.8. Basic programming techniques 226
Chapter 26 Computer Design and Operation 229
26.1. How a computer is arranged and works 229
26.2. Device and dimensions of RAM 230
26.3. Interaction of programs in memory 231
26.4. Computer external devices 231
26.5. Coding information in a computer 234
Appendix 2. Working in Windows. Entering text 236
Working with Windows 236
Turning the computer on and off. First steps 236
Working with Windows 236
Files and folders 237
File and folder names 238
Conductor 238
logical drives. File address (path, path to file) 239
How to enter a program into a computer or work with text in text editor 239
Working with a single line of text 239
Working with multiple lines 241
Code window - a small window on a large sheet with text 242
Copying, moving, deleting text fragments 242
Magic Cancel and Backspace Buttons 243
Problem solving 244
References 270
Index 272
On the one hand, you can make lasagna using a template semi-finished product, on the other hand, this approach is of little use when training future chefs.
However, you can start programming in Visual Basic. The main thing is not to be distracted by GUI and create the first programs as console applications. You are unlikely to find textbooks and tutorials dedicated to programming in the console, and therefore we will try to teach you the basics of it on the pages of our magazine. And in an understandable format.
To get started, download the latest edition of Visual Studio 2010 ( free version Express is available at www.microsoft.com/express/downloads/) and will be installed on the user's PC. We will begin to get acquainted with classical algorithmic constructions on the example of the game "Guess-ka". Let the computer think of a number from up to 100, and you will try to guess it in seven attempts. Your home PC will help you with the phrases "flight" and "underflight".
So, "Start Programs Microsoft Visual Studio 2010 Express Microsoft Visual Studio 2010 Express". In the window that opens, go to the "File" menu, select the "Create project" item and select the line "Console application" in the drop-down list. Give the project a name (default is ConsoleApplication1). And even here you will see four "free" lines of the future program:
Module Module1
SubMain()
End Module
Now, in the main procedure (between the second and third lines), paste the code of our game - a little lower we will analyze it in parts (see listing).
At this point, an inexperienced beginner will twist his finger at his temple, and an experienced programmer will sincerely smile. The numbers on the left are the classics. Lines of code in the BASIC language have been numbered since 1964, when three commands were presented in the first programming language manual Beginner's All Purpose Symbolic Instruction Code (BASIC):
10 LET X= (7+8) / 3
20 PRINT X
Now it is rather an atavism, and in the last century the presence of string numbering was determined by certain goals. We will use it to make it easier to parse the code piece by piece.
Line 10 The DIM statement declares the name and type of one or more variables. In this case, we have declared three integer variables: i - will be used in the loop; n - hidden number; p - our variants of the hidden number.
Lines 20 and 30 we will explain in pairs. The RND () function returns a random real number (of type Single) in the range from to 1. We multiplied the random number by 100 to expand the range from to 100. But the Math.Round () function, in fact, is superfluous in our program, but nevertheless let it be. It rounds the resulting number to an integer value. However, the variable n is declared as an integer, which means that when the program is executed, the fractional part of the hidden number would be cut off automatically. The Randomize() function initializes the generation of random numbers, otherwise the intended number will always be the same.
Lines 40 and 50 print the welcome phrases to the screen in console mode.
Lines 60 to 180 are the key lines in our code - this is a cyclic construction. Instructions 70 to 170 are called the loop body. Our cycle is destined to repeat itself 7 times - those same 7 attempts to guess the intended number. With each pass (iteration) of the loop, the value of the counter i will increase from 1 to 7 in line 180. Moreover, the value of the variable i will play an important role in line 190, but more on that later.
Pay attention to the already familiar statement in line 80. Here, the output string is formed dynamically, depending on the value of the variable i. And the Str(i) function turns a numeric variable into a regular string so that the informative phrase “This is your 1st attempt. Enter number:.
The user enters a value into the p variable on line 90. If you enter here not a number, but some other character, you will get an error. In the future, we will learn how to process such variants of events, but for now we will not dwell on this.
The construction from the 100th to the 170th line is called branching. Depending on the fulfillment of one or another condition, certain commands are carried out. Let's say you guessed right and the entered p is equal to the intended n. Then the computer will execute the statements from lines 110 and 120. By the way, the Exit For command is needed in order to complete the execution of the running cycle 60–180 in case of victory and transfer control to the operator on line 190.
Line 140 will be used in the algorithm if the input p is greater than the intended n. And line 160 will be executed if the input p is less than the intended n. Is it really that simple?
The branching construction in lines 190 to 220 will work if the value of counter i is equal to 8 at the exit from the loop. To clarify: if you guessed the intended number on the last, 7th, attempt, then the value of i would be equal to 7 And if it is equal to 8, then the loop ended by itself, the "happy" Exit For statement from line 120 was not executed.
Well, the last statement from line 230 expects any one (!) character to be entered into the console. If not for him, then the written console application would have worked without errors and immediately closed. By the way, try instead of Console.ReadKey () to write a GoTo 30 statement. Start debugging the application with a key. What happened in the end? If you don't understand something, position the cursor on GoTo and press the "Help" key to help you.
And next time we will program an even more interesting console game.