Why Visual Basic?

   

Why Visual Basic?

Although the word "basic" is contained within its title, the power of applications that are built using this robust development environment is anything but rudimentary. Although many administrators think of Visual Basic in terms of crude custom-developed database front-ends , Microsoft Office macros, shareware applications, and those dreadful VBRUNXXX.DLL's, which are required to support older Visual Basic applications, today's Visual Basic development environment can be used to build extremely sophisticated, yet easy to develop, multi- tier applications. With the recent proliferation of Web technology, forward-thinking developers and IT managers are trading in the resource-hungry, network- intensive , natively compiled applications of yesteryear in favor of thinner, easily customized, Web-based applications.

Most other ADSI texts focus on ADSI in Active Server Page (ASP) scripts. Although the use of ADSI code directly within an ASP is quick and easy to implement, some problems are inherent in this particular employment, and are discussed in the following sections.

Visual Basic Defines Datatypes in Variable Declarations

As you learn about ADSI, you will become familiar with the datatypes passed in and out of ADSI's methods . To focus purely on ASP scripting using VBScript masks the true datatypes used with each function ”as VBScript uses the variant datatype for all variables in the language.

Datatypes play a tremendous role in resource allocation for an application; thus, to display only VBScript robs you of a solid understanding of the datatypes used with ADSI. If you have ever tried converting an application from VBScript to Visual Basic, you know that this can be a daunting task if you do not have a solid programming background. Unless you continue to use variants for all datatypes (a shameless waste of system resources!) you will have an extremely difficult time getting your code to work unless you know the proper datatypes for each argument and return value. By viewing all code examples in this text in Visual Basic, you will gain a better understanding of the datatypes used with ADSI.

Visual Basic Allows Multi-Tier Development

Another problem with implementing ADSI code strictly within ASP is that application logic is intermingled with business logic. This makes it difficult to determine which function is supporting business logic and which function is supporting the proper execution of the application.

This presents particular problems when an organization merges with another entity and business rules change. For example, a recently merged corporation may decide to change its user account-naming standard. If the code to enforce the naming standard is intermingled with the code that actually performs user account creation, the system administrator must test every element in the page to assure that the development effort did not break the core application logic. This may sound trivial, but there has to be a better way to deal with an extremely complex page containing hundreds or thousands of lines of code.

There is indeed a better way, and it is called the Component Object Model (COM).

Visual Basic Separates Business Logic from Application Logic with COM

What the rest of the industry refers to as " n -tier" (2-tier, 3-tier, 4-tier, and so on) architecture, Microsoft labels with their own moniker: Windows DNA. No matter what you call it, the concept is simple: Efficient application architectures are founded upon separation of business logic and application logic.

Many applications and operating systems use this same concept, including almost every recent release of Microsoft software. The Office product line allows you to "drive" individual office automation applications from Visual Basic using the object model exposed by the office automation suite's type library. If you have ever created a stored procedure in SQL Server or called a batch file from inside another, you can understand the benefits of a procedural approach to programming.

To translate this into a nontechnical example: Imagine that you own a retail store in a shopping center. At the end of the day, you must perform 25 tasks to secure the store and close out the day's business. To help your employees, you create a checklist of items that need to be completed to close the store. After the list is written and distributed, you can simply tell your employees to "close" the store, and they will walk through the 25 steps on the checklist.

This approach makes it easy to perform repetitive or complex tasks within a single atomic unit that can be called using a single command. This concept is the fundamental premise of the Component Object Model (COM). Using COM, you can now provide the correct way to instantiate your object and reference the functions to the Web developer's call, encapsulating all ADSI code within your COM server. Should the underlying infrastructure of your organization change, you can easily change the code in the COM server without requiring the Web developers to redevelop the ASP that references the COM object.

To continue the store example: If you decided to change the store-closing procedure, you could update the task list to reflect the changes, but still tell employees to "close" the store. In this way, you can change the underlying store-closing procedures, but still reference the tasks at hand with a single command.

Visual Basic allows you to create COM objects quickly and easily by compiling code as an ActiveX DLL, and modifying the way subroutines and functions are defined ”for example, private versus public procedures or referencing variables by value instead of by reference. The creation of ActiveX DLL's is discussed in the "Developing a COM Server Using Visual Basic and ADSI" section found later in this chapter.

COM Allows Code Reuse

By compiling code into COM objects, Web developers can use any language they choose ”as long as the Web server supports it and the scripting language supports automation. If you create a COM object in Visual Basic, you can then allow VBScript developers to reference your object using only a few lines of code. If your Web developers use JavaScript, they too can share the same object. If you want to run an ADSI function within a Windows Scripting Host (WSH) application, you can also use the functions contained within a Visual Basic-developed COM object.

Without COM, the alternative is rather grim: Every time you want to create a user in a new application, you will have to break out this text and write up the appropriate script. Instead, if you choose to use COM, you can create a reusable component library that allows developers to select their functions by instantiating the proper class module and subsequently calling the appropriate function within the COM server.


   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net