Visual Basic 5 Curiosities

All examples were tested with VB5.

Arrays with zero Items

Private Sub Command1_Click()
    Dim buffer(3) As Byte
    Dim arr() As Byte
    arr = MidB(buffer, 1, 0)
    Call MsgBox(LBound(arr) & " / " & UBound(arr))
    ' LBound is 0 and UBound is -1
    ' but ReDim arr(0 to -1) is not allowed. Why?
End Sub

Assigning Arrays

Private Sub Form_Load()
    Dim byteBuf(3) As Byte
    Dim byteSeq() As Byte
    byteSeq = byteBuf        ' Is allowed
    Dim longBuf(3) As Long
    Dim longSeq() As Long
    longSeq = longBuf        ' Is not possible. Why?
End Sub

Long VB names

It is not possible to compile VB programs to executable files if project name plus class name has more than 39 characters due to a limitation of VB5 and ActiveX.

Decimal type

VB knows a decimal type but you have to use Variant. CORBA long long is mapped to a Decimal inside a Variant.
Dim decVal As Variant
decVal = CDec("12345678901234567890")

Global Err object

Each ActiveX-DLL has its own global Err object if you use the DLL by reference. There is only one global Err object if you include the DLL project in your main project for debugging purposes and you get different behavior.

Garbage collection of weak circular references

VB do not garbage collection of weak circular references. A reason of some memory leaks in VB applications. ActiveX EXE doesn´t terminate if circular references exists.

Use of `As New' is discouraged

Dim obj As New cMyClass
Set obj = Nothing
If obj Is Nothing Then
This is never happen therefore declaring variables As New is, in general, discouraged.