土地资源调查与评价

上传人:feng****ing 文档编号:60731407 上传时间:2022-03-09 格式:DOC 页数:24 大小:488.50KB
返回 下载 相关 举报
土地资源调查与评价_第1页
第1页 / 共24页
土地资源调查与评价_第2页
第2页 / 共24页
土地资源调查与评价_第3页
第3页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Beginning Visual Basic1. Introducing Visual BasicA Story About Bill and PaulBack in the early 1970 s, Bill and Paul were friends at LakesideSchool in Seattle, Washington. Bill and Paul enjoyed working with computers and wrote many games they could play - games like Tic-Tac-Toe and moon landing games. These computer games were writte n in a computer Ianguage calledBASIC(which stands forBeginner s All-Purpose SymbolicI nstructionCode). When the first small computer was developed in themid 19 70 s, Bill and Paul had just started college. They had improved their computer skills by then and were able to tell that new computer how to use the BASIC Ian guage. They actually sold their vers ion of the BASIC Ian guage to other people (it cost $350 and was stored on a cassettetape). They started making money selling BASIC and decided to start a compa ny. You may have heard of their compa ny - Microsoft! Bill is Bill Gates, who still runs Microsoft and is worth many billions of dollars, and Paul is Paul Alle n, who no Ion ger works for Microsoft, but has his own bus in ess ven tures in cludi ng computers and software, professi onal sports teams, and real estate developme nt.Yes, the first product sold by Microsoft was the BASIC computerIanguage. Microsoft s name for their BASIC Ianguage product has changed over the years, hav ing n ames like GW-BASIC, QuickBasic and QBasic, with the newest version being called Visual Basic . Visual Basic is one of the easiest program ming Ian guages to lear n. Yet, eve n though it is easy to lear n and to use, Visual Basic can also be used to develop very powerful computer programs. Many computer games are writte n in Visual Basic, bus in esses use Visual Basic to man age their databases, webmasters use Visual Basic in develop ing web pages, and people like yourself use Visual Basic to build Win dows applicati ons they want and n eed in their everyday life. In these notes, you will learn how to use Microsoft sVisual Basic to write your own computer programs. You may not become a billiona ire like Bill and Paul, but hopefully you ll have some funlearning a very valuable skill.Lets Get StartedLearning how to use Visual Basic to write a computer program (like learning anything new) involves many steps, many new terms, and many new skills. We will take it slow, describing each step, term, and skill in detail. Before starting, we assume you know how to do a few things:? You should know how to start your computer and use the mouse.? You should have a little knowledge on working with your operating system (Windows 95, 98, or NT).? You should know how to resize and move windows around on the screen.? You should know how to run an application on your computer by using the Start Menu.? You should know how to fill in information in Windowsthat may pop up on the screen.? You should know about folders and files and how to find them on your computer.? You should know what file extensions are and how to identify them. For example, in a file namedExample.ext ,the three letters ext are called the extension.You have probably used all of these skills if youve ever used a wordprocessor, spreadsheet, or any other software on your computer. If you think you lack any of these skills, ask someone for help or consult one of the many books introducing the Windows operating system.Lets get going. And, as we said, were going to take it slow.In this first class, we will learn how to get Visual Basic started on a computer, how to load a program (or project) into Visual Basic, how to run the program, how to stop the program, and how to exit from Visual Basic. It will be a good introduction to the many new things we will learn in the classes to come.Starti ng Visual BasicWe assume you have some versi on of Visual Basic in stalled and operational on your computer. If you don t, you need to do this first. Aga in, this might be a good place to ask for some one s help if you n eedit. Over the past several years, there have bee n many versi ons of VisualBasic. You will be able to do this class using Visual Basic 4.0 (32 bitversion), Visual Basic 5.0, or the new Visual Basic 6.0. Throughout theno tes, we will refer to Visual Basic by its abbreviati onVB and you willbe told what to do depe nding on what versi on of Visual Basic you areusing. If you are using Visual Basic 4.0, look for the abbreviati onVB4for in formatio n particular to your versi on. If you are using VisualBasic 5.0, look for the abbreviati onVB5for in formatio n particular toyour vers ion. An d, if you are using Visual Basic 6.0, look for the abbreviati onVB6for in formatio n particular to your versi on.To start Visual Basic:? Click on the Start butt on on the Win dows task bar.? Select Programs, then Microsoft Visual Basic # (where #is your versi on of Visual Basic).? Click on Visual Basic # (where aga in # is your versi on).(Some of the headings given here may differ slightly on your computer, but you should have no trouble finding the correct on es.) The Visual Basic program should start. Several win dows will appear on the scree n, with the layout depe nding on your vers ion of VB.专业资料 .VB4Title BarMain Menu高 Proj ectl - Microsoh Visual Basic designFie EditInsert Run Tcoh Addln$ He|pToolbarr_-|n|x|I之旧I気I刮窗|答曲I詁|讣I厂陰心I 土1 &20i 1125*ArSV-ip寻【気4JIi&u农、1囲甲叫ijaPope“i併-FmmAppearance1 VDAutoFl edrawFalseBackColoitMGOOOODOFt -BarderStyle2 - SizableCaptionFormlCfciGontrohTrueConliolBoxTrueDrai/jMode13 - Copy PenDravlStylea-SolidH raiAAft/idkh1 | Forml FormProiecHViefFarmView CedeVB5:Title BargjFoimlForm!Main Menu专业资料.VB6:Title BarMain MenuToolbar/槁 Projectl - Microsoft Visual Basic designFile Edit View rajec t Formst DeLug gun Query &ia4rrim Tools Add-fn Window HelpII 越皆帖普澱法Q OfProperties-Foim12J3Alphabetic | categorized | CNamg) Appearance 1 - 3FForml FomnGeneralForniLAutoRedrau False BcKColor 3order5tle Caption ClipContrate 匚 q ritrclBux DrawMode DrawStyle DraiWVidth inahlEd Fillcolor Fillstyle Font &H0OOOOC z 旨Eobte Forrnl TrueTrue13-CopyFeio - solidTrue &Hoaooac L - T龊叩 MS Sars Serif2J2JLJ=1=ontT rarspare=ore ColorHasDCTrue&H8X00CTrueWhen starting VB5 or VB6, a dialog box asking aboutNew Project type mayappear. If it does, just click theOpe nbutt on.Let s point out just a few itemson the screen. At the top of thescreen is the Visual Basic Main Window At the top of the main window is the Title Bar. The title bar gives us information about what program we re using and what Visual Basic program we are working with. Below the title bar is theMain Menufrom where we can control the Visual Basicprogram. You should be familiar with how menus work from using other programs like word processors and games. Un der the main menu is theToolbar . Here little buttons with pictures also allow us to controlVisual Basic, much like the main menu. If you put the mouse cursor over one of these buttons for a second or so, a little tooltip will pop up and tell you what that particular button does - try it! Almost allWindows applications (spreadsheets, word processors, games) have toolbars that help us do different tasks. This is the purpose of the Visual Basic toolbar. It will help us do most of our tasks. Well worry about theother things on the screen later.Opening a Visual Basic ProjectWhat we want to do right now isope n a project . Programs writte nusing Visual Basic are referred to asprojects . Projects include all thein formati on we n eed for our computer program. Whe n we are done writ ing our computer program using Visual Basic, we save it as a project.In cluded with these no tes are many Visual Basic projects you can ope n and use. Let s open one now.We will use the Visual Basic toolbar to open a project. Look for a butt on on the toolbar that looks like a folder ope ning up. This is the Open Project butt on:Click on this butt on. AnOpe n Project win dow will appear.Find the folder n amedBeg inVB (sta nds forBegi nning VisualBasic). This is the folder that holds the no tes and projects for this course. Open that folder.Find the folder n amedBVBProjects. This folder holds allthe projects for the course. In this folder are three other folders:VB4Projects (contains projects for VisualBasic 4.0, 32 bit version),VB5Projects (contains projectsfor Visual Basic 5.0), and VB6Projects (contains projects for Visual Basic 6.0). Select the folder for your vers ion of Visual Basic.Remember how you got to this folder. Throughout the course, you will go to this folder to ope n projects you will n eed.Now, i n your project file, find a project file n amedSample. Ope nSample. Many windows are now on the screen. Look for a window thatlooks somethi ng like this - this isSample:If this window doesn t show up when you open the project:VB4Click View on the main menu, the nForm.VB5, VB6: Click View on the main menu, thenObject .As an alter nate, if the wi ndow does not show up, press theF7 fun cti onkey while holdi ng dow n . This is a keyboard comma nd to show this particular wind ow. We re going to spend a bit of time explaining everything that is displayed here. This will introduce you to some of the vocabulary we use in Visual Basic. There are lots of terms used inVisual Basic. Don t try to memorize everything - you ll see t hese new words many times through the course.We call the displayed project wi ndow aForm. All Visual Basicprojects or programs are built using forms. In fact, you have probably no ticed that all Win dows applicatio ns are built using forms of some type. At the top of the form is theTitle Bar. It has an icon (littlepicture) related to the form, a descripti on of what the form does(Beg inning Visual Basic - Sample ), and three smaller butt tons thatcontrol form appearanee (we won t worry about these butto ns right now). There are lots of other things on the form. These other things are the heart of a Visual Basic computer program.You see a set of square butt ons with object n ames n ext to them.You see pictures of objects. You see a set of round butt ons with colorn ames n ext to them. There is a little box you can type in with someth ingcalled a scroll bar on the right side. There s a big butt on that saysBeep! There s a little device for picking the value of a number. And, there s a ball in a bi g recta ngle with a butt on that says Start and a little thing that looks like a stopwatch. We call all of these other things on the formCon trols or Objects . Con trols provide anin terfaceor line of com muni cati on, betwee n you (or the user of your program) and the computer. You use the con trols to tell the computer certa in thin gs.The computer then uses what it is told to determine some results and displays those results back to you through controls. By the way, the form itself is a control. If youve used any Windows applications,youve seen controls before- you probably just didnt know they werecalled controls. As examples, buttons on toolbars are controls, scroll bars to move through word processor documents are controls, menu items are controls, and the buttons you click on when opening and saving files are controls.I think you get the idea that controls are a very important part of Visual Basic, and you re right. They are the most important part of Visual Basic - they are what allow you to build your applications. We will spend much of this course just learning about controls. Right now, though, let s run this program and get some insight into how a Visual Basic project (and its controls) works. Before we leave though, look at the title bar in the Visual Basic main window - notice the bracketed word design . This tells us that Visual Basic is inDesign mode. That isthe mode used to build a Visual Basic project. Always look at this title bar to see what mode Visual Basic is working in.Running a Visual Basic ProjectAfter develop ing a Visual Basic project, you want to start or runthe program. This gets the program going and lets the user in teract withthe controls on the form and have the computer do its assigned tasks. Wecan run a project using the toolbar. Look for a butt on that looks likeSample (the project we ope nedthe Play butt on on a VCR, CD player, or cassette tape player:Click this butt on to run previously).The project form will appear and look something like this:I). Beginning Visual Basic - Sample-Stuff厂CarI r ruck厂 HouseB Cardr Eyeball 厂 FootballNotice a few things have changed. All the objects have disappeared. The background color of the form is blue. The circle button next toBlue hasa black dot in it. The little stopwatch control has disappeared. The little ball has dropped to the bottom of the big rectangle. What happened? Well find out how and why all this happened as we learn more about Visual Basic. Also, notice (in the main window) that Visual Basic is now in Run mode.The project is now running, but what is it doing? Nothing is happening, or is it? At this point, Visual Basic is waiting for you, the user, to do something. We say your Visual Basic project is waiting for an event to occur. Nothing can happen in a Visual Basic program until an event occurs. We call Visual Basic anevent-driven programminglanguage. So, let s cause an event.An event occurs when you do something on the form - click on something with the mouse, type something in places where words can go, or maybe drag an object across the form. In the upper left corner of the form is a group of six boxes within a rectangular region with the heading Stuff . Each little box has an object name printed next to it. Click on one of these boxes. Notice what happens. A check appears in the selected box, indicating box selection, and the object named by that box appears on the screen. When we click on a box, we cause an event, called a Click event. The computer recognizes the event and does what you have told it to do (through your computer program) if that particular event occurs. In this case, the event tells the computer to display the selected object. Click on the box again. The check mark and the objectdisappear. You have caused ano ther eve nt and told the computer to make the object disappear. This particular control is called acheck box.Notice you can check as many boxes as you want, pick ing which objects (if any) you want displayed on your scree n. Check boxes are used whe n you want to select items from a list. Two other con trols are used in this example. The recta ngular regi on the check boxes are contained is called a frame . The region each object picture is displayed in is called an image control. Now, let s look at causing events with the other controls on the form.Near the middle of the scree n is a group of four round butt ons in aframe with the headi ng Color. Each butt on has a color n ame prin ted n ext to it. The Blue butt on has a black dot in it, i ndicati ng it is the curre ntly selected color (no tice the form is blue). Click on ano ther of these butt ons. Notice what happe ns. The form color cha nges to the selected color. This Click eve nt tells the computer to cha nge the form backgro und color. Notice that whe n you select a new color, the black dot appears in the selected butt on and disappears in the previously selected butt on. Un like the check boxes we saw earlier, you can only select one of these butt ons. This makes sense - the form can only be one color!These round buttons are calledoption buttons . Option buttons are usedwhe n you n eed to choose exactly one opti on from a list of many.Under the Stuff frame is another frame with the headingPick aNumber There we see a number displayed in a control called alabel .Under the label is another control called ascroll bar. You ve probablysee n scroll bars in other applicati ons you have used. The scroll bar is used to cha nge the displayed nu mber. Click on the arrow on the rightside of the scroll bar. The displayed value will increase by 1. Continued clicking on that arrow will continue to increase the value. Click on the white area to the left of the arrow. The value will increase by 10. Click on the little bar (called a thumb) in the middle of the scroll bar and drag it right, then left. Notice that, too, changes the displayed value. In this example, the computer is responding to the scroll bar s Changeevent, which occurs each time the scroll bar thumb moves. The Change event tells the computer that the scroll bar value has changed and allows the new value to be displayed in the label control.Under the Pick a Number frame is a region with a scroll bar on the right side. This control is called a text box. You can click in it, then type in any text you want. Try it. The text box is like a little word processor in itself. Each time you type something in the text box, several events occur. There is aKeyPress event when you press a key anda Changeevent that is called each time the text in the box changes.Next to the text box is a button that saysBeep! Click the buttonand you should hear a beep on your computers speaker. This control iscalled a commandbutton and is one of the most widely used controls in Visual Basic. TheClick event told the computer to make the speakerbeep.The last thing on our form is a tall, yellow, rectangular control called a picture box that contains a little circle called ashapecontrol. Under the picture box is a command button that saysStart .Click on that button, that is, cause aClick event. The ball startsmoving up. It continues moving up until it hits the top of the picture box, then starts moving back down. It will continue to do this until you click the comma nd butt on that now says Stop. Remember the little stopwatch that was on our form in desig n mode, but disappeared whe n we ran the project. It is being used by the bouncing ball example - it is called a timer con trol. The Click eve nt on the comma nd butt on, in additi on to cha nging what the butt on says toStop, also started thistimer con trol. The timer con trol gen erates eve nts all by itself at preset time in tervals. In this example, aTimer eve nt is gen erated every1/10th of a sec ond and, in that eve nt, the ball positi on is cha nged to give the appeara nee of moveme nt. Notice that eve n while the ball is bouncing, you can cha nge the form color, make objects appear and disappear, type text, and make the computer beep. So, Visual Basic eve n has the capability of han dli ng multiple eve nts.Obviously, this project does n t do much mor e tha n dem on strate what can be done with Visual Basic, but that is a important concept. It points out what you will be doing in build ing your own Visual Basic projects. A project is made up of the con trols that let the user provide in formatio n to the computer. By caus ing eve nts with these con trols, the computer will gen erate any required results. We have n t worried abouthow to use the eve nts to determ ine these results, but we will in all the later classes. By the time you have fini shed this course, you will be able to build projects that do everythi ng (and more) that theSampleproject does. Let s look now at how to stop the project.Stopp ing a Visual Basic ProjectThere are many ways to stop a Visual Basic project. We will
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!