VB.NET "Compatibility Wrapper" 
Author Message
 VB.NET "Compatibility Wrapper"

One of the secondary issues with conversion of VBScript to VB.NET is translation
of runtime methods/properties.  The methods and properties are essentially all
"parts" of VBScript other than structural keywords - anything that does
something "to" a quantity or returns a value.

I've put together a compatibility library to help with this task.  Below is a
discussion of what's in the library; below that is the library itself.

--
Please respond in the newsgroup so everyone may benefit.
  http://www.*-*-*.com/
(email requests for support contract information welcomed)
 ----------
 Subscribe to Microsoft's Security Bulletins:
  http://www.*-*-*.com/

=======================================
LIBRARY DESCRIPTION

Properties:
Of the 85 properties VBScript's runtime exposes, 72 are already in VB.NET; I
have wrapped the other 13.

Methods
The VBScript runtime has 107 methods exposed; 75 are directly available to you
in VB.NET.  The remaining 32 I have wrapped insofar as possible; here is how
they are broken down:

    Math and Misc
The math functions are all in the System.Math namespace, and a few have
different names now.  All are wrapped and available by old name in the library,
as are a few miscellaneous functions.

    Currency to Decimal
Since the Currency data type is gone and Decimal has been introduced, I have
wrapped the somewhat-obscure "CCur" function around CDec.

    "Compatibility"  issues - String, Date, Array
Three methods (string, Array, Date) won't work directly as-is since they are
type names in VB.NET.  For this reason, I have them in a Compatibility subclass;
you can't call them directly by bare name.  If you have imported the parent
namespace, you can call them like

    Compatibility.Date

You can also bracket them to call them directly:

    [Date]

Either way, VB.NET will insist you modify them.

**** NOT AVAILABLE ***

The following methods are not available and are not wrapped:
Escape, Eval, Unescape, Execute, ExecuteGlobal, GetRef, LoadPicture

There are no close analogs to any of them currently.  It is possible to
implement escape-like support from Regexes in .NET and also from the System.Uri
class, but the System.Uri method is difficult; it would need to wrap a class
which implements System.Uri Inheritance.

The dynamic execution functions are slated to go into VB.NET "eventually".

GetRef may be possible to mimic with AddHandler and AddressOf.

LoadPicture... I have no clue about - never used it much myself!

=============================================
A VBSCRIPT ---> VB.NET COMPATIBILITY LIBRARY

' Code starts here

Public Class VBScript

  Public Shared Function Time() As Date
    Time = TimeOfDay
  End Function

  Public Shared Function CCur(ByVal value) As Decimal
    CCur = CDec(value)
  End Function

  Public Shared Function Log(ByVal value)
    Log = System.Math.Log(value)
  End Function

  Public Shared Function IsObject(ByVal value) As Boolean
    IsObject = IsReference(value)
  End Function

  Public Shared Function Round(ByVal value)
    Round = System.Math.Round(value)
  End Function

  Public Shared Function Sin(ByVal value)
    Sin = System.Math.Sin(value)
  End Function

  Public Shared Function Tan(ByVal value)
    Tan = System.Math.Tan(value)
  End Function

  Public Shared Function Abs(ByVal value)
    Abs = System.Math.Abs(value)
  End Function

  Public Shared Function Cos(ByVal value)
    Cos = System.Math.Cos(value)
  End Function

  Public Shared Function Atn(ByVal value)
    Atn = System.Math.Atan(value)
  End Function
  Public Shared Function Sqr(ByVal value)
    Sqr = value ^ (1 / 2)
  End Function

  Public Shared Function Sgn(ByVal value)
    Sgn = System.Math.Sign(value)
  End Function

  Public Shared Function IsEmpty(ByVal value)
    IsEmpty = IsNothing(value)
  End Function

  Public Shared Function IsNull(ByVal value)
    IsNull = IsDBNull(value)
  End Function

  Public ReadOnly Property vbBlack() As Int64
    Get
      vbBlack = &H0
    End Get
  End Property

  Public ReadOnly Property vbBlue() As Int64
    Get
      vbBlue = &HFF0000
    End Get
  End Property

  Public ReadOnly Property vbCyan() As Int64
    Get
      vbCyan = &HFFFF00
    End Get
  End Property

  Public ReadOnly Property vbDatabaseCompare() As Int64
    Get
      vbDatabaseCompare = &H2
    End Get
  End Property

  Public ReadOnly Property vbDataObject() As Int64
    Get
      vbDataObject = &HD
    End Get
  End Property

  Public ReadOnly Property vbDefaultButton4() As Int64
    Get
      vbDefaultButton4 = &H300
    End Get
  End Property

  Public ReadOnly Property vbError() As Int64
    Get
      vbError = &HA
    End Get
  End Property

  Public ReadOnly Property vbGreen() As Int64
    Get
      vbGreen = &HFF00
    End Get
  End Property

  Public ReadOnly Property vbMagenta() As Int64
    Get
      vbMagenta = &HFF00FF
    End Get
  End Property

  Public ReadOnly Property vbMsgBoxHelpButton() As Int64
    Get
      vbMsgBoxHelpButton = &H4000
    End Get
  End Property

  Public ReadOnly Property vbRed() As Int64
    Get
      vbRed = &HFF
    End Get
  End Property

  Public ReadOnly Property vbWhite() As Int64
    Get
      vbWhite = &HFFFFFF
    End Get
  End Property

  Public ReadOnly Property vbYellow() As Int64
    Get
      vbYellow = &HFFFF
    End Get
  End Property

  Public Class Compatibility

    Public Shared Function [Date]() As Date
      [Date] = Today
    End Function

    Public Shared Function [String](ByVal numChars, _
      ByVal stringChar) As String
      Dim s As String = ""
      s.PadLeft(numChars)
      [String] = s.Replace(" ", stringChar)
    End Function

    Public Shared Function [Array]( _
      ByVal ParamArray values()) As Array
      [Array] = values
    End Function

  End Class

End Class



Fri, 29 Jul 2005 09:33:55 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. C DLL and VB "wrapper DLL"

2. "Binary compatibility" hint

3. C# "as" operator in VB .NET

4. "vbCrLf" in VB.NET

5. What are "delegates" in VB.net

6. VB.NET "Scripting"

7. VB.NET, MSComm32 and "Ctrl-Z"

8. wrapper to print "Draft" on pages

9. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

10. GetObject("","InternetExplorer.Application") fails in Excel VBA

11. SysCmd 603, "path","path"

12. Loop print "VARIABLE", "VARIABLE"

 

 
Powered by phpBB® Forum Software