GNVQ Intermediate IT Optional Unit5

Tutors Sue Cahill and Colin Duley



GNVQ IT Differences between Visual Basic V4 and VBScript

Other Syntax Not Supported
Some syntax features that are not supported are summarized in Table 20.1. Refer to the Visual Basic language reference help file that comes with Visual Basic for more details on these statements and functions. Keep in mind that this table does not represent everything that is not supported in VBScript.  It would be difficult to cover every single nuance of all the differences, but this list is fairly comprehensive and will give you a good starting point. At the time of this printing, a more comprehensive list was also available at Microsoft's Web site under www.microsoft.com/vbscript.

Table 20.1. Partial list of Visual Basic syntax with no VBScript equivalent.
Add
AddItem
appactivate
Arrange
Arrays (setting low bounds so indexing starts at other than 0)
Beep
Boolean (must use variant)
Byte (must use variant)
ccur
Chr$ (note that Chr is supported)
Circle
clipboard object
Cls
Command
Command$
Conditional compiler directives
Const (must use variables to simulate constants)
Count
Currency (use variant to represent decimal-based money amounts)
Cvar
CVDate
Currency data type (use variant to represent decimal-based money amounts)
Date statement (allows program to set current date)
Date$ (date function to display date is supported)
Debug.Print
Declare (can't use dynamic link libraries [DLLs])
DefType
Dim x As New TypeName
DoEvents
Double (use variant)
Drag
End
EndDoc
Environ
Environ$
Erl
Error (the err object is supported)
Error$ (the err object is supported)
Fixed-length strings (use variant variable length string)
Format
Format$
GetObject
Global
GoSub...Return
Goto
Hide
IfTypeOf x Is TypeName
InputBox$ (Inputbox is supported)
Integer (use variant type)
IsMissing
Item
Lcase$ (Lcase is supported)
Left$ (Left is supported)
Like
Line numbers and labels
LinkExecute
LinkPoke
LinkRequest
LinkSend
Literals:
Real numbers with scientific exponentiation, such as 1.746E+100
Date-specific formats such as #7/6/62# (assign 7/6/62 to a variant)
Type characters, such as VarI%
Load
LoadPicture and SavePicture
Long (use variant)
Lset statements
Me
Mid$ (Mid is supported)
Mid statements (Mid as a function is supported)
Move
NewPage
Object (use variant to represent objects such as Hypertext Markup Language [HTML] forms)
On Error...Goto (On Error Resume Next is supported)
On Error...Resume (On Error Resume Next is supported)
Option Base
Option Compare
Option Private Module
ParamArray
Optional
Point
PrintForm
Print
Private (module level)
Pset
Public (module level)
OBColor
RGB
Refresh
Remove
RemoveItem
Resume (only support is for On Error Resume Next)
Right$ (Right is supported)
Rset statements
Rset (strings)
Rset (structs)
Scale
SendKeys
Set x = New TypeName (Set x = ObjName is supported)
Set/Let/Get (property procedures not supported, but Set x = ObjName is)
SetFocus
Shell
Show
Single (use variant)
Space$ (Space is supported)
Spc
Stop
Str$
StrConv
Str, Val
String$
Tab
TextHeight and TextWidth (for printing, graphics)
Time$ (Time is supported)
Trim$, Ltrim$, and Rtrim$
Type...End Type
TypeOf
TypeName
Type suffixes (%,$,!, and so on)
Ucase$ (Ucase is supported)
Unload
Use of explicitly named arguments such as KeithTest (argument1:=4)
With...End With
Zorder
 

Other Visual Basic and VBScript Differences
You have seen that many Visual Basic keywords and constructs are not supported in VBScript. VBScript has a few other differences from Visual Basic as well. These are discussed in the following sections.

Arrays
Arrays always start at an index of 0 in VBScript. In Visual Basic, you have the option to define the lower bound. In addition, you get a different number of array elements with the same declaration in Visual Basic and VBScript. This Visual Basic declaration gives you 10 elements that can be referenced from code by index numbers 0...9:
Dim CountArray(10)
This VBScript declaration gives you 11 elements that can be referenced from code by index numbers 0...10:
Dim CountArray(10)
You may have noticed that both lines are the same. That's not a typo! The declaration just works differently under Visual Basic 4.0 and VBScript.  This difference is likely to disappear with future product releases that are based on the new VBA 5.0 engine.  Fortunately, in this case the porting impact going to VBScript is relatively small. The VBScript declaration will give you an extra array element, but your code can work as before without change. The extra element can simply go unused without interfering with existing code unless you use the Ubound function to determine the upper bound of an array when looping, assigning values, and so on. If so, you could have trouble with your code. The recurring porting theme is that you need to check everything carefully.
 

Intrinsic Browser Objects
Visual Basic supports many objects that VBScript does not. These include the clipboard object, debug object, and data object. However, VBScript can also take advantage of objects not directly available to Visual Basic. The Internet Explorer environment provides VBScript with access to location, document, navigator, and other objects discussed on Error! Bookmark not defined., "Advanced User Interface and Browser Object Techniques." Typically, major design assessment will be required if you discover that code to be ported has relied on such objects. The browser does support intrinsic objects such as a command button, a text box, and others covered on Error! Bookmark not defined., "Intrinsic HTML Form Controls," and Error! Bookmark not defined., "More Intrinsic HTML Form Controls," that are very similar to the standard controls in Visual Basic. Property lists will be similar for these controls, but not identical in every respect. However, if you stick to relatively simple standard uses of these controls, porting difficulty should be minimal.

Multiple Form Architecture
Perhaps one of the most challenging porting problems is moving Visual Basic programs that make heavy use of underlying forms. VBScript under Internet Explorer now offers a somewhat equivalent model with its Layout Control forms interface. This, coupled with Internet Explorer's incorporation of 2-D layout for HTML, makes it possible to position elements and controls anywhere on a page in a formlike fashion. This approach is discussed in more detail on Error! Bookmark not defined.. If you have a Multiple Document Interface application under Visual Basic, you won't have a direct equivalent under VBScript, although you can use Internet Explorer's frames, also discussed on Error! Bookmark not defined., to build a slightly different kind of multiple windows. The best bet is to reassess the entire user interface and determine whether you can best represent a series of Visual Basic forms with the Layout Control approach, through a progression of Web frames or pages, the display of input and message boxes from a script, or the display of varying labels. In any event, some user interface redesign may be in order if you are porting code that includes a nontrivial user interface to VBScript. Over the long run, it is possible that the form model between Visual Basic and VBScript may merge with subsequent releases of the product and the operating system.

Summary
Today's lesson addresses issues that are likely to be of concern when moving code between Visual Basic and VBScript. VBScript provides a powerful Web page programming capability, and it is also closely related to what is one of the world's most widely used languages-its parent language Visual Basic for Applications. A natural result is that programmers will look to porting code between the environments for maximum payback of coding efforts. Considering the differences between Visual Basic and VBScript can be valuable even for programmers who have never used Visual Basic and who just program in the script environment. Knowledge of what's not in VBScript but is in the parent language helps provide a broader view of the language and a greater overall understanding of what it can best accomplish.
Differences between the languages are described throughout today's lesson. VBScript is largely a subset of Visual Basic. There are some intrinsic Internet Explorer objects available to VBScript that are not directly available to Visual Basic. Likewise, Visual Basic supports some objects and many language aspects that are not present in VBScript. This means that special care must be taken in moving code between the environments. Therefore, the easiest ports are those where Visual Basic code is converted to VBScript. But these are not always pain-free. Incompatibilities are very likely to arise, and they can range from the very obvious to the very subtle. Because VBScript has no dedicated development environment, debugging scripts that have been converted is often a challenge. Tracking down porting problems and language differences can be especially time consuming. A good understanding of the language differences smoothes the process.
Many specific language differences are addressed. VBScript provides access to some elements that Visual Basic does not. For example, you can use the document and location objects in VBScript but not in Visual Basic. In some cases, Visual Basic and VBScript support the same elements, but they work slightly differently. A Dim ArrayName(n) statement allocates 0 to n elements in VBScript but just 0 to n-1 elements in Visual Basic 4.0.
Today's lesson addresses many areas of Visual Basic that are not supported in VBScript, including the clipboard object, print object, application control statements such as shell, appactivate, SendKeys, data access objects, and file I/O. Guidelines are presented to smooth the porting process. The best tool to aid in porting code, however, is simply a strong understanding of both languages and experience with both. It is important to keep the code compatibility in perspective. Even though there are some pitfalls to moving code between these environments, the two languages are still so closely related that improved programs and great productivity savings can result for those willing to tackle such ports.


 Top of Page
Home Page 
Query for Tutor?