Beginning Visual Basic 2005 phần 10 pot

78 311 0
Beginning Visual Basic 2005 phần 10 pot

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

If btn02.Text = btn12.Text And btn12.Text = btn22.Text And _ btn22.Text <> String.Empty Then ‘Winner on third column Call Winner(btn02.Text) Return True End If If btn00.Text = btn11.Text And btn11.Text = btn22.Text And _ btn22.Text <> String.Empty Then ‘Winner on diagonal top left to bottom right Call Winner(btn00.Text) Return True End If If btn20.Text = btn11.Text And btn11.Text = btn02.Text And _ btn02.Text <> String.Empty Then ‘Winner on diagonal bottom left to top right Call Winner(btn20.Text) Return True End If ‘Test for a tie, all square full Dim ctrl As Control Dim intOpenings As Integer = 0 For Each ctrl In Me.Controls If TypeOf (ctrl) Is Button And ctrl.Name <> “btnNewGame” Then If ctrl.Text = String.Empty Then intOpenings = intOpenings + 1 End If End If Next If intOpenings = 0 Then Call Winner(“It’s a tie.”) Return True End If Return False End Function The remaining code is part of the handlers for the form’s Load event and the New Game button Click event. On form load, the overloaded method CorrectEnabledState is called and all buttons are disabled. When you click the New Game button, ResetGame is called to set up the board to start a new game. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Me.Load CorrectEnabledState(False) lblMessages.Text = “Click new game to begin.” End Sub Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnNewGame.Click ResetGame() End Sub 722 Chapter 22 25_574019 ch22.qxd 9/16/05 9:33 PM Page 722 Summary Visual Studio 2005 and the Compact Framework make developing mobile applications very similar to desktop application development. This small learning curve for .NET developers is one of the reasons more PDAs are shipping with a Windows operating system than with any other competitor. The trend has been growing, and companies are starting to value the developer with mobile application skills. Take advantage of your knowledge and leverage it to start developing mobile applications. In this chapter, you learned the basics of mobile development. You saw what is similar and what is dif- ferent between the full version of the .NET Framework and the Compact Framework. You were shown examples of the missing pieces that explain how the CF has been shrunk by over 80 percent. Finally, you built your first application, tic-tac-toe. To summarize, you should know how to: ❑ Find differences between the full .NET framework and the Compact Framework ❑ Use ActiveSync to connect to smart devices ❑ Create mobile applications ❑ Use the built in emulator to test mobile applications Exercise The computer player is a random picker. Give the computer player some brains. Add at least one function named ComputerPlayToWin to the application. When the computer moves, call ComputerPlayToWin and check for a spot on the board that will create a win for the computer. If it exists, the computer should play that move rather than a random move. You can add other procedures if needed. 723 Building Mobile Applications 25_574019 ch22.qxd 9/16/05 9:33 PM Page 723 25_574019 ch22.qxd 9/16/05 9:33 PM Page 724 A Where To Now? Now that you have come to the end of this book, you should have a relatively good idea of how to write code using Visual Basic 2005. The topics and example code covered in this book have been designed to provide you with a firm foundation, but it is just the beginning of your journey. In fact, this book is just one of the many steps you are going to take on your road to becoming a full fledged Visual Basic 2005 programmer. Although you have come a long way, there is still a lot far- ther to go, and you will certainly have many more questions on the way. The problem now is, where do you get these questions answered, and, of course, “What next?” This appendix offers you some advice on what your possible next step(s) could be. As you can imagine, a number of different routes are open to any one person. The path you choose will proba- bly depend on what your goal is or what you are being asked to do by your employer. Some of you will want to continue at a more general level with some knowledge about all aspects of Visual Basic 2005, while others may want to drill down into more specific areas. Well, it is extremely important not to take a long break before carrying on with Visual Basic 2005. If you do so, you will find that you will quickly forget what you have learned. The trick is to prac- tice. You can do this in a number of ways. ❑ Continue with the examples from this book. Try to add more features and more code to it. Try to merge and blend different samples together. ❑ You may have an idea for a new program. Go on and write it. ❑ Try to get a firm understanding of the terminology. ❑ Read as many articles as you can. Even if you do not understand them at first, bits and pieces will come together. ❑ Make sure you communicate your knowledge. If you know other programmers, get talk- ing and ask questions. ❑ Consult our online and offline resources for more information. The rest of this appendix lists available resources, both online and offline, to help you decide where to go next. 26_574019 appa.qxd 9/16/05 9:26 PM Page 725 Online Resources Basically, there are thousands of places you can go online for help with any problems you may have. The good news is that many of them are free. Whenever you come across a problem— and, unfortunately, you will — there are always loads of people out there willing to help. These unknown souls include others who were at the same stage as you and may have had a similar problem, or experts with a great deal of knowledge. The key is not to be intimidated and to use these resources as much as you like. Remember, everyone was a complete beginner at some point and has had many of the same experiences as you. In this section, we are going to begin by examining the P2P site provided by Wrox and then follow on with some of the more general sites around. If you can’t find what you want through any of the sites listed here or if you have some time and want to explore, just search for Visual Basic 2005 and you will be on your way! P2P.Wrox.com P2P provides programmer-to-programmer support on mailing lists, forums, and newsgroups in addition to a one-to-one e-mail system. You can join any of the mailing lists for author and peer support in Visual Basic 2005 (plus any others you may be interested in). You can choose to join the mailing lists, and you can receive a weekly digest of the list. If you don’t have the time or facilities to receive mailing lists, you can search the online archives using subject areas or keywords. Should you wish to use P2P for online support, go to http://p2p.wrox.com. On P2P, you can view the groups without becoming a member. These lists are moderated, so you can be confident of the informa- tion presented. Also, junk mail and spam are deleted, and your e-mail is protected by the unique Lyris system from Web-bots, which can automatically cover up newsgroup mailing list addresses. Microsoft Resources Probably one of the first sites you’ll intuitively turn to is the Microsoft site (www.microsoft.com). That makes sense, because it is full of information, including support, tips, hints, downloads, and news- groups ( news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb). To see more newsgroups, navigate to http://communities2.microsoft.com/communities/newsgroups/ en-us/default.aspx . There are also a number of sites on MSDN that you may find to be very helpful, including the following: ❑ Visual Studio 2005 site: http://lab.msdn.microsoft.com/vs2005/. ❑ Visual Studio 2005 documentation: http://lab.msdn.microsoft.com/library/. ❑ MSDN Library: http://msdn.microsoft.com/library/. ❑ Microsoft Developer Network site: http://msdn.microsoft.com. ❑ Microsoft Visual Basic site: http://msdn.microsoft.com/vbasic/. ❑ .NET download site: http://msdn.microsoft.com/netframework/downloads/. ❑ GotDotNet: www.gotdotnet.com. 726 Appendix A 26_574019 appa.qxd 9/16/05 9:26 PM Page 726 Other Resources As said earlier, there are hundreds of sites online that discuss both Visual Basic .NET and Visual Basic 2005. These sites give everything from news on moving from Visual Basic .NET to Visual Basic 2005, to listings of up and coming conferences worldwide. Although you can do a search for Visual Basic 2005, the number of sites returned can be extremely overwhelming. Let’s look quickly at two of these possible sites: one for the United Kingdom and another for the United States. In the United Kingdom, www.vbug.co.uk offers a wealth of information on Visual Basic. This is the Web site for the Visual Basic Users Group (VBUG), which you can join. Besides the Web site, this group holds meetings and an annual conference, plus provides a magazine. There is a listing of further links on the Web site, and you may want to use this to start your search over the Internet. In the United States you can get a journal, The Visual Studio Magazine, from a similar user group. Again, this journal is backed by meetings and four yearly conferences along with a Web site, http://www .devx.com/vb/ , which can give e-mail updates. On the Web site, you have access to a number of differ- ent areas both in Visual Basic and other related and nonrelated Visual Studio areas. Of course, these are just two among the many out there to try to get you started. Some of you may decide to use these two, and many of you may choose others as your favored sites, it’s all up to you! What you need to remember, though, is that the Internet is not the only place to find information, so we will go on to look at some resources not found on the Web. Offline Resources (Books) Wrox Press is committed to providing books that will help you develop your programming skills in the direction that you want. We have a selection of tutorial-style books that build on the Visual Basic 2005 knowledge gained here. These will help you to specialize in particular areas. Here are the details of a few key titles. Professional VB .NET, 2nd Edition (Wrox Press, ISBN 0-7645-7536-8) This book takes a deeper look at all aspects of Visual Basic 2005 and is probably the most logical of “next steps.” It provides the next level from this book; however, it will be worth practicing your programming skills beforehand. Topics include the following: ❑ Common Language Runtime ❑ Variables and Data Types ❑ Object Syntax Introduction ❑ Inheritance and Interfaces ❑ Applying Objects and Components 727 Where To Now? 26_574019 appa.qxd 9/16/05 9:26 PM Page 727 ❑ Namespaces ❑ Error Handling and Debugging ❑ ADO.NET ❑ XML with VB.NET ❑ Forms ❑ Security ❑ ASP.NET 2.0 Advanced Features and much more! ASP.NET 2.0 Beta Preview (Wrox Press, 0-7645-7286-5) ASP.NET 2 Beta Preview is timed to coincide with the first widespread beta release of ASP.NET, “Whidbey” — the new version of Microsoft’s popular technology for creating dynamic Web sites that pull unique information for each visitor rather than showing everyone the same static HTML pages. The book gets developers up to speed with the new features and capabilities that ASP.NET 2.0 provides. Developers will learn how to build ASP.NET 2.0 applications for themselves from the examples that the book provides. This book is for ASP.NET developers making the transition to this new version of the technology. The changes are many, and in some cases they’re quite dramatic. The book spends a good deal of time alert- ing you to all that has changed and explaining what you need to know to make the transition to ASP.NET 2.0. Finally, the book focuses on both the Visual Basic 2005 and C# developer. Examples throughout the book do not favor one developer over another. Instead, every example is provided in both languages. This book covers the following: ❑ Introduction to ASP.NET 2.0 ❑ Visual Studio 2005 ❑ Application and Page Frameworks ❑ New Ways to Handle Data ❑ Site Navigation ❑ Working with Master Pages ❑ Themes and Skins ❑ Membership and Role Management ❑ Personalization 728 Appendix A 26_574019 appa.qxd 9/16/05 9:26 PM Page 728 ❑ Portal Frameworks and Web Parts ❑ SQL Cache Invalidation ❑ Additional New Controls ❑ Changes to ASP.NET 1.0 Controls ❑ Administration and Management ❑ Visual Basic 8.0 and C# 2.0 Language Enhancements 729 Where To Now? 26_574019 appa.qxd 9/16/05 9:26 PM Page 729 26_574019 appa.qxd 9/16/05 9:26 PM Page 730 B Implementing the Microsoft Solutions Framework So here you are, ready to go out into the world and build applications with Visual Basic 2005. Congratulate yourself; your accomplishment of finishing the chapters of the book should excite you. Soon, creating applications will become second nature to you. As you work in IT, you will play many roles on teams. In some cases, your manager will only ask you to write code. By finish- ing this book, you have a strong understanding of what you will need to do in that situation. Other times, management will ask you to wear many hats on a project and be responsible for delivering an entire solution. This appendix shows you how to create a successful solution. Let’s start with a basic question. How is a solution different from an application? A solution is the entire process of creating a system for a customer. The solution includes planning, documenting, testing, releasing, training, and supporting the application. The application is just one part of the solution. Microsoft has a set of processes and models that to some is the standard for solution delivery in the IT industry. Known as MSF (Microsoft Solutions Framework), software developers around the globe apply this framework to internal strategies to ensure best practices when building software. The MSF is a recent interpretation of the classic software development life cycle. In this appendix, you will do the following: ❑ Learn about the software development life cycle. ❑ Get an overview of the MSF and how it relates to the software development life cycle. ❑ See how to manage trade-offs. ❑ Learn how to define success for a project. A detailed explanation of the Framework would take two or three hundred pages. This appendix is just a concise summary to wet your whistle, so to speak. Keep this in mind as you begin to explore this tool. 27_574019 appb.qxd 9/16/05 9:49 PM Page 731 [...]... count from 1 to 10 and display the numbers in a list box The code to execute this loop is shown here: ‘Count from 1 to 10 For intCount As Integer = 1 To 10 ListBox1.Items.Add(intCount) Next The second For Next loop should count backward from 10 to 1 and display those numbers in a list box The code to execute this loop is shown here: ‘Count backwards from 10 to 1 For intCount As Integer = 10 To 1 Step... and concatenate the variables and display the results in a message box The String variables can be declared and set as: ‘Declare variables and set their values Dim strOne As String = Visual Basic “ Dim strTwo As String = 2005 To concatenate the variables and display the results, you could write code such as: ‘Concatenate the strings and display the results MessageBox.Show(strOne & strTwo, “Exercise... important, it installs the attacker’s the malicious code in memory The victim program runs the attacker’s code as if it were its own, and the damage is done The root cause of this problem is not one most Visual Basic 2005 developers will encounter, but it should make you aware that people may use your functions in ways you did not intend them to be used Appendix C Take a look at another example of a software... had been fired What has actually happened here is that the code in the MouseUp event was fired, but the code in that event causes a message box to be displayed In the course of seeing that code, Visual Basic 2005 has determined that the Button control will lose focus and has fired the LostFocus event, which displays the message box in that event handler first Exercise 2 This exercise tasked you with... MessageBox.Show(ExceptionErr.Message, “Debugging”, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try 754 Solutions Chapter 10 Solutions Exercise 1 Once you add the Implements statement highlighted as follows and press Enter, the rest of the code shown below it is automatically inserted by Visual Studio 2005 to handle disposing of your class Namespace CarPerformance Public Class Car Implements IDisposable Private... this release, you will need more resources to make the deadline Adding another developer to meet the deadline will cost an extra $10, 000 Looking back at the project priorities, you see that Tina cannot spend more than $50,000 You have set aside the entire $50,000 budget, and $10, 000 more is too much It is time to call Tina and explain the situation 736 Implementing the Microsoft Solutions Framework While... Appendix C Summar y Security is the hottest topic in the information technology industry Making applications 100 percent secure is not possible with the openness of the Internet, but minimizing risks to vital data should be a top priority in application design As you build applications with VS 2005, know that you have the best tool available to create secure Windows applications, but it is your responsibility... disposing Then ‘ TODO: put code to dispose managed resources End If ‘ TODO: put code to free unmanaged resources here End If Me.disposed = True End Sub #Region “ IDisposable Support “ ‘ This code added by Visual Basic to correctly implement the disposable pattern Public Overloads Sub Dispose() Implements IDisposable.Dispose ‘ Do not change this code Put cleanup code in Dispose(ByVal disposing As Boolean) above... math operation on these variables and display the results in a message box The variables can be declared and set as: ‘Declare variables and set their values Dim intX As Integer = 5 Dim intY As Integer = 10 A math operation can be performed and the results displayed as: ‘Multiply the numbers and display the results MessageBox.Show(“The sum of “ & intX & “ * “ & intY & “ = “ & _ intX * intY, “Exercise 1”)... to complete your Menus application by adding a StatusStrip control and writing the necessary code to display a message when text was cut, copied, and pasted in your text boxes If you followed the same basic procedures to add a StatusStrip control as you did in the Text Editor project in Chapter 6, you will have added the control and added one panel named sspStatus All that is required at this point . sites online that discuss both Visual Basic .NET and Visual Basic 2005. These sites give everything from news on moving from Visual Basic .NET to Visual Basic 2005, to listings of up and coming. aspects of Visual Basic 2005, while others may want to drill down into more specific areas. Well, it is extremely important not to take a long break before carrying on with Visual Basic 2005. If you. may find to be very helpful, including the following: ❑ Visual Studio 2005 site: http://lab.msdn.microsoft.com/vs2005/. ❑ Visual Studio 2005 documentation: http://lab.msdn.microsoft.com/library/. ❑

Ngày đăng: 12/08/2014, 10:21

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan