VB.NET函数与语句详解

需积分: 13 0 下载量 107 浏览量 更新于2024-07-17 收藏 223KB PDF 举报
"Sybex - Mastering Visual Basic .NET VB.NET Functions (VBL) 提供了一本关于VB.NET函数和语句的附加参考指南,它按照类别组织了VB.NET支持的功能,便于开发者查找和理解相关操作。此参考强调了VB6到VB.NET的一些关键差异,如许多VB6的语句在VB.NET中被实现为函数,而一些VB6函数在.NET框架类中有对应的等效方法。例如,VB6中的Len()函数用于获取字符串长度,在VB.NET中可以通过字符串变量的Length属性来获取。同时,VB.NET的内置函数多接受可选参数,如果省略参数,仍需用逗号表示其缺失。参考中还列举了所有VB.NET支持的函数,并按类别进行了分类。此外,书中详细讨论了各种类的方法,帮助读者深入理解和使用VB.NET的功能。" VB.NET与VB6的关键差异主要体现在以下几个方面: 1. **函数与语句的转换**:在VB.NET中,很多VB6的语句被转换为函数,比如打开文件的操作。此外,许多VB6的函数现在有了.NET框架类中的等效方法。 2. **内置函数的变化**:VB6中的Len()函数在VB.NET中仍然可用,但可以使用字符串变量的Length属性来替代。例如: ```vbnet Dim strVar As String = "a short string" Console.WriteLine("The string contains " & strVar.Length & " characters") ``` 或者仍然可以使用Len()函数: ```vbnet Dim strVar As String = "a short string" Console.WriteLine("The string contains " & Len(strVar) & " characters") ``` 3. **可选参数的处理**:VB.NET的内置函数通常有重载形式,如果省略可选参数,仍需保留逗号表示参数缺失。例如Mid()函数提取字符串中的字符,语法为`newString = Mid(string[, start][, length])`,其中start和length为可选参数。 4. **函数分类与详细描述**:提供的参考资源按类别列举了VB.NET的所有函数,方便开发者根据需求查找和结合使用。同时,书中详细讨论了各种类的方法,提供实例说明。 5. **语句与函数的区分**:表1中的项目,没有括号的是语句,这些语句也在参考中进行了描述。 通过这本书,VB.NET的开发者不仅能了解到VB6到VB.NET的迁移差异,还能深入掌握VB.NET的函数和语句使用,以及如何有效地利用.NET框架的类库进行编程。这对于提升开发效率和代码质量具有重要意义。
2019-08-15 上传
Introduction At first, .NET was no more than a distant echo in my consciousness. For a long time—it seems like years, and actually, it was years—I heard the distant beating of publicity drums regarding .NET, and I couldn't care less. My concern has always been to work with high- quality programming tools that are solid, rather than playing with the latest technology toy, and I am ever suspicious of publicity campaigns. Visual Basic 6 worked well enough for me, my consulting clients, and the readers of my books. Why should I bother taking the time to understand this .NET thing until it was tried-and-true technology? What's the .NET Strategy? Before we get to my "Aha!" moment—and I've had several epiphanies related to .NET and Visual Basic .NET—I would like to step back for a second and consider exactly what .NET is and what it is not. This is particularly confusing because some things that Microsoft calls .NET are a matter of "vision," some are marketing terms, and others—such as Visual Basic .NET—are grounded technologies that are here today. (I mean, what could be more grounded as a technology than a programming language?) Pushing aside the clouds of confusion that swirl around the terminology, Microsoft's .NET strategy involves three related offerings: • .NET Framework and Visual Studio .NET, a runtime platform and development environment that works with languages including Visual Basic .NET • .NET Enterprise Servers, a set of enterprise server products such as Biztalk Server, Exchange Server, Mobile Information Server, and SQL Server, which happen to have been given the .NET moniker for marketing purposes • .NET MyServices, also sometimes called Hailstorm, which is a vision for creating services, such as the Passport user authentication service, that can be drawn upon as utilities by myriad distributed applications The domain of this book is the first of these: applications written in the Visual Basic .NET language, using the Visual Studio development environment, targeting the .NET Framework as a runtime platform. You can think of the runtime platform that .NET applications are written for as being analogous to the Java runtime "sandbox" that Java applications target, except that, at this point, the .NET Framework is primarily deployed on Microsoft Windows platforms.
2019-08-15 上传
Introduction Welcome to .NET and Visual Basic .NET.As you already know, .NET is a name for a new strategy: a blueprint for building applications for the next decade. It’s actually even more than that. It’s Microsoft’s commitment to remain at the top of a rapidly changing world and give us the tools to address the needs of tomorrow’s computing. Visual Basic .NET is a language for creating .NET applications, like many others. It also happens that Visual Basic is the easiest to learn, most productive language (but you already know that). Visual Basic .NET is released shortly after the tenth anniversary of the first version of VB. The original language that changed the landscape of computing has lasted for 10 years and has enabled more programmers to write Windowsapplication than any other language. Programmers who invested in Visual Basic 10 years ago are in demand today. In the world of computing, how- ever, things change very fast, including languages. At some point, they either die, or they evolve into something new. Visual Basic was a language designed primarily for developing Windows applications. It was a simple language, because it managed to hide many of the low-level details of the operating system. Those who wanted to do more with Visual Basic had to resort to Win- dows API. In a way, earlier versions of Visual Basic were ‘sandboxed’ to protect developers from scary details. Microsoft had to redesign Visual Basic. The old language just didn’t belong in the .NET pic- ture (at least, it wouldn’t integrate very well into the picture). Visual Basic .NET is not VB7; it’s a drastic departure from VB6, but a necessary departure. Visual Basic .NET was designed to take us through the next decade of computing, and if you want to stay ahead, you will have to invest the time and effort to learn it. The most fundamental component of the .NET initiative is the .NET Framework, or simply the Framework. You can think of the Framework as an enormous collection of functions for just about any programming task. All drawing methods, for example, are part of the System.Drawing class. To draw a rectangle, you call the DrawRectangle method, passing the appropriate argu- ments. To create a new folder, you call the CreateDirectory method of the Directory class; to retrieve the files in a folder, you call the GetFiles method of the same object. The Framework contains all the functionality of the operating system and makes it available to your application through numerous methods. VB was such a success because it was a very simple language. You didn’t have to learn a lot before you could start using the language. Being able to access the Framework’s objects means that you’re no longer limited by the language. The new version of the language unlocks the full potential of .NET; now there’s hardly anything you can do with another language but can’t do 2877c00.qxd 11/11/01 4:13 PM Page xxiii INTRODUCTION xxiv with Visual Basic. This makes the language as powerful as any other language, but it also makes the learning curve steeper. The good news is that, if you get started today, you’ll get a head start, which may well last for another decade. Who Should Read This Book? You don’t need to know Visual Basic to read Mastering Visual Basic .NET,but you do need a basic understanding of programming. You need to know the meaning of variables and functions and how an If…Thenstructure works. This book is addressed to the typical programmer who wants to get the most out of Visual Basic. It covers the topics I feel are of use to most VB programmers, and it does so in depth. Visual Basic .NET is an extremely rich programming environment, and I’ve had to choose between superficial coverage of many topics and in-depth coverage of fewer topics. To make room for more topics, I have avoided including a lot of reference material and lengthy listings. For example, you won’t find complete project listings or Form descriptions. I assume you can draw a few controls on a Form and set their properties, and you don’t need long descriptions of the properties of the control. I’m also assuming that you don’t want to read the trivial segments of each application. Instead, the listings concentrate on the “meaty” part of the code: the procedures that explain the topic at hand. If you want to see the complete listing, it’s all on the CD. The topics covered in this book were chosen to provide a solid understanding of the principles and techniques for developing applications with Visual Basic. Programming isn’t about new key- words and functions. I chose the topics I felt every programmer should learn in order to master the language. I was also motivated by my desire to present useful, practical examples. You will not find all topics equally interesting or important. My hope is that everyone will find something interesting and something of value to their daily work—whether it’s an application that maps the folders and files of a drive to a TreeView control, an application that prints tabular data, or an application that saves a collection of objects to a file. Many books offer their readers long, numbered sequences of steps to accomplish something. Fol- lowing instructions simplifies certain tasks, but programming isn’t about following instructions. It’s about being creative; it’s about understanding principles and being able to apply the same techniques in several practical situations. And the way to creatively exploit the power of a language such as Visual Basic .NET is to understand its principles and its programming model. In many cases, I provide a detailed, step-by-step procedure that will help you accomplish a task, such as designing a menu. But not all tasks are as simple as designing menus. I explain why things must be done in a certain way, and I present alternatives and try to connect new topics to those explained earlier in the book. In several chapters, I expand on applications developed in earlier chap- ters. Associating new knowledge to something you have already mastered provides positive feedback and a deeper understanding of the language. This book isn’t about the hottest features of the language; it’s about solid programming tech- niques and practical examples. For example, I’m not going to show you how to write multithreaded applications. The real challenge with multithreaded applications is their debugging, which requires substantial experience. Once you master the basics of programming Windowsapplications with Visual Basic .NET and you feel comfortable with the more advanced examples of the book, you will find it easy to catch up with the topics that aren’t discussed.