嗔秤戻幣�哉膵�云利匈嬉蝕湊蛸賜�塋床四衲���萩晦編報炎嘔囚^泡仟 ̄云利匈�《超噌�殻窟�嵌虜隆輓麈觚翹瀘卉韮�仍仍�。� 烏御危列
昂昂慕汐 卦指云慕朕村 厘議慕尺 厘議慕禰 TXT畠云和墮 序秘慕杏 紗秘慕禰

VB2008貫秘壇欺娼宥(PDF鯉塀哂猟井)-及78嫗

梓囚徒貧圭�鮗� ○ 賜 ★ 辛酔堀貧和鍬匈��梓囚徒貧議 Enter 囚辛指欺云慕朕村匈��梓囚徒貧圭�鮗� ● 辛指欺云匈競何��
!!!!隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��




know about when writing your own code。 



More Preprocessor Directive Details 



Earlier in the chapter�察�you saw how you can use the hash character ��#�� and conditional state

ments to conditionally include code during pilation。 The technical term for this jargon is  

called preprocessing the code�察�and the statements are called  preprocessor directives。 Table 6´1  

shows the preprocessor directives you can use。 



Table 6´1。 Available Preprocessor Directives 



Hash Code                   Description 



#Const                      Used to define the pilation identifier�察�such as the INTEGRATE_TESTS  

                            identifier used in this chapter¨s example。 You would define this at the top  

                            of a source code file to activate conditional preprocessor statements  

                            used throughout the source code file。 Using a #Const directive does not  

                            span multiple source code files。 



#If and #End If             Used to conditionally include or not include a piece of source code。 You  

                           would use a conditional directive whenever you wanted to define source  

                            code configurations�察�such as for debug or production builds。 


´´´´´´´´´´´´´´´´´´´´´´Page 180´´´´´´´´´´´´´´´´´´´´´´´

158       CH AP T E R   6   *    L E A R N IN G   T HE   B AS IC S  O F   OB J E CT OR I E N T E D   P R O G R AM M IN G 



           Table 6´1。 Available Preprocessor Directives ��Continued�� 



           Hash Code                   Description 



           #ElseIf                     Instead of a single #If block�察�you could have multiple tests for code  

                                       inclusion。 You would use #ElseIf when you have more than a single  

                                       preprocessor directive�察�such as for debug�察�production�察�and performance  

                                       builds。 



           #Else                       A default code block that is included if the other #If statements did  

                                       not trigger。 



           #Region and                 These have absolutely nothing to do with the pilation of the source  

           #EndRegion                  code。 They are used by Visual Studio to create regions of source code that  

                                       can be ^folded。 ̄ Folding means to collapse a block code out of sight  

                                       temporarily。 Source code files can be bee long�察�and constantly paging  

                                       up and down bees tedious。 By folding the code�察�you are reducing the  

                                       amount of times that you need to page up and down�察�even though the  

                                       code still exists。 



                The following example demonstrates how to use the preprocessor directives。 



           #Const ACTIVATE_1 = True 



           Namespace TestDefine 

               Class Example 

           #If ACTIVATE_1 Then 

                   Private _dataMember As Integer 

           #ElseIf Not NO_ACTIVATE_10 Then 

                   Private _dataMember3 As Integer 

           #Else 

                   Private _defaultValue As Integer 

           #End If 

               End Class 

           End Namespace 



                In general�察�you will use preprocessor directives when you are building debug mode or  

           release mode code。 Debug mode means that the code is piled such that it can be debugged  

           and analyzed using pretty symbols。 Release mode means when the code is piled�察�the code  

           can still be debugged�察�but the pretty symbols are missing。  



           *Note  Visual Basic Express does not give you the flexibility to choose debug mode or release mode for  

           development。 To get this feature�察�you need the full version of Visual Studio。 



                Think of the pretty symbols as milestones on the road。 Every time your code executes in  

           debug mode�察�the code is saying�察 �You are now calling this method in this source code file�察院�or  

           ^Oops�察�that property code in the source code file is not working properly。 ̄ In release mode�察�the  

           pretty symbols are more like road signs saying�察 �Place X y Miles/Kilometers。 ̄ The signs help  


´´´´´´´´´´´´´´´´´´´´´´Page 181´´´´´´´´´´´´´´´´´´´´´´´

                       CH A PT E R   6   *    L E A R N I N G   T HE   B AS IC S  O F   O B J E CT OR I E N TE D   P R O G R AM M IN G 159 



guide you�察�but the information you get from them is very limited�察�that is�察�you don¨t know which  

towns you¨re passing。 



More Property Scope Details 



In this chapter¨s examples�察�the Get and Set parts of the properties always had the same scope。  

However�察�properties can have mixed scope�察�that is�察�the Get and Set parts can have different  

scopes。 Scope splitting works only if you specify both the Get and Set parts of the property。 The  

idea behind splitting the scope is to enable the implementation of the logic where classes in the  

inheritance chain are allowed to assign a property�察�and classes external to the inheritance  

chain are allowed only to read the property。 The following is an example where a property is  

declared as Public and the assignment of the property is  Protected。 



Class PropertyScopeExample 

    Private _value As Integer 



    Public Property Value�┌� As Integer 

        Protected Set��ByVal value As Integer��  

            _value = value 

        End Set 

        Get 

            Return _value 

        End Get 

    End Property 

End Class 



The MustOverride Keyword 



In this chapter¨s example�察�the keyword MustInherit was used to declare a class that could be  

referenced�察�but not instantiated。 It is also possible to define methods that need to be imple

mented。 In Visual Basic�察�to require a derived cl
卦指朕村 貧匯匈 和匯匈 指欺競何 壘��1�� 家��1��
隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��
梁椣戻幣�� 梁心弌傍議揖扮窟燕得胎��傍竃徭失議心隈才凪万弌誌育断蛍�輌臆惨軼僑〃�燕慕得珊辛參資誼持蛍才将刮襲潜��範寔亟圻幹慕得 瓜寡追葎娼得辛參資誼寄楚署衛、持蛍才将刮襲潜填��