VBScript is the dominant and default scripting language for server-side processing via ASPs (Active Server Pages) on Microsoft's web server: IIS (Internet Information Server/Services). VBS and JS can also be used for WSH (Windows Scripting Host) which is the replacement for the old batch files (.bat) and can run directly in the operating system. EGs: See my section on ASP.
VBScript can also be used for client-side processing. (Please note that JavaScript is preferred for client-side scripting because VBS is not supported by Netscape Navigator, whereas JS is supported by both Netscape and Microsoft browsers.) For client-side processing, VBScript is enclosed by <script> tags. VBScript is usually further enclosed within HTML comment tags in case the user's browser is not enabled for VBScript.
Here's how VBS and VB features relate:
') is placed at the start of the comment. Comments cannot utilize line continuation. _).The functions used by VBS are similar to the VB functions. The items in bold are new to VB 5.6 (MSIE 6): CStr, Escape, and Unescape.
| Abs | Array | Asc | Atn |
| CBool | CByte | CCur | CDate |
| CDbl | Chr | CInt | CLng |
| Conversions | Cos | CreateObject | CSng |
| CStr | Date | DateAdd | DateDiff |
| DatePart | DateSerial | DateValue | Day |
| Derived Math | Escape | Eval | Exp |
| Filter | FormatCurrency | FormatDateTime | FormatNumber |
| FormatPercent | GetLocale | GetObject | GetRef |
| Hex | Hour | InputBox | InStr |
| InStrRev | Int, Fix | IsArray | IsDate |
| IsEmpty | IsNull | IsNumeric | IsObject |
| Join | LBound | LCase | Left |
| Len | LoadPicture | Log | LTrim; RTrim; and Trim |
| Maths | Mid | Minute | Month |
| MonthName | MsgBox | Now | Oct |
| Replace | RGB | Right | Rnd |
| Round | ScriptEngine | ScriptEngineBuildVersion | ScriptEngineMajorVersion |
| ScriptEngineMinorVersion | Second | SetLocale | Sgn |
| Sin | Space | Split | Sqr |
| StrComp | String | StrReverse | Tan |
| Time | Timer | TimeSerial | TimeValue |
| TypeName | UBound | UCase | Unescape |
| VarType | Weekday | WeekdayName | Year |
Note that there are variations of the VB Format() function but the Format() function itself is not available to VBS.
Certain functions (EG: InputBox() and MsgBox()) are designed for client-side code and should not be used in server-side code.
This checks if a control has a value that follows minimal syntax requirements for email addresses.
Function ValidEmail()
Dim re, str
Set e = window.event.srcelement
str = e.value
If Len(Trim(str)) > 0 Then
Set re = new RegExp
re.Pattern = "(\w+)@(\w+)\.(\w+)"
If Not(re.Test(str)) Then
Alert("You have entered an invalid email format")
e.focus
End If
Set re = Nothing
End If
Set e = Nothing
End Function
This is VBS client side code that gets the value and displayed text from the selected option in a select list.
This is in the header:
<script language="VBScript"><!--
Sub selX_OnBlur()
MsgBox "value=" & selX.value & " " & _
"text=" & selX.options(selX.selectedIndex).text
End Sub
' --></script>
This is the select box:
<select name="selX"> <option value="1">Ape</option> <option value="2">Bee</option> <option value="3">Cat</option> </select>
Page Modified: (Hand noted: 2007-10-03 18:55:04Z) (Auto noted: 2008-02-04 22:45:36Z)