Page

D.6.0- Unsupported String functions, statements and constructs

Created by Brendan Doss.
Last Updated by Brendan Doss.  

PublicCategorized as Appendix D.

Not yet tagged
<< D.5.1- String Functions and StatementsAppendixDD.7.0- String constants >>

Unsupported String functions,statements and constructs

The following VB/VBA stringfunctions/statements and constructs are not supported in VBScript:

 

Function
Statement Name

Alternative

Format

FormatCurrency, FormatDateTime, FormatNumber, FormatPercent

LSet

Left, Len and Space functions in conjunction:

 

Dim strTest
Dim strNewText

          ' strTest is now 5 chars wide
   strTest = "01234"
          ' Assign the text to left align
   strNewText = "<-Test"
          ' Use the VB/VBA LSet (Unsupported)
   LSet strTest = strNewText

          ' Check if the New Text is wider than
          ' the variable we will align it in
   If Len(strNewText) <= Len(strTest) Then
                    ' Copy the text across and pad the
                    ' rest with spaces
       strTest = strNewText & Space(Len(strTest) - Len(strNewText))
   Else
                    ' Copy as many chars from the new
                    ' text as strTest is wide
       strTest = Left(strNewText, Len(strTest))
   End If

 

In both cases strTest will hold the value "<-Tes", because the original
string
strTest is only 5 characters wide and thus cannot hold all of strNewText. Had strTest been larger, the remaining places would have been filled with spaces.

Mid (statement)

Left, Mid and InStr functions, or the Replace function:

 

Here is how to replace a substring identified by characters using the Replace function:

Dim strText
Dim strFind
Dim strSubstitute

   strText = "This is the text I want to replace a substring in"
   strFind = "want to replace"
   strSubstitute = "have replaced"

   strText = Replace(strText, strFind, strSubstitute)

 

strText now holds This is the text I have replaced a substring in

 

 

Here is how to replace a substring identified by position and length using the InStr, Left and Mid functions:

 

Dim strText
Dim strSubstitute

   strText = "This is the text I want to replace a substring in"
   strSubstitute = "have replaced"

   strText = Left$(strText, 19) & strSubstitute & Mid$(strText, _
             35, Len(strText) - 34)

 

strText now holds This is the text I have replaced a substring in

 

RSet

Left, Len and Space functions in conjunction:

Dim strTest
Dim strNewText

          ' strTest is now 5 chars wide
   strTest = "01234"
          ' Assign the text to right align
   strNewText = "Test->"
          ' Use the VB/VBA RSet (Unsupported)
   RSet strTest = strNewText

          ' Check if the New Text is wider than
          ' the variable we will asign it in
   If Len(strNewText) <= Len(strTest) Then
                    ' Pad with spaces and copy the
                    ' text across
       strTest = Space(Len(strTest) - Len(strNewText)) & strNewText
   Else
                    ' Copy as many chars from the new
                    ' text as strTest is wide
        strTest = Left(strNewText, Len(strTest))
   End If

 

In both cases strTest will hold the value "Test-", because the original string strTest is only 5 characters wide and thus cannot hold all of strNewText. Had strTest been larger, the remaining places would have been filled with spaces.

 

StrConv

Very unlikely that this will be needed as all variables are Variant and this will be done implicitly.

 

Fixed length strings (Dim strMessage As String * 50) are not supported.


<< D.5.1- String Functions and StatementsAppendixDD.7.0- String constants >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |