|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Turning Bounds Checking On Or OffWhen you use arrays, Visual Basic checks to make sure that you dont inadvertently try to access memory past the end or before the beginning of the array when the program runs, which is an error that could corrupt memory. In the early days of programming, however, you could use array index values that were past the end of an array without causing a compiler error, and some programmers used to rely on that to create some programming tricks involving accessing memory far beyond what they were supposed to stick with (especially in C, where the name of an array is really a pointer). That practice is heavily discouraged today, but some programmers must still have a soft spot for it, because Visual Basic allows you to turn off array bounds checking. (In fairness, there are one or two other reasons you might want to turn off bounds checking, such as not having the program halt for bounds violations while youre trying to track down a bug or, conceivably, for performance reasons.) What does a bounds violation look like? Heres an example in code where we set up an array and then try to access a location past the end of it:
Private Sub Command1_Click()
Dim Addresses(1 To 10) As Integer
Addresses(1) = 1 'Fine
Addresses(11) = 11 'Problem!
End Sub
If you were to run this code, youd get the error box shown in Figure 2.23unless you turn off bounds checking.
You can turn off bounds checking by following these steps:
Thats itnow youve turned off array bounds checking.
Checking For Pentium ErrorsSome time ago, one version of the Intel Pentium suffered from a well-publicized hardware bug in the floating point instruction named FDIV. Intel responded quickly and offered to replace the defective chips, but its reasonable to expect some are still out there. For that reason, Visual Basic has a check to make sure the Pentium your program runs on is safe. That check is enabled by default, but if for some reason you want to turn it off (although it is hard to see why you would), you can turn off the Pentium FDIV check with these steps:
Thats ityouve disabled the FDIV Pentium check. Although you might want to do this yourself if you know what youre doing, its not recommended that you do this in any software you release commercially. Managing Add-InsThe deadline for your project is fast approaching, and the pressure is on. Suddenly it occurs to you that youve already written a lot of the components you need to usethe day is saved! But how can you access those components? One easy way is to use the Visual Component Manager. But when you check the Visual Basic Add-Ins menu, you dont see the Visual Component Manager there. How do you add it? You use the Visual Basic Add-In Manager to add thisand any otheradd-in. Heres how to use the Add-In Manager:
Thats itnow youve added the add-in you want. To remove it, simply deselect the add-ins box in the Add-In Manager. (Some add-ins have an annoying habit of starting when Visual Basic starts, grinding on for a long time while it loads and taking up a lot of memory, which can be annoying if you dont need the add-in any more.) Adding ActiveX Controls And Insertable Objects To ProjectsBeen away from Visual Basic for a while and need to get back into the swing of things? Youve been designing your project but suddenly realize you need a Microsoft Grid control. Thats an ActiveX controlhow do you add those again? Use the Add File To Project menu item? Double-click the toolbox and hope an Insert dialog box comes up? Add a reference to the actual Grid controls OCX file, asctrls.ocx, to the project? None of thoseheres how you do it:
You can also add insertable objects like Microsoft Word or Microsoft Excel objects to a Visual Basic project by using the Components dialog box. Instead of the Controls tab in the Components box, however, you use the Insertable Objects tab and select the object you want; that object will appear in the toolbox, and you can use it in your project from then on. For example, weve inserted an Excel worksheet into the Visual Basic project in Figure 2.27.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |