Visual Basic (VB) is a general object-based programming language developed by Microsoft Corporation. It is a structured, modular, object-oriented visual programming language that includes an event-driven mechanism to assist the development environment. It is a language that can be used for the development of Microsoft's own products. "Visual" refers to the way to develop a graphical user interface (GUI) - there is no need to write a lot of code to describe the appearance and location of the interface elements, just add a pre-built object to a point on the screen. "Basic" refers to the BASIC (Beginners All-Purpose Symbolic Instruction Code) language, which is one of the most widely used languages ​​in the history of computing technology. Visual Basic is derived from the BASIC programming language. VB has a graphical user interface (GUI) and a rapid application development (RAD) system that can easily connect to databases using DAO, RDO, ADO, or easily create Active X controls for efficient generation of type-safe and object-oriented applications. [2] . Programmers can easily build an application quickly using the components provided by VB. (1) Language features of VB Visual development environment: what you see in interface design; object-oriented programming: program and data encapsulation as an object, in the toolbox are all one class, such as the commandbutton class, when you drag it out of the toolbox, It is instantiated as an object named command1, if you drag 2 commands, it is 2 different objects; event-driven programming: VB programs have no obvious entry and exit, are waiting for the user or system or code to trigger An event, and then perform the task corresponding to the event (2) Working mode of VB Design mode, run mode, interrupt mode; there is no way to modify the code and design interface window in the run mode. (3) VB file type Form file frm; program module file bas; class module file cls; project file vbp; project group file vbg; resource file res; save project should save project file vbp and form file frm. (4) VB window Any window that is closed can not be found, should be found under the view menu, toolbox window, code window, form layout window, immediate window (you can query the program to run object values ​​in interrupt mode, ctrl+G opens immediately window) (1) The basic concept of object-oriented Classes: Abstractions of objects with similar properties and methods, such as universities; Objects: Class instantiation becomes an object, each object has its own properties and methods, such as Tianfu College of Southwestern University of Finance and Economics. Attribute: The static feature of the object. The most important attribute is name. The name of the object in VB cannot be omitted, and it cannot be modified during the running of the program. Event: The effect of the person or system on the object, the object is passive. For example, load, unload, timer; click, etc.; method: the behavior of the object, the opponent is the initiative, such as move, show, hide and so on. (2) VB development process The first step of analysis and drawing flow chart The second step interface design The third step is to write code The fourth step of the test run (1) Format of VB writing code The case of letters is not distinguished in VB code. Multiple statements can be written on the same line, separated by a colon ":". A statement can be written on the same line or on multiple lines. The continuation line symbol is a space underlined with "_". Comment statements begin with Rem, and single quotes "'" can also be used. The latter comment content can appear directly after the relevant statement. Added "Block Comments/Cancel Block Comments" in VB6: In code mode, right click on the toolbar and select "Edit" in the popup menu... The naming rules for variables and constants: there are numbers, letters, underscores; letters are the first character; no more than 255 characters; cannot be named with VB keywords and system constants (2) Basic data type of VB String type: String with "" double quotes as delimiter Declare a string variable without specifying the string length: dim s as string Example: dim s as string S="China" Print len(s) „ length is 4 bytes S=â€abs†Print len(s) „ length is 3 bytes Declare a fixed-length string, followed by * to specify the length of the string dim s as string * 8 example: Dim s as sting * 6 Dim a as integer S=â€12345678†Print len(s) „ length is 6 bytes a=len(s) Print len(a) „ is 2 bytes in length, if it prints other types of length, its data type The number of bytes occupied Date type Use "" double quotes or ##äº•å· as delimiter Example: dim a as date A=#4/20/1999# A=A-10 Print A „ #4/10/1999# minus the number of days Object type Object type variables can be used to reference various objects in a program. The use of object types is divided into declarations. Assignment, representing three steps, similar to taking a small name for the control example: Dim a as commandbutton Set a=command1 A.caption=â€hello†„equivalent to command1.caption=â€hello†Variant type Variant declaration mode dim c or dim c as variant example: Dim a ,b as double „a is a variant The variant is that the value is empty before the variable is assigned. Variant type is the data type can be changed according to the assignment value Example: Dim A A=â€88†„A is the string “88†A=A+10 „A value is 98 (3) Declaration of VB constants Symbolic constant declaration: The keyword is const and must be initialized at the time of declaration Symbolic constant declarations are implicit and explicit example: Const a as string=â€123†Explicitly declared Const a = true implicit declaration (4) Declaration of VB variables Variable declaration: the keyword is dim, the variable must be defined, and then used Variable declarations are implicit and explicit example: Dim a as double Dim a%,b# (5) VB operator Operator classification Arithmetic operator: () ^ * / \ mod + - Relational operator: " 》 = "= 》 = "" Logical operators: not and or xor eqv imp Runner priority Arithmetic operator "relational operator" logical operator Priority order: The top-to-bottom correspondence is from high to low, and the same row has the same priority, and the program is executed sequentially. Arithmetic operator (highest priority) () Sin cos„ ^ * / \ Mod + - Relational operator 》 》= 《= = 《》 Logical operator (lowest priority) Not And Or Xor Eqv Imp Operator Division / \ mod : / is the real division, returning the business 23/5 = 4.6 \ is divisible 23\5.8=3 23\5.2=4 Mod returns the remainder 23mod5.8=5 23mod5.2=3 1mod2=1 + operator: both sides are strings to do string concatenation "1" + "2" = "12" One side is the value of the string, and the string is converted to a value plus 1 + "2" = 3 Both sides are numerical values ​​plus 1+2=3 The + sign has a higher priority than & 300" & "123" + 200 = "300323" Relational operator: The result of the operation is true or false 1 "=2 is true "a" ""b" compares ASCII "abc" "abd" compares ASCII from the first character Logical operator: not invert And take two and both are true to be true Or is true if it is true or one is true Xor XOR is true to true, the same is false Eqv is the same or the same as true, the difference is false Imp implies true imp false to false other are true (6) VB function Mathematical operation function Abs: takes the absolute value of the parameter, if the variable is not initialized, it is 0 abs(-10)=10 Int: rounded, when it is negative, returns the first negative integer less than or equal to the parameter int(-1.1)=-2 Fix: rounds, when it is negative, returns the first negative integer of the parameter greater than or equal to fix(-1.1)=-1 Exp: how many times e is returned Log: returns the natural logarithm of the parameter Len: take the length of the string, len ("abcdefg") = 7 len ("white") = 4 Trim: remove the spaces on the left and right sides of the string String: How many strings are returned in succession, the first character string(3,"abc")=â€aaa†Lcase: uppercase letters are lowercase lcase("ABcd")=â€abcd†Ucase: lowercase letters are capitalized Ucase ("ABcd") = "ABCD" Left: Returns the number of characters from the left of the string, if the number is greater than the length of the full return Left("abcdef",3)=â€abc†Right: Returns the number of characters from the right of the string. If the number is greater than the length, it returns. Right("abcdef",3)=â€def†Mid: returns a string of the specified length from a position in the middle Mid("abcdef",3,2)=â€cd†Instr: Returns the position of the specified string in another string Instr(1,"abcdef","de")=4 instr(4,"abcdef","cd")=0 Date function Type conversion function Other functions Cstr: convert the value to a string Val: Convert a string to a number Rnd: Generate random numbers Int(Rnd()*90+10) The range is 10-99 Int(Rnd()*99+1) range is 1 - 99 (1) inputbox function The inputbox is used to receive input from the user's keyboard data and only receive one data input. Syntax format of inputbox: inputbox ("prompt information", "title", "default value") The length of the prompt message cannot exceed 1024 bytes. If the dialog title is not written, the default is project 1, which is different from "" empty title. The data type returned by Inputbox is string, so it usually needs to be added when returning a numeric type. Val function converts a string to a numeric value (2) msgbox function The msgbox function is used to prompt the message and accept the user's feedback click button information The syntax of msgbox: Msgbox ("hint information", dialog button combination + icon + default button, "title") The length of the prompt message cannot exceed 1024 bytes. If the dialog title is not written, the default is project 1, which is different from "" empty title. The data type returned by Msgbox is the integer type, that is, the user returns the VB constant such as vbyes and vbno after clicking the message box button. For details, please refer to the corresponding table in the book. (3) msgbox statement The same thing about the msgbox statement and the msgbox function is to give a message prompt. The difference between the msgbox statement and the msgbox function is that the statement has no return value, that is, after the user clicks the message box button, there is no information returned. Other grammar rules, including the combination of dialogs, are exactly the same as the msgbox function. (4) print method The print method is used to output data on a form or on a printer. Print alone is to print a blank line Print followed by ; the number is output in a row After the print is added, the number is output as an output area with 14 characters. Tab(n) is the absolute distance Spc(n) is the relative distance label The class name is label, and the instantiated object name defaults to label1, which is the name attribute. Caption: Display the text content of the label, such as label1.caption=â€Welcome vb†Backstyle: Set the label transparency effect, 0 is transparent, 1 is opaque Text box The class name is called textbox, and the instantiated object name defaults to text1, which is the name attribute. Text: used to display or get the content of the text box, for example: text1.text=â€12†shows 12 to Text box, a=text1.text gets the content entered in the text box Alignment: Alignment of text boxes Enable: Set the text box is not available Visible: Set the text box to be visible or not Tooltiptext: set the prompt message after the mouse is placed Passwordchar: Enter or display the symbol of the password Maxlength: Set the maximum length of the input characters. If you enter 0, you can enter any length. Change event: triggered when the content of the text box changes Command button The class name is called commandbutton, and the instantiated object name defaults to command1, which is the name attribute. Canel: Set whether the button is the default cancel button in the current form, triggered when ESC Default: Set whether the button is the default button of the current form, and trigger when ENTER Timer The class name is timer, and the instantiated object name defaults to timer, which is the name attribute. Enable: Set the text box is not available Interval: Set the timing interval in milliseconds Graphic button The class name is pictureBox, and the instantiated object name defaults to picture1, which is the name attribute. Picture: Set this property to load the picture in the format Picture1.picture=loadpicture("URL") single button The class name is called optionbutton, and the instantiated object name defaults to option1, which is the name attribute. Caption: Display the text content of the radio button Value: Determine if the radio button is selected, the values ​​are true and false If option1.value=true then Label1.caption=option1.caption Elseif option2.value=true then Label1.caption=option2.caption End if Check button The class name is called checkbox, and the instantiated object name is called check1 by default, that is, the name attribute. Caption: Display the text content of the check button Value: Determines whether the check button is selected, the values ​​are 0 and 1, and 2 are unselected, respectively. Checked, can't be used If check1.value=1 then Label1.caption=check1.caption Endif If check2.value=1 then Label1.caption=check2.caption End if scroll bar The class name is called scrollBar, and the instantiated object name defaults to scroll1, which is the name attribute. Max: the maximum value of the scroll bar Min: the minimum value of the scroll bar Smallchange: The amount of change in value when the scroll bar arrow is clicked Largechange: The amount of change in value when the scroll bar is blank. Value: where the slider is located Scroll event: always triggered when the slider moves in real time Change: Click on the blank, click the arrow, and the slider will move once when the mouse is released. List box The class name is listbox, and the instantiated object name defaults to list1, which is the name attribute. List: The content of the i-1 item in the list box, where the data is stored, and the access subscript list(1) Listcount: indicates the number of list items in the list box. Listindex: Selected item table, example: Selected item content: list1.list(list1.listindex) Selected: The subscript indicates the status of the item selected and not selected. Additem: insert a line of text at the specified position in the list box, for example: insert to the end List1.additem "aaaa" , list1.listcount-1 Removeitem: delete list items, for example: delete the currently selected item List1.remveitem list1.listindex Clear: empty the list box Combo Box The class name is combobox, and the instantiated object name defaults to combo1, which is the name attribute. The combo box is a combined textbox and listbox, so there are properties common to both controls. When used, only the object name should be changed to combo1, and other attributes refer to the list. The key point is to be able to write programs and apply them flexibly. Program design has three structures, sequential structure, conditional structure, and cyclic structure. Conditional structure If condition then task, end if omitted If condition then task else task, end if omitted If condition then task Endif If condition Then task Else task Endif If condition then task Elseif condition then task Elseif condition then task Elseif condition then task Endif As long as one condition is met, it will not be judged later. Select case variable Case value task Case value list task Case value range task Case conditional expression task End select As long as one condition is met, it will not be judged later. Loop structure For type loop For variable = initial value to final value step step task Next variable Variables should be added once when exiting the loop. Example for i=1 to 100 step 1 S=s+i Next i While loop Variable = initial value While condition task Variable = variable + step size Wend Example: while i "=100 S=s+i i=i+1 Wend Do type loop Do while condition task Loop Example: Do while i "=100 S=s+i I=i+1 Loop Do until condition task Loop Example: Do until i "100 S=s+i I=i+1 Loop Do task Loop while condition Example: Do S=s+i I=i+1 Loop while i "=100 Do task Loop until condition Example: Do S=s+i I=i+1 Loop until i"100 Goto statement Statement label: task If condition then Goto statement label Endif Example: a: s=s+i I=i+1 If i"=100 then Goto a End if Exit statement force exit loop Array declaration Dim array name (subscript to superscript) as data type Dim a(1 to 10) as integer length 10 Dim b(5) as integer length is 6, subscript omitted If you want the default subscript to start at 1, add option base 1 Array operations: assignment, reference, input, output, copy Ensure that the array subscript does not overflow when operating on the data. Enter 10 numbers, find the largest and smallest average, bubble sort Private Sub Command1_Click() Dim (1 To 10) As Integer Dim i As Integer Dim j As Integer Dim max As Integer Dim min As Integer Dim avg As Integer Dim sum As Integer For i = 1 To 10 a(i) = Val(InputBox("", "", "1")) Print a(i); Next i Max = a(1) Min = a(2) For i = 1 To 10 If max " a(i) Then Max = a(i) End If If min 》 a(i) Then Min = a(i) End If Sum = sum + a(i) Next i Avg = sum / 10 Print “max=â€; max; “min=â€; min; “avg=â€; avg; For i = 1 To 9 For j = 1 To 10 - i If a(j) 》 a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If Next j Next i For i = 1 To 10 Print a(i); Next i End Sub Audible and visual alarm is set up to meet customers' special requirements for alarm loudness and installation location. At the same time, two alarm signals, sound and light, are issued. Special fields: iron and steel metallurgy, telecommunication towers, hoisting machinery, construction machinery, ports, transportation, wind power generation, ocean-going ships and other industries; it is an accessory product in the industrial alarm system. emergency alarm,Audible Visual Signals,Visual Alarm devices,sound and light siren,visual alarm system Taixing Minsheng Electronic Co.,Ltd. , https://www.ms-speakers.com