收藏 分享(赏)

一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc

上传人:dreamzhangning 文档编号:2790648 上传时间:2018-09-27 格式:DOC 页数:10 大小:20.14KB
下载 相关 举报
一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc_第1页
第1页 / 共10页
一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc_第2页
第2页 / 共10页
一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc_第3页
第3页 / 共10页
一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc_第4页
第4页 / 共10页
一、编写简单的vb程序然后实现该程序(First, write a simple VB program and then implement the program).doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、一、编写简单的 vb程序然后实现该程序(First, write a simple VB program and then implement the program)Own collectionThink its usefulSo upload it to BaiduShare it with you!First, write a simple VB program and then implement the programCase 1-2. designed a simple calculator to complete the addition and subtraction func

2、tions, using the text box to do the data input and output. The interface after the program is shown as shown in the diagramPractice goal:(1) master the general process of writing a VB application(2) master the method of entering code form from object form(3) master the simple code writing method (th

3、e difficulty and emphasis of this topic)(4) understand the essential difference between tags and text boxes (labels can only be outputText boxes can be input and output(5) understand the shape of a label that can be set as a text boxThe text box can also be set to the shape of the tagThe attributes

4、used in this case: the Alignment attribute and the Caption property of Text; the method used: the Click method of Command(6) review the method of adding and resizing controls(7) understand the function of Val function and Str functionRequirement:1. click the Add buttonThe data in the text box 1 is a

5、dded to the data in box 2Results release text box 32. click the “subtract“ buttonThe data in the text box 1 is subtracted from the data in box 2Results release text box 33. click the screen“Clears the contents of the three text boxes4. click exit“End programThe operating procedure is as follows:The

6、first step: create a project (the same as case 1-1)The second step: build user interface(1) establish a new project (program): the same as case 1-1(2) the form editor appears to resize the form to the requested size(3) draw the control on the form according to the requirements of the topic:Draw thre

7、e “text boxes“Text1“, “Text2“ and “Text3“ are automatically marked in the box“;Draw three labels, tag automatically marked “Label1“, “Label3“, “Label3“Draw four “command buttons“Button “Command1“, “Command2“, “Command3“ and “Command4“ are automatically marked“(4) after finishing all the controlsAdju

8、st its position and size properlyThinking: in generalSimilar buttons should be the same sizeHow should it be realized?The third step: set the property of the control(1) there are only a few of the most commonly used attributes in VB programmingSuch as “name“, “Caption“, “Font“, “Text“, “ForeColor“ o

9、f the controlOther properties need not be setUse default values(2) to make the design interface clear and organizedUsually, the design information of form and control is made into a table before designAnd then design it by this tableThe interface design information table is:Object name (Name) header

10、 (Caption) text (Text)Windows Form1 VB programming exampleTab 1 Label1 data 1Tab 2 Label2 data 2Tab 3 Label3 calculation resultsText box 1 TxtData1 emptyText box 2 TxtData2 emptyText box 3 TxtRel emptyButton 1 cmdAdd add noButton 2 cmdSub subtraction noNo 3 cmdCls screen buttonNo 4 cmdEnd screen but

11、tonBe careful:(1) the name is the Name attributeAnd Caption are different attributesName is the internal name of the objectCaption is the external title of an object“(2) the name attribute is a read-only attributeThe name of the bid in the property window is the name“Name is used in the program(3) t

12、he Font property and ForeColor attribute of the control can be set according to the requirementsThe fourth step: write event driver code (not in case 1-1)1. into the program code window (there are 4 ways)* double-click the object to write the driver;* / execution view code window;* press the F7 key;

13、Click view code from project explorer“Introduction of program code window2. write the “add“ button driver(1) according to the requirements of the subjectClick the Add buttonThe addition operation is performedTherefore, in the code edit object box, select “cmdAdd“ (because the “add“ button Name attri

14、bute is cmdAdd), and because it is “click“So in the process / event box, select “Click“The system will automatically give the start and end rows of the driver(2) write the code between the start line and the end line:Text3.Text = Val (Text1.Text) + Val (Text2.Text)Object attribute values are represe

15、nted as object names. Attribute names such as: Text1.textModify attribute values of objects in codeBe careful:(1) the Val () in the above statement is a standard functionThe function is to convert character data into numeric data, and there is also a Str () function corresponding to itFunction is op

16、posite to Val () function. Please refer to MSDN for detailed function and usage(2) Text1.text is the content of the text box: the subtraction button driver programming method is the same as above3, the “screen“ button driver (clear out the contents of the text box)Private Sub cmdCls_Click ()Text1.Te

17、xt =“Text2.Text =“Text3.Text =“End SubNote: the sentence in the program should be indented to the right; the clear text box is nothing written in the text box;4, “end“ button driverPrivate Sub cmdExit_Click ()End End is the end statementFunction is the end of a program running;End SubThe fifth step:

18、 save the programThe project file is saved as: lx1-2.vbp, and the form file is saved as lx1-2.frmThe sixth step: operation engineeringClick the start button on the toolbarOr “run / start“ under the selection menu“The program starts runningThe initial interface is as follows:Enter the operation data

19、in the first text box and second text boxes, respectivelyClick “add“ or “subtract“ buttonThe calculation results appear in the third text boxes; click the “clear“ buttonThe data in the three text boxes is clearedReflection:1, after the above program runningWhen you input data, the data is on the lef

20、t side of the textboxHow can I make the data in the middle or right side of the text box?2, if you write the addition of the statement code Text3.Text = Val (Text1.Text) + Val (Text2.Text)Changed to: Text3.Text = Text1.Text + Text2.TextIs the running result correct? Why?3. Can you replace the text box of the calculation result with tags? What attribute can be used to change the shape of a tag to the shape of a text box?

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报